-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalization fix Prefix Tables starting with number (#9301)
* add normalization-clickhouse docker build step * bump normalization version * small changes gradle * fix settings gradle * fix eof file * correct clickhouse normalization * Refactor jinja template for scd (#9278) * merge chris code and regenerate sql files * correct scd post-hook generation for snowflake * fix scd table for snowflake prefix table with number * scd fix for all destinations * use quote * use normalize column for post-hook * change logic to apply quote * add logic to handle prefix for mssql and oracle * run tests * correct unit test * bump normalization version Co-authored-by: James Zhao <james.zhao@sinoreps.com> Co-authored-by: Edward Gao <edward.gao@airbyte.io> Co-authored-by: Christophe Duong <christophe.duong@gmail.com>
- Loading branch information
1 parent
4190dbc
commit 511819b
Showing
69 changed files
with
354 additions
and
708 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ms/models/generated/airbyte_incremental/scd/test_normalization/dedup_cdc_excluded_scd.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/models/generated/airbyte_incremental/scd/test_normalization/dedup_exchange_rate_scd.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...e_incremental/scd/test_normalization/nested_stream_with_co__lting_into_long_names_scd.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/models/generated/airbyte_incremental/scd/test_normalization/dedup_exchange_rate_scd.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rbyte_incremental/scd/test_normalization/nested_stream_with_co_1g_into_long_names_scd.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/models/generated/airbyte_incremental/scd/test_normalization/dedup_exchange_rate_scd.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/models/generated/airbyte_incremental/scd/test_normalization/dedup_exchange_rate_scd.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
...ration_tests/normalization_test_output/postgres/test_simple_streams/first_dbt_project.yml
This file was deleted.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
...first_output/airbyte_incremental/scd/test_normalization/1_prefix_startwith_number_scd.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
|
||
|
||
create table "postgres".test_normalization."1_prefix_startwith_number_scd" | ||
as ( | ||
|
||
-- depends_on: ref('1_prefix_startwith_number_stg') | ||
with | ||
|
||
input_data as ( | ||
select * | ||
from "postgres"._airbyte_test_normalization."1_prefix_startwith_number_stg" | ||
-- 1_prefix_startwith_number from "postgres".test_normalization._airbyte_raw_1_prefix_startwith_number | ||
), | ||
|
||
scd_data as ( | ||
-- SQL model to build a Type 2 Slowly Changing Dimension (SCD) table for each record identified by their primary key | ||
select | ||
md5(cast(coalesce(cast("id" as | ||
varchar | ||
), '') as | ||
varchar | ||
)) as _airbyte_unique_key, | ||
"id", | ||
"date", | ||
"text", | ||
"date" as _airbyte_start_at, | ||
lag("date") over ( | ||
partition by "id" | ||
order by | ||
"date" is null asc, | ||
"date" desc, | ||
_airbyte_emitted_at desc | ||
) as _airbyte_end_at, | ||
case when row_number() over ( | ||
partition by "id" | ||
order by | ||
"date" is null asc, | ||
"date" desc, | ||
_airbyte_emitted_at desc | ||
) = 1 then 1 else 0 end as _airbyte_active_row, | ||
_airbyte_ab_id, | ||
_airbyte_emitted_at, | ||
_airbyte_1_prefix_startwith_number_hashid | ||
from input_data | ||
), | ||
dedup_data as ( | ||
select | ||
-- we need to ensure de-duplicated rows for merge/update queries | ||
-- additionally, we generate a unique key for the scd table | ||
row_number() over ( | ||
partition by | ||
_airbyte_unique_key, | ||
_airbyte_start_at, | ||
_airbyte_emitted_at | ||
order by _airbyte_active_row desc, _airbyte_ab_id | ||
) as _airbyte_row_num, | ||
md5(cast(coalesce(cast(_airbyte_unique_key as | ||
varchar | ||
), '') || '-' || coalesce(cast(_airbyte_start_at as | ||
varchar | ||
), '') || '-' || coalesce(cast(_airbyte_emitted_at as | ||
varchar | ||
), '') as | ||
varchar | ||
)) as _airbyte_unique_key_scd, | ||
scd_data.* | ||
from scd_data | ||
) | ||
select | ||
_airbyte_unique_key, | ||
_airbyte_unique_key_scd, | ||
"id", | ||
"date", | ||
"text", | ||
_airbyte_start_at, | ||
_airbyte_end_at, | ||
_airbyte_active_row, | ||
_airbyte_ab_id, | ||
_airbyte_emitted_at, | ||
now() as _airbyte_normalized_at, | ||
_airbyte_1_prefix_startwith_number_hashid | ||
from dedup_data where _airbyte_row_num = 1 | ||
); | ||
|
24 changes: 24 additions & 0 deletions
24
...streams/first_output/airbyte_incremental/test_normalization/1_prefix_startwith_number.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
|
||
|
||
create table "postgres".test_normalization."1_prefix_startwith_number" | ||
as ( | ||
|
||
-- Final base SQL model | ||
-- depends_on: "postgres".test_normalization."1_prefix_startwith_number_scd" | ||
select | ||
_airbyte_unique_key, | ||
"id", | ||
"date", | ||
"text", | ||
_airbyte_ab_id, | ||
_airbyte_emitted_at, | ||
now() as _airbyte_normalized_at, | ||
_airbyte_1_prefix_startwith_number_hashid | ||
from "postgres".test_normalization."1_prefix_startwith_number_scd" | ||
-- 1_prefix_startwith_number from "postgres".test_normalization._airbyte_raw_1_prefix_startwith_number | ||
where 1 = 1 | ||
and _airbyte_active_row = 1 | ||
|
||
); | ||
|
Oops, something went wrong.