-
Notifications
You must be signed in to change notification settings - Fork 238
/
Copy pathvalidate.sql
50 lines (39 loc) · 1.84 KB
/
validate.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{% macro dbt_spark_validate_get_file_format(raw_file_format) %}
{#-- Validate the file format #}
{% set accepted_formats = ['text', 'csv', 'json', 'jdbc', 'parquet', 'orc', 'hive', 'delta', 'iceberg', 'libsvm', 'hudi'] %}
{% set invalid_file_format_msg -%}
Invalid file format provided: {{ raw_file_format }}
Expected one of: {{ accepted_formats | join(', ') }}
{%- endset %}
{% if raw_file_format not in accepted_formats %}
{% do exceptions.raise_compiler_error(invalid_file_format_msg) %}
{% endif %}
{% do return(raw_file_format) %}
{% endmacro %}
{% macro dbt_spark_validate_get_incremental_strategy(raw_strategy, file_format) %}
{#-- Validate the incremental strategy #}
{% set invalid_strategy_msg -%}
Invalid incremental strategy provided: {{ raw_strategy }}
Expected one of: 'append', 'merge', 'insert_overwrite'
{%- endset %}
{% set invalid_merge_msg -%}
Invalid incremental strategy provided: {{ raw_strategy }}
You can only choose this strategy when file_format is set to 'delta' or 'iceberg' or 'hudi'
{%- endset %}
{% set invalid_insert_overwrite_endpoint_msg -%}
Invalid incremental strategy provided: {{ raw_strategy }}
You cannot use this strategy when connecting via endpoint
Use the 'append' or 'merge' strategy instead
{%- endset %}
{% if raw_strategy not in ['append', 'merge', 'insert_overwrite'] %}
{% do exceptions.raise_compiler_error(invalid_strategy_msg) %}
{%-else %}
{% if raw_strategy == 'merge' and file_format not in ['delta', 'iceberg', 'hudi'] %}
{% do exceptions.raise_compiler_error(invalid_merge_msg) %}
{% endif %}
{% if raw_strategy == 'insert_overwrite' and target.endpoint %}
{% do exceptions.raise_compiler_error(invalid_insert_overwrite_endpoint_msg) %}
{% endif %}
{% endif %}
{% do return(raw_strategy) %}
{% endmacro %}