Skip to content

Commit 63701c7

Browse files
committed
Added parallel support for incremental append SQL
1 parent b2daf0b commit 63701c7

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

dbt/include/oracle/macros/materializations/incremental/strategies.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@
9393
9494
9595
{% macro oracle__get_incremental_append_sql(args_dict) %}
96+
{%- set parallel = config.get('parallel', none) -%}
9697
{%- set dest_columns = args_dict["dest_columns"] -%}
9798
{%- set temp_relation = args_dict["temp_relation"] -%}
9899
{%- set target_relation = args_dict["target_relation"] -%}
99100
{%- set dest_column_names = dest_columns | map(attribute='name') | list -%}
100101
{%- set dest_cols_csv = get_quoted_column_csv(model, dest_column_names) -%}
101-
INSERT INTO {{ target_relation }} ({{ dest_cols_csv }})
102+
INSERT INTO {% if parallel %} /*+parallel({{ parallel }})*/ {% endif %} {{ target_relation }} ({{ dest_cols_csv }})
102103
(
103104
SELECT {{ dest_cols_csv }}
104105
FROM {{ temp_relation }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{#
2+
Copyright (c) 2022, Oracle and/or its affiliates.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
#}
16+
{{
17+
config(
18+
materialized='incremental',
19+
incremental_strategy='append',
20+
parallel=4,
21+
table_compression_clause='COLUMN STORE COMPRESS FOR QUERY LOW')
22+
}}
23+
24+
SELECT prod_name, channel_desc, calendar_month_desc,
25+
{{ snapshot_hash_arguments(['prod_name', 'channel_desc', 'calendar_month_desc']) }} AS group_id,
26+
TO_CHAR(SUM(amount_sold), '9,999,999,999') SALES$,
27+
RANK() OVER (ORDER BY SUM(amount_sold)) AS default_rank,
28+
RANK() OVER (ORDER BY SUM(amount_sold) DESC NULLS LAST) AS custom_rank
29+
FROM {{ source('sh_database', 'sales') }}, {{ source('sh_database', 'products') }}, {{ source('sh_database', 'customers') }},
30+
{{ source('sh_database', 'times') }}, {{ source('sh_database', 'channels') }}, {{ source('sh_database', 'countries') }}
31+
WHERE sales.prod_id=products.prod_id AND sales.cust_id=customers.cust_id
32+
AND customers.country_id = countries.country_id AND sales.time_id=times.time_id
33+
AND sales.channel_id=channels.channel_id
34+
AND country_iso_code='US'
35+
36+
{% if is_incremental() %}
37+
38+
AND times.calendar_month_desc > (SELECT MAX(calendar_month_desc) FROM {{ this }})
39+
40+
{% endif %}
41+
42+
GROUP BY prod_name, channel_desc, calendar_month_desc
43+

0 commit comments

Comments
 (0)