-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance standard templates #75
base: master
Are you sure you want to change the base?
Changes from 10 commits
cbdd414
11b1918
5608a63
2002ee8
8c9c05d
a35f23e
cba3416
f599fe0
f21bd46
894db3f
3880623
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{#- Copyright 2017 Cargill Incorporated | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
-#} | ||
-- Create a Kudu table in Impala | ||
USE {{ conf.staging_database.name }}; | ||
ALTER TABLE {{ table.destination.name }}{% if conf.user_defined is defined and conf.user_defined.kudu_suffix is defined %}{{ conf.user_defined.kudu_suffix }}{% endif %} | ||
SET TBLPROPERTIES( | ||
{%- if table.metadata %} | ||
{%- for key, value in table.metadata.items() %} | ||
'{{ key }}' = '{{ value }}', | ||
{%- endfor %} | ||
{%- endif %} | ||
{%- for column in table.columns -%} | ||
"{{ cleanse_column(column.name)|lower }}" = "{{ column.comment }}"{%- if not loop.last -%},{% endif %} | ||
{%- endfor -%}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{#- Copyright 2017 Cargill Incorporated | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. #} | ||
|
||
-- Create a Parquet table in Impala | ||
set sync_ddl=1; | ||
USE {{ conf.staging_database.name }}; | ||
{%- for column in table.columns %} | ||
ALTER TABLE {{ table.destination.name }}{% if conf.user_defined is defined and conf.user_defined.parquet_suffix is defined %}{{ conf.user_defined.parquet_suffix }}{% endif %} | ||
CHANGE {{ cleanse_column(column.name) }} {{ cleanse_column(column.name) }} {{ map_datatypes(column).parquet }} COMMENT "{{ column.comment }}"; | ||
{%- endfor %}) | ||
|
||
{%- if table.metadata %} | ||
ALTER TABLE {{ table.destination.name }}{% if conf.user_defined is defined and conf.user_defined.parquet_suffix is defined %}{{ conf.user_defined.parquet_suffix }}{% endif %} | ||
SET TBLPROPERTIES ( | ||
{%- for key, value in table.metadata.items() %} | ||
'{{ key }}' = '{{ value }}'{%- if not loop.last -%}, {% endif %} | ||
{%- endfor %} | ||
) | ||
{%- endif %} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,9 @@ | |
-- Create a Parquet table in Impala | ||
set sync_ddl=1; | ||
USE {{ conf.raw_database.name }}; | ||
CREATE EXTERNAL TABLE IF NOT EXISTS {{ table.destination.name }}_avro ( | ||
CREATE EXTERNAL TABLE IF NOT EXISTS `{{ table.destination.name }}_avro` ( | ||
{% for column in table.columns %} | ||
`{{ column.name.replace('/','_') }}` {{ map_datatypes(column).avro }} COMMENT "{{ column.comment }}" | ||
`{{ cleanse_column(column.name) }}` {{ map_datatypes_v2(column).avro }} COMMENT "{{ column.comment }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of cleanse_column |
||
{%- if not loop.last -%}, {% endif %} | ||
{%- endfor %}) | ||
COMMENT '{{ table.comment }}' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
hadoop fs -mkdir {{ conf.raw_database.path }}/{{ table.destination.name }}_avro/.meta/ | ||
hadoop fs -put -f AutoGeneratedSchema.avsc {{ conf.raw_database.path }}/{{ table.destination.name }}_avro/.meta/{{ table.destination.name }}.avsc | ||
hadoop fs -mkdir -p {{ conf.raw_database.path }}/{{ table.destination.name }}_avro/.meta/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure |
||
hadoop fs -put -f AutoGeneratedSchema.avsc {{ conf.raw_database.path }}/{{ table.destination.name }}_avro/.meta/{{ table.destination.name }}.avsc |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
INSERT OVERWRITE TABLE {{ conf.raw_database.name }}.{{ table.destination.name }}_partitioned PARTITION (ingest_partition=${var:val}) | ||
INSERT OVERWRITE TABLE `{{ conf.raw_database.name }}`.`{{ table.destination.name }}_partitioned` PARTITION (ingest_partition=${var:val}) | ||
SELECT {% for column in table.columns %} | ||
{%- if column["datatype"].lower() == "decimal" %} | ||
cast (`{{ column.name.replace('/','_') }}` as decimal({{column.precision}}, {{column.scale}}) ) | ||
{%- else %} `{{ column.name.replace('/','_') }}` | ||
{% endif %} | ||
{%- if not loop.last -%}, {% endif %} | ||
{%- if column["datatype"].lower() == "decimal" %} cast (`{{ cleanse_column(column.name) }}` as decimal({{column.precision}}, {{column.scale}}) ) | ||
{%- elif column["datatype"].lower() == "timestamp" %} cast (`{{ cleanse_column(column.name) }}`/1000 as timestamp ) AS `{{ cleanse_column(column.name) }}` | ||
{%- else %} `{{ cleanse_column(column.name) }}` | ||
{%- endif %} | ||
{%- if not loop.last %}, {% endif %} | ||
{%- endfor %} | ||
FROM {{ conf.raw_database.name }}.{{ table.destination.name }}_avro; | ||
FROM `{{ conf.raw_database.name }}`.`{{ table.destination.name }}_avro`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,14 +14,10 @@ | |
|
||
-- Create a Parquet table in Impala | ||
set sync_ddl=1; | ||
USE {{ conf.staging_database.name }}; | ||
CREATE EXTERNAL TABLE IF NOT EXISTS {{ table.destination.name }} ( | ||
{% for column in table.columns %} | ||
{%- if column["datatype"].lower() == "decimal" %} | ||
`{{ column.name.replace('/','_') }}` {{ map_datatypes(column).parquet }}({{column.precision}},{{column.scale}}) COMMENT "{{ column.comment }}" | ||
{%- else %} `{{ column.name.replace('/','_') }}` {{ map_datatypes(column).parquet }} COMMENT "{{ column.comment }}" | ||
{% endif %} | ||
{%- if not loop.last -%}, {% endif %} | ||
USE `{{ conf.staging_database.name }}`; | ||
CREATE EXTERNAL TABLE IF NOT EXISTS `{{ table.destination.name }}` ( | ||
{%- for column in table.columns %} | ||
`{{ cleanse_column(column.name) }}` {{ map_datatypes_v2(column, 'parquet') }} COMMENT "{{ column.comment }}" {%- if not loop.last -%}, {% endif %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You removed the decimal logic, does map_datatypes_v2 handle the decimal type? |
||
{%- endfor %}) | ||
COMMENT '{{ table.comment }}' | ||
STORED AS PARQUET | ||
|
@@ -32,4 +28,4 @@ TBLPROPERTIES( | |
'{{ key }}' = '{{ value }}'{%- if not loop.last -%}, {% endif %} | ||
{%- endfor %} | ||
) | ||
{%- endif %} | ||
{%- endif %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
DROP TABLE IF EXISTS {{ conf.raw_database.name }}.{{ table.destination.name }}_avro; | ||
DROP TABLE IF EXISTS {{ conf.raw_database.name }}.{{ table.destination.name }}_partitioned; | ||
DROP TABLE IF EXISTS {{ conf.staging_database.name }}.{{ table.destination.name }}; | ||
DROP TABLE IF EXISTS `{{ conf.raw_database.name }}`.`{{ table.destination.name }}_avro`; | ||
DROP TABLE IF EXISTS `{{ conf.raw_database.name }}`.`{{ table.destination.name }}_partitioned`; | ||
DROP TABLE IF EXISTS `{{ conf.staging_database.name }}`.`{{ table.destination.name }}`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,7 @@ set -e | |
# Check parquet table | ||
AVRO=$({{ conf.impala_cmd }} avro-table-rowcount.sql -B 2> /dev/null) | ||
PARQUET=$({{ conf.impala_cmd }} report-table-rowcount.sql -B 2> /dev/null) | ||
SOURCE=$(cat sourceCount.txt) | ||
|
||
SOURCE=$({{ conf.source_database.cmd }} source-table-rowcount.sql -s -r -N -B 2> /dev/null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is stderr piped to /dev/null |
||
echo "avro count: $AVRO" | ||
echo "report count: $PARQUET" | ||
echo "source count: $SOURCE" | ||
|
@@ -30,4 +29,4 @@ fi | |
if [ "$PARQUET" -ne "$SOURCE" ]; then | ||
echo FINAL TABLE ROW COUNTS DO NOT MATCH | ||
exit 1 | ||
fi | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give an example of how this
user_defined
block is used and what it's for?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This raises a flag because it will break existing scripts that are expecting the
_parquet
suffix