Skip to content

Commit

Permalink
Support array based unique key in delete+insert optimised
Browse files Browse the repository at this point in the history
  • Loading branch information
rlh1994 committed May 24, 2024
1 parent 6906bd3 commit 950daa7
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
id,start_tstamp
1,2021-01-01 00:00:00
1,2021-03-05 00:00:00
2,2021-03-02 00:00:00
2,2021-03-02 00:00:00
3,2021-03-07 00:00:00
4,2021-03-04 00:00:00
5,2021-03-08 00:00:00
id,id2,start_tstamp
1,1,2021-01-01 00:00:00
1,1,2021-03-05 00:00:00
2,2,2021-03-02 00:00:00
2,2,2021-03-02 00:00:00
3,3,2021-03-07 00:00:00
4,4,2021-03-04 00:00:00
5,5,2021-03-08 00:00:00
20 changes: 10 additions & 10 deletions integration_tests/data/materializations/data_incremental.csv
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
run,id,start_tstamp
1,1,2021-01-01 00:00:00
1,2,2021-03-01 00:00:00
1,2,2021-03-03 00:00:00
1,3,2021-03-03 00:00:00
1,4,2021-03-04 00:00:00
2,1,2021-03-05 00:00:00
2,2,2021-03-02 00:00:00
2,3,2021-03-07 00:00:00
2,5,2021-03-08 00:00:00
run,id,id2,start_tstamp
1,1,1,2021-01-01 00:00:00
1,2,2,2021-03-01 00:00:00
1,2,2,2021-03-03 00:00:00
1,3,3,2021-03-03 00:00:00
1,4,4,2021-03-04 00:00:00
2,1,1,2021-03-05 00:00:00
2,2,2,2021-03-02 00:00:00
2,3,3,2021-03-07 00:00:00
2,5,5,2021-03-08 00:00:00
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
id,start_tstamp
1,2021-01-01 00:00:00
1,2021-03-05 00:00:00
2,2021-03-02 00:00:00
2,2021-03-02 00:00:00
3,2021-03-07 00:00:00
4,2021-03-04 00:00:00
5,2021-03-08 00:00:00
id,id2,start_tstamp
1,1,2021-01-01 00:00:00
1,1,2021-03-05 00:00:00
2,2,2021-03-02 00:00:00
2,2,2021-03-02 00:00:00
3,3,2021-03-07 00:00:00
4,4,2021-03-04 00:00:00
5,5,2021-03-08 00:00:00
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id,start_tstamp
1,2021-01-01 00:00:00
4,2021-03-04 00:00:00
5,2021-03-08 00:00:00
1,2021-03-05 00:00:00
2,2021-03-02 00:00:00
3,2021-03-07 00:00:00
id,id2,start_tstamp
1,1,2021-01-01 00:00:00
4,4,2021-03-04 00:00:00
5,5,2021-03-08 00:00:00
1,1,2021-03-05 00:00:00
2,2,2021-03-02 00:00:00
3,3,2021-03-07 00:00:00
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id,start_tstamp
1,2021-01-01 00:00:00
1,2021-03-05 00:00:00
2,2021-03-02 00:00:00
3,2021-03-07 00:00:00
4,2021-03-04 00:00:00
5,2021-03-08 00:00:00
id,id2,start_tstamp
1,1,2021-01-01 00:00:00
1,1,2021-03-05 00:00:00
2,2,2021-03-02 00:00:00
3,3,2021-03-07 00:00:00
4,4,2021-03-04 00:00:00
5,5,2021-03-08 00:00:00
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0
{{
config(
materialized='incremental',
unique_key='id',
unique_key=['id', 'id2'],
upsert_date_key='start_tstamp',
partition_by = snowplow_utils.get_value_by_target_type(bigquery_val={
"field": "start_tstamp",
Expand All @@ -36,6 +36,7 @@ with data as (

select
id,
id2,
start_tstamp

from data
Expand All @@ -45,6 +46,7 @@ with data as (

select
id,
id2,
start_tstamp

from data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0
config(
materialized='incremental',
incremental_strategy='delete+insert',
unique_key='id',
unique_key=['id', 'id2'],
upsert_date_key='start_tstamp',
tags=["requires_script"],
snowplow_optimize=true
Expand All @@ -28,6 +28,7 @@ with data as (

select
id,
id2,
start_tstamp

from data
Expand All @@ -37,6 +38,7 @@ with data as (

select
id,
id2,
start_tstamp

from data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ You may obtain a copy of the Snowplow Personal and Academic License Version 1.0
{% set lower_limit, upper_limit = limits[0], limits[1] %}
-- use those calculated min + max values to limit 'target' scan, to only the days with new data
{% set predicate_override %}
{{ date_column }} between '{{ lower_limit }}' and '{{ upper_limit }}'
{{target_tb}}.{{ date_column }} between '{{ lower_limit }}' and '{{ upper_limit }}'
{% endset %}
{% endif %}
{# Combine predicates with user provided ones #}
Expand Down

0 comments on commit 950daa7

Please sign in to comment.