dbt-adapters 1.22.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. dbt/adapters/__about__.py +1 -0
  2. dbt/adapters/__init__.py +8 -0
  3. dbt/adapters/base/README.md +13 -0
  4. dbt/adapters/base/__init__.py +16 -0
  5. dbt/adapters/base/column.py +173 -0
  6. dbt/adapters/base/connections.py +429 -0
  7. dbt/adapters/base/impl.py +2036 -0
  8. dbt/adapters/base/meta.py +150 -0
  9. dbt/adapters/base/plugin.py +32 -0
  10. dbt/adapters/base/query_headers.py +106 -0
  11. dbt/adapters/base/relation.py +648 -0
  12. dbt/adapters/cache.py +521 -0
  13. dbt/adapters/capability.py +63 -0
  14. dbt/adapters/catalogs/__init__.py +14 -0
  15. dbt/adapters/catalogs/_client.py +54 -0
  16. dbt/adapters/catalogs/_constants.py +1 -0
  17. dbt/adapters/catalogs/_exceptions.py +39 -0
  18. dbt/adapters/catalogs/_integration.py +113 -0
  19. dbt/adapters/clients/__init__.py +0 -0
  20. dbt/adapters/clients/jinja.py +24 -0
  21. dbt/adapters/contracts/__init__.py +0 -0
  22. dbt/adapters/contracts/connection.py +229 -0
  23. dbt/adapters/contracts/macros.py +11 -0
  24. dbt/adapters/contracts/relation.py +160 -0
  25. dbt/adapters/events/README.md +51 -0
  26. dbt/adapters/events/__init__.py +0 -0
  27. dbt/adapters/events/adapter_types_pb2.py +2 -0
  28. dbt/adapters/events/base_types.py +36 -0
  29. dbt/adapters/events/logging.py +83 -0
  30. dbt/adapters/events/types.py +436 -0
  31. dbt/adapters/exceptions/__init__.py +40 -0
  32. dbt/adapters/exceptions/alias.py +24 -0
  33. dbt/adapters/exceptions/cache.py +68 -0
  34. dbt/adapters/exceptions/compilation.py +269 -0
  35. dbt/adapters/exceptions/connection.py +16 -0
  36. dbt/adapters/exceptions/database.py +51 -0
  37. dbt/adapters/factory.py +264 -0
  38. dbt/adapters/protocol.py +150 -0
  39. dbt/adapters/py.typed +0 -0
  40. dbt/adapters/record/__init__.py +2 -0
  41. dbt/adapters/record/base.py +291 -0
  42. dbt/adapters/record/cursor/cursor.py +69 -0
  43. dbt/adapters/record/cursor/description.py +37 -0
  44. dbt/adapters/record/cursor/execute.py +39 -0
  45. dbt/adapters/record/cursor/fetchall.py +69 -0
  46. dbt/adapters/record/cursor/fetchmany.py +23 -0
  47. dbt/adapters/record/cursor/fetchone.py +23 -0
  48. dbt/adapters/record/cursor/rowcount.py +23 -0
  49. dbt/adapters/record/handle.py +55 -0
  50. dbt/adapters/record/serialization.py +115 -0
  51. dbt/adapters/reference_keys.py +39 -0
  52. dbt/adapters/relation_configs/README.md +25 -0
  53. dbt/adapters/relation_configs/__init__.py +12 -0
  54. dbt/adapters/relation_configs/config_base.py +46 -0
  55. dbt/adapters/relation_configs/config_change.py +26 -0
  56. dbt/adapters/relation_configs/config_validation.py +57 -0
  57. dbt/adapters/sql/__init__.py +2 -0
  58. dbt/adapters/sql/connections.py +263 -0
  59. dbt/adapters/sql/impl.py +286 -0
  60. dbt/adapters/utils.py +69 -0
  61. dbt/include/__init__.py +3 -0
  62. dbt/include/global_project/__init__.py +4 -0
  63. dbt/include/global_project/dbt_project.yml +7 -0
  64. dbt/include/global_project/docs/overview.md +43 -0
  65. dbt/include/global_project/macros/adapters/apply_grants.sql +167 -0
  66. dbt/include/global_project/macros/adapters/columns.sql +144 -0
  67. dbt/include/global_project/macros/adapters/freshness.sql +32 -0
  68. dbt/include/global_project/macros/adapters/indexes.sql +41 -0
  69. dbt/include/global_project/macros/adapters/metadata.sql +105 -0
  70. dbt/include/global_project/macros/adapters/persist_docs.sql +33 -0
  71. dbt/include/global_project/macros/adapters/relation.sql +84 -0
  72. dbt/include/global_project/macros/adapters/schema.sql +20 -0
  73. dbt/include/global_project/macros/adapters/show.sql +26 -0
  74. dbt/include/global_project/macros/adapters/timestamps.sql +52 -0
  75. dbt/include/global_project/macros/adapters/validate_sql.sql +10 -0
  76. dbt/include/global_project/macros/etc/datetime.sql +62 -0
  77. dbt/include/global_project/macros/etc/statement.sql +52 -0
  78. dbt/include/global_project/macros/generic_test_sql/accepted_values.sql +27 -0
  79. dbt/include/global_project/macros/generic_test_sql/not_null.sql +9 -0
  80. dbt/include/global_project/macros/generic_test_sql/relationships.sql +23 -0
  81. dbt/include/global_project/macros/generic_test_sql/unique.sql +12 -0
  82. dbt/include/global_project/macros/get_custom_name/get_custom_alias.sql +36 -0
  83. dbt/include/global_project/macros/get_custom_name/get_custom_database.sql +32 -0
  84. dbt/include/global_project/macros/get_custom_name/get_custom_schema.sql +60 -0
  85. dbt/include/global_project/macros/materializations/configs.sql +21 -0
  86. dbt/include/global_project/macros/materializations/functions/aggregate.sql +65 -0
  87. dbt/include/global_project/macros/materializations/functions/function.sql +20 -0
  88. dbt/include/global_project/macros/materializations/functions/helpers.sql +20 -0
  89. dbt/include/global_project/macros/materializations/functions/scalar.sql +69 -0
  90. dbt/include/global_project/macros/materializations/hooks.sql +35 -0
  91. dbt/include/global_project/macros/materializations/models/clone/can_clone_table.sql +7 -0
  92. dbt/include/global_project/macros/materializations/models/clone/clone.sql +67 -0
  93. dbt/include/global_project/macros/materializations/models/clone/create_or_replace_clone.sql +7 -0
  94. dbt/include/global_project/macros/materializations/models/incremental/column_helpers.sql +80 -0
  95. dbt/include/global_project/macros/materializations/models/incremental/incremental.sql +99 -0
  96. dbt/include/global_project/macros/materializations/models/incremental/is_incremental.sql +13 -0
  97. dbt/include/global_project/macros/materializations/models/incremental/merge.sql +120 -0
  98. dbt/include/global_project/macros/materializations/models/incremental/on_schema_change.sql +159 -0
  99. dbt/include/global_project/macros/materializations/models/incremental/strategies.sql +92 -0
  100. dbt/include/global_project/macros/materializations/models/materialized_view.sql +121 -0
  101. dbt/include/global_project/macros/materializations/models/table.sql +64 -0
  102. dbt/include/global_project/macros/materializations/models/view.sql +72 -0
  103. dbt/include/global_project/macros/materializations/seeds/helpers.sql +128 -0
  104. dbt/include/global_project/macros/materializations/seeds/seed.sql +60 -0
  105. dbt/include/global_project/macros/materializations/snapshots/helpers.sql +345 -0
  106. dbt/include/global_project/macros/materializations/snapshots/snapshot.sql +109 -0
  107. dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql +34 -0
  108. dbt/include/global_project/macros/materializations/snapshots/strategies.sql +184 -0
  109. dbt/include/global_project/macros/materializations/tests/helpers.sql +44 -0
  110. dbt/include/global_project/macros/materializations/tests/test.sql +66 -0
  111. dbt/include/global_project/macros/materializations/tests/unit.sql +40 -0
  112. dbt/include/global_project/macros/materializations/tests/where_subquery.sql +15 -0
  113. dbt/include/global_project/macros/python_model/python.sql +114 -0
  114. dbt/include/global_project/macros/relations/column/columns_spec_ddl.sql +89 -0
  115. dbt/include/global_project/macros/relations/create.sql +23 -0
  116. dbt/include/global_project/macros/relations/create_backup.sql +17 -0
  117. dbt/include/global_project/macros/relations/create_intermediate.sql +17 -0
  118. dbt/include/global_project/macros/relations/drop.sql +41 -0
  119. dbt/include/global_project/macros/relations/drop_backup.sql +14 -0
  120. dbt/include/global_project/macros/relations/materialized_view/alter.sql +55 -0
  121. dbt/include/global_project/macros/relations/materialized_view/create.sql +10 -0
  122. dbt/include/global_project/macros/relations/materialized_view/drop.sql +14 -0
  123. dbt/include/global_project/macros/relations/materialized_view/refresh.sql +9 -0
  124. dbt/include/global_project/macros/relations/materialized_view/rename.sql +10 -0
  125. dbt/include/global_project/macros/relations/materialized_view/replace.sql +10 -0
  126. dbt/include/global_project/macros/relations/rename.sql +35 -0
  127. dbt/include/global_project/macros/relations/rename_intermediate.sql +14 -0
  128. dbt/include/global_project/macros/relations/replace.sql +50 -0
  129. dbt/include/global_project/macros/relations/schema.sql +8 -0
  130. dbt/include/global_project/macros/relations/table/create.sql +60 -0
  131. dbt/include/global_project/macros/relations/table/drop.sql +14 -0
  132. dbt/include/global_project/macros/relations/table/rename.sql +10 -0
  133. dbt/include/global_project/macros/relations/table/replace.sql +10 -0
  134. dbt/include/global_project/macros/relations/view/create.sql +27 -0
  135. dbt/include/global_project/macros/relations/view/drop.sql +14 -0
  136. dbt/include/global_project/macros/relations/view/rename.sql +10 -0
  137. dbt/include/global_project/macros/relations/view/replace.sql +66 -0
  138. dbt/include/global_project/macros/unit_test_sql/get_fixture_sql.sql +107 -0
  139. dbt/include/global_project/macros/utils/any_value.sql +9 -0
  140. dbt/include/global_project/macros/utils/array_append.sql +8 -0
  141. dbt/include/global_project/macros/utils/array_concat.sql +7 -0
  142. dbt/include/global_project/macros/utils/array_construct.sql +12 -0
  143. dbt/include/global_project/macros/utils/bool_or.sql +9 -0
  144. dbt/include/global_project/macros/utils/cast.sql +7 -0
  145. dbt/include/global_project/macros/utils/cast_bool_to_text.sql +7 -0
  146. dbt/include/global_project/macros/utils/concat.sql +7 -0
  147. dbt/include/global_project/macros/utils/data_types.sql +129 -0
  148. dbt/include/global_project/macros/utils/date.sql +10 -0
  149. dbt/include/global_project/macros/utils/date_spine.sql +75 -0
  150. dbt/include/global_project/macros/utils/date_trunc.sql +7 -0
  151. dbt/include/global_project/macros/utils/dateadd.sql +14 -0
  152. dbt/include/global_project/macros/utils/datediff.sql +14 -0
  153. dbt/include/global_project/macros/utils/equals.sql +14 -0
  154. dbt/include/global_project/macros/utils/escape_single_quotes.sql +8 -0
  155. dbt/include/global_project/macros/utils/except.sql +9 -0
  156. dbt/include/global_project/macros/utils/generate_series.sql +53 -0
  157. dbt/include/global_project/macros/utils/hash.sql +7 -0
  158. dbt/include/global_project/macros/utils/intersect.sql +9 -0
  159. dbt/include/global_project/macros/utils/last_day.sql +15 -0
  160. dbt/include/global_project/macros/utils/length.sql +11 -0
  161. dbt/include/global_project/macros/utils/listagg.sql +30 -0
  162. dbt/include/global_project/macros/utils/literal.sql +7 -0
  163. dbt/include/global_project/macros/utils/position.sql +11 -0
  164. dbt/include/global_project/macros/utils/replace.sql +14 -0
  165. dbt/include/global_project/macros/utils/right.sql +12 -0
  166. dbt/include/global_project/macros/utils/safe_cast.sql +9 -0
  167. dbt/include/global_project/macros/utils/split_part.sql +26 -0
  168. dbt/include/global_project/tests/generic/builtin.sql +30 -0
  169. dbt/include/py.typed +0 -0
  170. dbt_adapters-1.22.2.dist-info/METADATA +124 -0
  171. dbt_adapters-1.22.2.dist-info/RECORD +173 -0
  172. dbt_adapters-1.22.2.dist-info/WHEEL +4 -0
  173. dbt_adapters-1.22.2.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,52 @@
1
+ {%- macro current_timestamp() -%}
2
+ {{ adapter.dispatch('current_timestamp', 'dbt')() }}
3
+ {%- endmacro -%}
4
+
5
+ {% macro default__current_timestamp() -%}
6
+ {{ exceptions.raise_not_implemented(
7
+ 'current_timestamp macro not implemented for adapter ' + adapter.type()) }}
8
+ {%- endmacro %}
9
+
10
+ {%- macro snapshot_get_time() -%}
11
+ {{ adapter.dispatch('snapshot_get_time', 'dbt')() }}
12
+ {%- endmacro -%}
13
+
14
+ {% macro default__snapshot_get_time() %}
15
+ {{ current_timestamp() }}
16
+ {% endmacro %}
17
+
18
+ {% macro get_snapshot_get_time_data_type() %}
19
+ {% set snapshot_time = adapter.dispatch('snapshot_get_time', 'dbt')() %}
20
+ {% set time_data_type_sql = 'select ' ~ snapshot_time ~ ' as dbt_snapshot_time' %}
21
+ {% set snapshot_time_column_schema = get_column_schema_from_query(time_data_type_sql) %}
22
+ {% set time_data_type = snapshot_time_column_schema[0].dtype %}
23
+ {{ return(time_data_type or none) }}
24
+ {% endmacro %}
25
+
26
+ ---------------------------------------------
27
+
28
+ /* {#
29
+ DEPRECATED: DO NOT USE IN NEW PROJECTS
30
+
31
+ This is ONLY to handle the fact that Snowflake + Postgres had functionally
32
+ different implementations of {{ dbt.current_timestamp }} + {{ dbt_utils.current_timestamp }}
33
+
34
+ If you had a project or package that called {{ dbt_utils.current_timestamp() }}, you should
35
+ continue to use this macro to guarantee identical behavior on those two databases.
36
+ #} */
37
+
38
+ {% macro current_timestamp_backcompat() %}
39
+ {{ return(adapter.dispatch('current_timestamp_backcompat', 'dbt')()) }}
40
+ {% endmacro %}
41
+
42
+ {% macro default__current_timestamp_backcompat() %}
43
+ current_timestamp::timestamp
44
+ {% endmacro %}
45
+
46
+ {% macro current_timestamp_in_utc_backcompat() %}
47
+ {{ return(adapter.dispatch('current_timestamp_in_utc_backcompat', 'dbt')()) }}
48
+ {% endmacro %}
49
+
50
+ {% macro default__current_timestamp_in_utc_backcompat() %}
51
+ {{ return(adapter.dispatch('current_timestamp_backcompat', 'dbt')()) }}
52
+ {% endmacro %}
@@ -0,0 +1,10 @@
1
+ {% macro validate_sql(sql) -%}
2
+ {{ return(adapter.dispatch('validate_sql', 'dbt')(sql)) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__validate_sql(sql) -%}
6
+ {% call statement('validate_sql') -%}
7
+ explain {{ sql }}
8
+ {% endcall %}
9
+ {{ return(load_result('validate_sql')) }}
10
+ {% endmacro %}
@@ -0,0 +1,62 @@
1
+ {% macro convert_datetime(date_str, date_fmt) %}
2
+
3
+ {% set error_msg -%}
4
+ The provided partition date '{{ date_str }}' does not match the expected format '{{ date_fmt }}'
5
+ {%- endset %}
6
+
7
+ {% set res = try_or_compiler_error(error_msg, modules.datetime.datetime.strptime, date_str.strip(), date_fmt) %}
8
+ {{ return(res) }}
9
+
10
+ {% endmacro %}
11
+
12
+
13
+ {% macro dates_in_range(start_date_str, end_date_str=none, in_fmt="%Y%m%d", out_fmt="%Y%m%d") %}
14
+ {% set end_date_str = start_date_str if end_date_str is none else end_date_str %}
15
+
16
+ {% set start_date = convert_datetime(start_date_str, in_fmt) %}
17
+ {% set end_date = convert_datetime(end_date_str, in_fmt) %}
18
+
19
+ {% set day_count = (end_date - start_date).days %}
20
+ {% if day_count < 0 %}
21
+ {% set msg -%}
22
+ Partition start date is after the end date ({{ start_date }}, {{ end_date }})
23
+ {%- endset %}
24
+
25
+ {{ exceptions.raise_compiler_error(msg, model) }}
26
+ {% endif %}
27
+
28
+ {% set date_list = [] %}
29
+ {% for i in range(0, day_count + 1) %}
30
+ {% set the_date = (modules.datetime.timedelta(days=i) + start_date) %}
31
+ {% if not out_fmt %}
32
+ {% set _ = date_list.append(the_date) %}
33
+ {% else %}
34
+ {% set _ = date_list.append(the_date.strftime(out_fmt)) %}
35
+ {% endif %}
36
+ {% endfor %}
37
+
38
+ {{ return(date_list) }}
39
+ {% endmacro %}
40
+
41
+
42
+ {% macro partition_range(raw_partition_date, date_fmt='%Y%m%d') %}
43
+ {% set partition_range = (raw_partition_date | string).split(",") %}
44
+
45
+ {% if (partition_range | length) == 1 %}
46
+ {% set start_date = partition_range[0] %}
47
+ {% set end_date = none %}
48
+ {% elif (partition_range | length) == 2 %}
49
+ {% set start_date = partition_range[0] %}
50
+ {% set end_date = partition_range[1] %}
51
+ {% else %}
52
+ {{ exceptions.raise_compiler_error("Invalid partition time. Expected format: {Start Date}[,{End Date}]. Got: " ~ raw_partition_date) }}
53
+ {% endif %}
54
+
55
+ {{ return(dates_in_range(start_date, end_date, in_fmt=date_fmt)) }}
56
+ {% endmacro %}
57
+
58
+
59
+ {% macro py_current_timestring() %}
60
+ {% set dt = modules.datetime.datetime.now() %}
61
+ {% do return(dt.strftime("%Y%m%d%H%M%S%f")) %}
62
+ {% endmacro %}
@@ -0,0 +1,52 @@
1
+ {#--
2
+ The macro override naming method (spark__statement) only works for macros which are called with adapter.dispatch. For macros called directly, you can just redefine them.
3
+ --#}
4
+ {%- macro statement(name=None, fetch_result=False, auto_begin=True, language='sql') -%}
5
+ {%- if execute: -%}
6
+ {%- set compiled_code = caller() -%}
7
+
8
+ {%- if name == 'main' -%}
9
+ {{ log('Writing runtime {} for node "{}"'.format(language, model['unique_id'])) }}
10
+ {{ write(compiled_code) }}
11
+ {%- endif -%}
12
+ {%- if language == 'sql'-%}
13
+ {%- set res, table = adapter.execute(compiled_code, auto_begin=auto_begin, fetch=fetch_result) -%}
14
+ {%- elif language == 'python' -%}
15
+ {%- set res = submit_python_job(model, compiled_code) -%}
16
+ {#-- TODO: What should table be for python models? --#}
17
+ {%- set table = None -%}
18
+ {%- else -%}
19
+ {% do exceptions.raise_compiler_error("statement macro didn't get supported language") %}
20
+ {%- endif -%}
21
+
22
+ {%- if name is not none -%}
23
+ {{ store_result(name, response=res, agate_table=table) }}
24
+ {%- endif -%}
25
+
26
+ {%- endif -%}
27
+ {%- endmacro %}
28
+
29
+
30
+ {% macro noop_statement(name=None, message=None, code=None, rows_affected=None, res=None) -%}
31
+ {%- set sql = caller() -%}
32
+
33
+ {%- if name == 'main' -%}
34
+ {{ log('Writing runtime SQL for node "{}"'.format(model['unique_id'])) }}
35
+ {{ write(sql) }}
36
+ {%- endif -%}
37
+
38
+ {%- if name is not none -%}
39
+ {{ store_raw_result(name, message=message, code=code, rows_affected=rows_affected, agate_table=res) }}
40
+ {%- endif -%}
41
+
42
+ {%- endmacro %}
43
+
44
+
45
+ {# a user-friendly interface into statements #}
46
+ {% macro run_query(sql) %}
47
+ {% call statement("run_query_statement", fetch_result=true, auto_begin=false) %}
48
+ {{ sql }}
49
+ {% endcall %}
50
+
51
+ {% do return(load_result("run_query_statement").table) %}
52
+ {% endmacro %}
@@ -0,0 +1,27 @@
1
+ {% macro default__test_accepted_values(model, column_name, values, quote=True) %}
2
+
3
+ with all_values as (
4
+
5
+ select
6
+ {{ column_name }} as value_field,
7
+ count(*) as n_records
8
+
9
+ from {{ model }}
10
+ group by {{ column_name }}
11
+
12
+ )
13
+
14
+ select *
15
+ from all_values
16
+ where value_field not in (
17
+ {% for value in values -%}
18
+ {% if quote -%}
19
+ '{{ value }}'
20
+ {%- else -%}
21
+ {{ value }}
22
+ {%- endif -%}
23
+ {%- if not loop.last -%},{%- endif %}
24
+ {%- endfor %}
25
+ )
26
+
27
+ {% endmacro %}
@@ -0,0 +1,9 @@
1
+ {% macro default__test_not_null(model, column_name) %}
2
+
3
+ {% set column_list = '*' if should_store_failures() else column_name %}
4
+
5
+ select {{ column_list }}
6
+ from {{ model }}
7
+ where {{ column_name }} is null
8
+
9
+ {% endmacro %}
@@ -0,0 +1,23 @@
1
+ {% macro default__test_relationships(model, column_name, to, field) %}
2
+
3
+ with child as (
4
+ select {{ column_name }} as from_field
5
+ from {{ model }}
6
+ where {{ column_name }} is not null
7
+ ),
8
+
9
+ parent as (
10
+ select {{ field }} as to_field
11
+ from {{ to }}
12
+ )
13
+
14
+ select
15
+ from_field
16
+
17
+ from child
18
+ left join parent
19
+ on child.from_field = parent.to_field
20
+
21
+ where parent.to_field is null
22
+
23
+ {% endmacro %}
@@ -0,0 +1,12 @@
1
+ {% macro default__test_unique(model, column_name) %}
2
+
3
+ select
4
+ {{ column_name }} as unique_field,
5
+ count(*) as n_records
6
+
7
+ from {{ model }}
8
+ where {{ column_name }} is not null
9
+ group by {{ column_name }}
10
+ having count(*) > 1
11
+
12
+ {% endmacro %}
@@ -0,0 +1,36 @@
1
+
2
+ {#
3
+ Renders a alias name given a custom alias name. If the custom
4
+ alias name is none, then the resulting alias is just the filename of the
5
+ model. If an alias override is specified, then that is used.
6
+
7
+ This macro can be overriden in projects to define different semantics
8
+ for rendering a alias name.
9
+
10
+ Arguments:
11
+ custom_alias_name: The custom alias name specified for a model, or none
12
+ node: The available node that an alias is being generated for, or none
13
+
14
+ #}
15
+
16
+ {% macro generate_alias_name(custom_alias_name=none, node=none) -%}
17
+ {% do return(adapter.dispatch('generate_alias_name', 'dbt')(custom_alias_name, node)) %}
18
+ {%- endmacro %}
19
+
20
+ {% macro default__generate_alias_name(custom_alias_name=none, node=none) -%}
21
+
22
+ {%- if custom_alias_name -%}
23
+
24
+ {{ custom_alias_name | trim }}
25
+
26
+ {%- elif node.version -%}
27
+
28
+ {{ return(node.name ~ "_v" ~ (node.version | replace(".", "_"))) }}
29
+
30
+ {%- else -%}
31
+
32
+ {{ node.name }}
33
+
34
+ {%- endif -%}
35
+
36
+ {%- endmacro %}
@@ -0,0 +1,32 @@
1
+ {#
2
+ Renders a database name given a custom database name. If the custom
3
+ database name is none, then the resulting database is just the "database"
4
+ value in the specified target. If a database override is specified, then
5
+ the custom database name is used instead of the default "database" value.
6
+
7
+ This macro can be overriden in projects to define different semantics
8
+ for rendering a database name.
9
+
10
+ Arguments:
11
+ custom_database_name: The custom database name specified for a model, or none
12
+ node: The node the database is being generated for
13
+
14
+ #}
15
+
16
+ {% macro generate_database_name(custom_database_name=none, node=none) -%}
17
+ {% do return(adapter.dispatch('generate_database_name', 'dbt')(custom_database_name, node)) %}
18
+ {%- endmacro %}
19
+
20
+ {% macro default__generate_database_name(custom_database_name=none, node=none) -%}
21
+ {%- set default_database = target.database -%}
22
+ {%- if custom_database_name is none -%}
23
+
24
+ {{ default_database }}
25
+
26
+ {%- else -%}
27
+
28
+ {{ custom_database_name }}
29
+
30
+ {%- endif -%}
31
+
32
+ {%- endmacro %}
@@ -0,0 +1,60 @@
1
+
2
+ {#
3
+ Renders a schema name given a custom schema name. If the custom
4
+ schema name is none, then the resulting schema is just the "schema"
5
+ value in the specified target. If a schema override is specified, then
6
+ the resulting schema is the default schema concatenated with the
7
+ custom schema.
8
+
9
+ This macro can be overriden in projects to define different semantics
10
+ for rendering a schema name.
11
+
12
+ Arguments:
13
+ custom_schema_name: The custom schema name specified for a model, or none
14
+ node: The node the schema is being generated for
15
+
16
+ #}
17
+ {% macro generate_schema_name(custom_schema_name=none, node=none) -%}
18
+ {{ return(adapter.dispatch('generate_schema_name', 'dbt')(custom_schema_name, node)) }}
19
+ {% endmacro %}
20
+
21
+ {% macro default__generate_schema_name(custom_schema_name, node) -%}
22
+
23
+ {%- set default_schema = target.schema -%}
24
+ {%- if custom_schema_name is none -%}
25
+
26
+ {{ default_schema }}
27
+
28
+ {%- else -%}
29
+
30
+ {{ default_schema }}_{{ custom_schema_name | trim }}
31
+
32
+ {%- endif -%}
33
+
34
+ {%- endmacro %}
35
+
36
+
37
+ {#
38
+ Renders a schema name given a custom schema name. In production, this macro
39
+ will render out the overriden schema name for a model. Otherwise, the default
40
+ schema specified in the active target is used.
41
+
42
+ Arguments:
43
+ custom_schema_name: The custom schema name specified for a model, or none
44
+ node: The node the schema is being generated for
45
+
46
+ #}
47
+ {% macro generate_schema_name_for_env(custom_schema_name, node) -%}
48
+
49
+ {%- set default_schema = target.schema -%}
50
+ {%- if target.name == 'prod' and custom_schema_name is not none -%}
51
+
52
+ {{ custom_schema_name | trim }}
53
+
54
+ {%- else -%}
55
+
56
+ {{ default_schema }}
57
+
58
+ {%- endif -%}
59
+
60
+ {%- endmacro %}
@@ -0,0 +1,21 @@
1
+ {% macro set_sql_header(config) -%}
2
+ {{ config.set('sql_header', caller()) }}
3
+ {%- endmacro %}
4
+
5
+
6
+ {% macro should_full_refresh() %}
7
+ {% set config_full_refresh = config.get('full_refresh') %}
8
+ {% if config_full_refresh is none %}
9
+ {% set config_full_refresh = flags.FULL_REFRESH %}
10
+ {% endif %}
11
+ {% do return(config_full_refresh) %}
12
+ {% endmacro %}
13
+
14
+
15
+ {% macro should_store_failures() %}
16
+ {% set config_store_failures = config.get('store_failures') %}
17
+ {% if config_store_failures is none %}
18
+ {% set config_store_failures = flags.STORE_FAILURES %}
19
+ {% endif %}
20
+ {% do return(config_store_failures) %}
21
+ {% endmacro %}
@@ -0,0 +1,65 @@
1
+ --- get signature dispatch + default macro ---
2
+
3
+ {% macro get_aggregate_function_create_replace_signature(target_relation) %}
4
+ {{ return(adapter.dispatch('get_aggregate_function_create_replace_signature', 'dbt')(target_relation)) }}
5
+ {% endmacro %}
6
+
7
+ {% macro default__get_aggregate_function_create_replace_signature(target_relation) %}
8
+ CREATE OR REPLACE AGGREGATE FUNCTION {{ target_relation.render() }} ({{ get_formatted_aggregate_function_args()}})
9
+ RETURNS {{ model.returns.data_type }}
10
+ {{ get_function_language_specifier() }}
11
+ {{ get_aggregate_function_volatility_specifier() }}
12
+ {% if model.get('language') == 'python' %}
13
+ {{ get_function_python_options() }}
14
+ {% endif %}
15
+ AS
16
+ {% endmacro %}
17
+
18
+ --- formatted args dispatch + default macro ---
19
+
20
+ {% macro get_formatted_aggregate_function_args() %}
21
+ {{ return(adapter.dispatch('get_formatted_aggregate_function_args', 'dbt')()) }}
22
+ {% endmacro %}
23
+
24
+ {% macro default__get_formatted_aggregate_function_args() %}
25
+ {# conveniently we can reuse the sql scalar function args #}
26
+ {{ formatted_scalar_function_args_sql() }}
27
+ {% endmacro %}
28
+
29
+ --- function language specifier dispatch + default macro ---
30
+
31
+ {% macro get_function_language_specifier() %}
32
+ {{ return(adapter.dispatch('get_function_language_specifier', 'dbt')()) }}
33
+ {% endmacro %}
34
+
35
+ {% macro default__get_function_language_specifier() %}
36
+ {% set language = model.get('language') %}
37
+ {% if language == 'sql' %}
38
+ {# generally you dont need to specify the language for sql functions #}
39
+ {% elif language == 'python' %}
40
+ LANGUAGE PYTHON
41
+ {% else %}
42
+ {{ 'LANGUAGE ' ~ language.upper() }}
43
+ {% endif %}
44
+ {% endmacro %}
45
+
46
+ --- function volatility specifier dispatch + default macro ---
47
+
48
+ {% macro get_aggregate_function_volatility_specifier() %}
49
+ {{ return(adapter.dispatch('get_aggregate_function_volatility_specifier', 'dbt')()) }}
50
+ {% endmacro %}
51
+
52
+ {% macro default__get_aggregate_function_volatility_specifier() %}
53
+ {{ scalar_function_volatility_sql() }}
54
+ {% endmacro %}
55
+
56
+ --- function python options + default macro ---
57
+
58
+ {% macro get_function_python_options() %}
59
+ {{ return(adapter.dispatch('get_function_python_options', 'dbt')()) }}
60
+ {% endmacro %}
61
+
62
+ {% macro default__get_function_python_options() %}
63
+ RUNTIME_VERSION = '{{ model.config.get('runtime_version') }}'
64
+ HANDLER = '{{ model.config.get('entry_point') }}'
65
+ {% endmacro %}
@@ -0,0 +1,20 @@
1
+ {% materialization function, default, supported_languages=['sql', 'python'] %}
2
+ {% set existing_relation = load_cached_relation(this) %}
3
+ {% set target_relation = this.incorporate(type=this.Function) %}
4
+
5
+ {{ run_hooks(pre_hooks) }}
6
+
7
+ {% set function_config = this.get_function_config(model) %}
8
+ {% set macro_name = this.get_function_macro_name(function_config) %}
9
+
10
+ {# Doing this aliasing of adapter.dispatch is a hacky way to disable the static analysis of actually calling adapter.dispatch #}
11
+ {# This is necessary because the static analysis breaks being able to dynamically pass a macro_name #}
12
+ {% set _dispatch = adapter.dispatch %}
13
+
14
+ {% set build_sql = _dispatch(macro_name, 'dbt')(target_relation) %}
15
+ {{ function_execute_build_sql(build_sql, existing_relation, target_relation) }}
16
+ {{ run_hooks(post_hooks) }}
17
+
18
+ {{ return({'relations': [target_relation]}) }}
19
+
20
+ {% endmaterialization %}
@@ -0,0 +1,20 @@
1
+ {% macro function_execute_build_sql(build_sql, existing_relation, target_relation) %}
2
+ {{ return(adapter.dispatch('function_execute_build_sql', 'dbt')(build_sql, existing_relation, target_relation)) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__function_execute_build_sql(build_sql, existing_relation, target_relation) %}
6
+
7
+ {% set grant_config = config.get('grants') %}
8
+
9
+ {% call statement(name="main") %}
10
+ {{ build_sql }}
11
+ {% endcall %}
12
+
13
+ {% set should_revoke = should_revoke(existing_relation, full_refresh_mode=True) %}
14
+ {% do apply_grants(target_relation, grant_config, should_revoke=should_revoke) %}
15
+
16
+ {% do persist_docs(target_relation, model) %}
17
+
18
+ {{ adapter.commit() }}
19
+
20
+ {% endmacro %}
@@ -0,0 +1,69 @@
1
+ {% macro scalar_function_sql(target_relation) %}
2
+ {{ return(adapter.dispatch('scalar_function_sql', 'dbt')(target_relation)) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__scalar_function_sql(target_relation) %}
6
+ {{ scalar_function_create_replace_signature_sql(target_relation) }}
7
+ {{ scalar_function_body_sql() }};
8
+ {% endmacro %}
9
+
10
+ {% macro scalar_function_create_replace_signature_sql(target_relation) %}
11
+ {{ return(adapter.dispatch('scalar_function_create_replace_signature_sql', 'dbt')(target_relation)) }}
12
+ {% endmacro %}
13
+
14
+ {% macro default__scalar_function_create_replace_signature_sql(target_relation) %}
15
+ CREATE OR REPLACE FUNCTION {{ target_relation.render() }} ({{ formatted_scalar_function_args_sql()}})
16
+ RETURNS {{ model.returns.data_type }}
17
+ {{ scalar_function_volatility_sql() }}
18
+ AS
19
+ {% endmacro %}
20
+
21
+ {% macro formatted_scalar_function_args_sql() %}
22
+ {{ return(adapter.dispatch('formatted_scalar_function_args_sql', 'dbt')()) }}
23
+ {% endmacro %}
24
+
25
+ {% macro default__formatted_scalar_function_args_sql() %}
26
+ {% set args = [] %}
27
+ {% for arg in model.arguments -%}
28
+ {%- do args.append(arg.name ~ ' ' ~ arg.data_type) -%}
29
+ {%- endfor %}
30
+ {{ args | join(', ') }}
31
+ {% endmacro %}
32
+
33
+ {% macro scalar_function_body_sql() %}
34
+ {{ return(adapter.dispatch('scalar_function_body_sql', 'dbt')()) }}
35
+ {% endmacro %}
36
+
37
+ {% macro default__scalar_function_body_sql() %}
38
+ $$
39
+ {{ model.compiled_code }}
40
+ $$ LANGUAGE SQL
41
+ {% endmacro %}
42
+
43
+ {% macro scalar_function_volatility_sql() %}
44
+ {{ return(adapter.dispatch('scalar_function_volatility_sql', 'dbt')()) }}
45
+ {% endmacro %}
46
+
47
+ {% macro default__scalar_function_volatility_sql() %}
48
+ {% set volatility = model.config.get('volatility') %}
49
+ {% if volatility == 'deterministic' %}
50
+ IMMUTABLE
51
+ {% elif volatility == 'stable' %}
52
+ STABLE
53
+ {% elif volatility == 'non-deterministic' %}
54
+ VOLATILE
55
+ {% elif volatility != none %}
56
+ {# This shouldn't happen unless a new volatility is invented #}
57
+ {% do unsupported_volatility_warning(volatility) %}
58
+ {% endif %}
59
+ {# If no volatility is set, don't add anything and let the data warehouse default it #}
60
+ {% endmacro %}
61
+
62
+ {% macro unsupported_volatility_warning(volatility) %}
63
+ {{ return(adapter.dispatch('unsupported_volatility_warning', 'dbt')(volatility)) }}
64
+ {% endmacro %}
65
+
66
+ {% macro default__unsupported_volatility_warning(volatility) %}
67
+ {% set msg = "Found `" ~ volatility ~ "` volatility specified on function `" ~ model.name ~ "`. This volatility is not supported by " ~ adapter.type() ~ ", and will be ignored" %}
68
+ {% do exceptions.warn(msg) %}
69
+ {% endmacro %}
@@ -0,0 +1,35 @@
1
+ {% macro run_hooks(hooks, inside_transaction=True) %}
2
+ {% for hook in hooks | selectattr('transaction', 'equalto', inside_transaction) %}
3
+ {% if not inside_transaction and loop.first %}
4
+ {% call statement(auto_begin=inside_transaction) %}
5
+ commit;
6
+ {% endcall %}
7
+ {% endif %}
8
+ {% set rendered = render(hook.get('sql')) | trim %}
9
+ {% if (rendered | length) > 0 %}
10
+ {% call statement(auto_begin=inside_transaction) %}
11
+ {{ rendered }}
12
+ {% endcall %}
13
+ {% endif %}
14
+ {% endfor %}
15
+ {% endmacro %}
16
+
17
+
18
+ {% macro make_hook_config(sql, inside_transaction) %}
19
+ {{ tojson({"sql": sql, "transaction": inside_transaction}) }}
20
+ {% endmacro %}
21
+
22
+
23
+ {% macro before_begin(sql) %}
24
+ {{ make_hook_config(sql, inside_transaction=False) }}
25
+ {% endmacro %}
26
+
27
+
28
+ {% macro in_transaction(sql) %}
29
+ {{ make_hook_config(sql, inside_transaction=True) }}
30
+ {% endmacro %}
31
+
32
+
33
+ {% macro after_commit(sql) %}
34
+ {{ make_hook_config(sql, inside_transaction=False) }}
35
+ {% endmacro %}
@@ -0,0 +1,7 @@
1
+ {% macro can_clone_table() %}
2
+ {{ return(adapter.dispatch('can_clone_table', 'dbt')()) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__can_clone_table() %}
6
+ {{ return(False) }}
7
+ {% endmacro %}