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.
- dbt/adapters/__about__.py +1 -0
- dbt/adapters/__init__.py +8 -0
- dbt/adapters/base/README.md +13 -0
- dbt/adapters/base/__init__.py +16 -0
- dbt/adapters/base/column.py +173 -0
- dbt/adapters/base/connections.py +429 -0
- dbt/adapters/base/impl.py +2036 -0
- dbt/adapters/base/meta.py +150 -0
- dbt/adapters/base/plugin.py +32 -0
- dbt/adapters/base/query_headers.py +106 -0
- dbt/adapters/base/relation.py +648 -0
- dbt/adapters/cache.py +521 -0
- dbt/adapters/capability.py +63 -0
- dbt/adapters/catalogs/__init__.py +14 -0
- dbt/adapters/catalogs/_client.py +54 -0
- dbt/adapters/catalogs/_constants.py +1 -0
- dbt/adapters/catalogs/_exceptions.py +39 -0
- dbt/adapters/catalogs/_integration.py +113 -0
- dbt/adapters/clients/__init__.py +0 -0
- dbt/adapters/clients/jinja.py +24 -0
- dbt/adapters/contracts/__init__.py +0 -0
- dbt/adapters/contracts/connection.py +229 -0
- dbt/adapters/contracts/macros.py +11 -0
- dbt/adapters/contracts/relation.py +160 -0
- dbt/adapters/events/README.md +51 -0
- dbt/adapters/events/__init__.py +0 -0
- dbt/adapters/events/adapter_types_pb2.py +2 -0
- dbt/adapters/events/base_types.py +36 -0
- dbt/adapters/events/logging.py +83 -0
- dbt/adapters/events/types.py +436 -0
- dbt/adapters/exceptions/__init__.py +40 -0
- dbt/adapters/exceptions/alias.py +24 -0
- dbt/adapters/exceptions/cache.py +68 -0
- dbt/adapters/exceptions/compilation.py +269 -0
- dbt/adapters/exceptions/connection.py +16 -0
- dbt/adapters/exceptions/database.py +51 -0
- dbt/adapters/factory.py +264 -0
- dbt/adapters/protocol.py +150 -0
- dbt/adapters/py.typed +0 -0
- dbt/adapters/record/__init__.py +2 -0
- dbt/adapters/record/base.py +291 -0
- dbt/adapters/record/cursor/cursor.py +69 -0
- dbt/adapters/record/cursor/description.py +37 -0
- dbt/adapters/record/cursor/execute.py +39 -0
- dbt/adapters/record/cursor/fetchall.py +69 -0
- dbt/adapters/record/cursor/fetchmany.py +23 -0
- dbt/adapters/record/cursor/fetchone.py +23 -0
- dbt/adapters/record/cursor/rowcount.py +23 -0
- dbt/adapters/record/handle.py +55 -0
- dbt/adapters/record/serialization.py +115 -0
- dbt/adapters/reference_keys.py +39 -0
- dbt/adapters/relation_configs/README.md +25 -0
- dbt/adapters/relation_configs/__init__.py +12 -0
- dbt/adapters/relation_configs/config_base.py +46 -0
- dbt/adapters/relation_configs/config_change.py +26 -0
- dbt/adapters/relation_configs/config_validation.py +57 -0
- dbt/adapters/sql/__init__.py +2 -0
- dbt/adapters/sql/connections.py +263 -0
- dbt/adapters/sql/impl.py +286 -0
- dbt/adapters/utils.py +69 -0
- dbt/include/__init__.py +3 -0
- dbt/include/global_project/__init__.py +4 -0
- dbt/include/global_project/dbt_project.yml +7 -0
- dbt/include/global_project/docs/overview.md +43 -0
- dbt/include/global_project/macros/adapters/apply_grants.sql +167 -0
- dbt/include/global_project/macros/adapters/columns.sql +144 -0
- dbt/include/global_project/macros/adapters/freshness.sql +32 -0
- dbt/include/global_project/macros/adapters/indexes.sql +41 -0
- dbt/include/global_project/macros/adapters/metadata.sql +105 -0
- dbt/include/global_project/macros/adapters/persist_docs.sql +33 -0
- dbt/include/global_project/macros/adapters/relation.sql +84 -0
- dbt/include/global_project/macros/adapters/schema.sql +20 -0
- dbt/include/global_project/macros/adapters/show.sql +26 -0
- dbt/include/global_project/macros/adapters/timestamps.sql +52 -0
- dbt/include/global_project/macros/adapters/validate_sql.sql +10 -0
- dbt/include/global_project/macros/etc/datetime.sql +62 -0
- dbt/include/global_project/macros/etc/statement.sql +52 -0
- dbt/include/global_project/macros/generic_test_sql/accepted_values.sql +27 -0
- dbt/include/global_project/macros/generic_test_sql/not_null.sql +9 -0
- dbt/include/global_project/macros/generic_test_sql/relationships.sql +23 -0
- dbt/include/global_project/macros/generic_test_sql/unique.sql +12 -0
- dbt/include/global_project/macros/get_custom_name/get_custom_alias.sql +36 -0
- dbt/include/global_project/macros/get_custom_name/get_custom_database.sql +32 -0
- dbt/include/global_project/macros/get_custom_name/get_custom_schema.sql +60 -0
- dbt/include/global_project/macros/materializations/configs.sql +21 -0
- dbt/include/global_project/macros/materializations/functions/aggregate.sql +65 -0
- dbt/include/global_project/macros/materializations/functions/function.sql +20 -0
- dbt/include/global_project/macros/materializations/functions/helpers.sql +20 -0
- dbt/include/global_project/macros/materializations/functions/scalar.sql +69 -0
- dbt/include/global_project/macros/materializations/hooks.sql +35 -0
- dbt/include/global_project/macros/materializations/models/clone/can_clone_table.sql +7 -0
- dbt/include/global_project/macros/materializations/models/clone/clone.sql +67 -0
- dbt/include/global_project/macros/materializations/models/clone/create_or_replace_clone.sql +7 -0
- dbt/include/global_project/macros/materializations/models/incremental/column_helpers.sql +80 -0
- dbt/include/global_project/macros/materializations/models/incremental/incremental.sql +99 -0
- dbt/include/global_project/macros/materializations/models/incremental/is_incremental.sql +13 -0
- dbt/include/global_project/macros/materializations/models/incremental/merge.sql +120 -0
- dbt/include/global_project/macros/materializations/models/incremental/on_schema_change.sql +159 -0
- dbt/include/global_project/macros/materializations/models/incremental/strategies.sql +92 -0
- dbt/include/global_project/macros/materializations/models/materialized_view.sql +121 -0
- dbt/include/global_project/macros/materializations/models/table.sql +64 -0
- dbt/include/global_project/macros/materializations/models/view.sql +72 -0
- dbt/include/global_project/macros/materializations/seeds/helpers.sql +128 -0
- dbt/include/global_project/macros/materializations/seeds/seed.sql +60 -0
- dbt/include/global_project/macros/materializations/snapshots/helpers.sql +345 -0
- dbt/include/global_project/macros/materializations/snapshots/snapshot.sql +109 -0
- dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql +34 -0
- dbt/include/global_project/macros/materializations/snapshots/strategies.sql +184 -0
- dbt/include/global_project/macros/materializations/tests/helpers.sql +44 -0
- dbt/include/global_project/macros/materializations/tests/test.sql +66 -0
- dbt/include/global_project/macros/materializations/tests/unit.sql +40 -0
- dbt/include/global_project/macros/materializations/tests/where_subquery.sql +15 -0
- dbt/include/global_project/macros/python_model/python.sql +114 -0
- dbt/include/global_project/macros/relations/column/columns_spec_ddl.sql +89 -0
- dbt/include/global_project/macros/relations/create.sql +23 -0
- dbt/include/global_project/macros/relations/create_backup.sql +17 -0
- dbt/include/global_project/macros/relations/create_intermediate.sql +17 -0
- dbt/include/global_project/macros/relations/drop.sql +41 -0
- dbt/include/global_project/macros/relations/drop_backup.sql +14 -0
- dbt/include/global_project/macros/relations/materialized_view/alter.sql +55 -0
- dbt/include/global_project/macros/relations/materialized_view/create.sql +10 -0
- dbt/include/global_project/macros/relations/materialized_view/drop.sql +14 -0
- dbt/include/global_project/macros/relations/materialized_view/refresh.sql +9 -0
- dbt/include/global_project/macros/relations/materialized_view/rename.sql +10 -0
- dbt/include/global_project/macros/relations/materialized_view/replace.sql +10 -0
- dbt/include/global_project/macros/relations/rename.sql +35 -0
- dbt/include/global_project/macros/relations/rename_intermediate.sql +14 -0
- dbt/include/global_project/macros/relations/replace.sql +50 -0
- dbt/include/global_project/macros/relations/schema.sql +8 -0
- dbt/include/global_project/macros/relations/table/create.sql +60 -0
- dbt/include/global_project/macros/relations/table/drop.sql +14 -0
- dbt/include/global_project/macros/relations/table/rename.sql +10 -0
- dbt/include/global_project/macros/relations/table/replace.sql +10 -0
- dbt/include/global_project/macros/relations/view/create.sql +27 -0
- dbt/include/global_project/macros/relations/view/drop.sql +14 -0
- dbt/include/global_project/macros/relations/view/rename.sql +10 -0
- dbt/include/global_project/macros/relations/view/replace.sql +66 -0
- dbt/include/global_project/macros/unit_test_sql/get_fixture_sql.sql +107 -0
- dbt/include/global_project/macros/utils/any_value.sql +9 -0
- dbt/include/global_project/macros/utils/array_append.sql +8 -0
- dbt/include/global_project/macros/utils/array_concat.sql +7 -0
- dbt/include/global_project/macros/utils/array_construct.sql +12 -0
- dbt/include/global_project/macros/utils/bool_or.sql +9 -0
- dbt/include/global_project/macros/utils/cast.sql +7 -0
- dbt/include/global_project/macros/utils/cast_bool_to_text.sql +7 -0
- dbt/include/global_project/macros/utils/concat.sql +7 -0
- dbt/include/global_project/macros/utils/data_types.sql +129 -0
- dbt/include/global_project/macros/utils/date.sql +10 -0
- dbt/include/global_project/macros/utils/date_spine.sql +75 -0
- dbt/include/global_project/macros/utils/date_trunc.sql +7 -0
- dbt/include/global_project/macros/utils/dateadd.sql +14 -0
- dbt/include/global_project/macros/utils/datediff.sql +14 -0
- dbt/include/global_project/macros/utils/equals.sql +14 -0
- dbt/include/global_project/macros/utils/escape_single_quotes.sql +8 -0
- dbt/include/global_project/macros/utils/except.sql +9 -0
- dbt/include/global_project/macros/utils/generate_series.sql +53 -0
- dbt/include/global_project/macros/utils/hash.sql +7 -0
- dbt/include/global_project/macros/utils/intersect.sql +9 -0
- dbt/include/global_project/macros/utils/last_day.sql +15 -0
- dbt/include/global_project/macros/utils/length.sql +11 -0
- dbt/include/global_project/macros/utils/listagg.sql +30 -0
- dbt/include/global_project/macros/utils/literal.sql +7 -0
- dbt/include/global_project/macros/utils/position.sql +11 -0
- dbt/include/global_project/macros/utils/replace.sql +14 -0
- dbt/include/global_project/macros/utils/right.sql +12 -0
- dbt/include/global_project/macros/utils/safe_cast.sql +9 -0
- dbt/include/global_project/macros/utils/split_part.sql +26 -0
- dbt/include/global_project/tests/generic/builtin.sql +30 -0
- dbt/include/py.typed +0 -0
- dbt_adapters-1.22.2.dist-info/METADATA +124 -0
- dbt_adapters-1.22.2.dist-info/RECORD +173 -0
- dbt_adapters-1.22.2.dist-info/WHEEL +4 -0
- dbt_adapters-1.22.2.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
{# ------- BOOLEAN MACROS --------- #}
|
|
2
|
+
|
|
3
|
+
{#
|
|
4
|
+
-- COPY GRANTS
|
|
5
|
+
-- When a relational object (view or table) is replaced in this database,
|
|
6
|
+
-- do previous grants carry over to the new object? This may depend on:
|
|
7
|
+
-- whether we use alter-rename-swap versus CREATE OR REPLACE
|
|
8
|
+
-- user-supplied configuration (e.g. copy_grants on Snowflake)
|
|
9
|
+
-- By default, play it safe, assume TRUE: that grants ARE copied over.
|
|
10
|
+
-- This means dbt will first "show" current grants and then calculate diffs.
|
|
11
|
+
-- It may require an additional query than is strictly necessary,
|
|
12
|
+
-- but better safe than sorry.
|
|
13
|
+
#}
|
|
14
|
+
|
|
15
|
+
{% macro copy_grants() %}
|
|
16
|
+
{{ return(adapter.dispatch('copy_grants', 'dbt')()) }}
|
|
17
|
+
{% endmacro %}
|
|
18
|
+
|
|
19
|
+
{% macro default__copy_grants() %}
|
|
20
|
+
{{ return(True) }}
|
|
21
|
+
{% endmacro %}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
{#
|
|
25
|
+
-- SUPPORT MULTIPLE GRANTEES PER DCL STATEMENT
|
|
26
|
+
-- Does this database support 'grant {privilege} to {grantee_1}, {grantee_2}, ...'
|
|
27
|
+
-- Or must these be separate statements:
|
|
28
|
+
-- `grant {privilege} to {grantee_1}`;
|
|
29
|
+
-- `grant {privilege} to {grantee_2}`;
|
|
30
|
+
-- By default, pick the former, because it's what we prefer when available.
|
|
31
|
+
#}
|
|
32
|
+
|
|
33
|
+
{% macro support_multiple_grantees_per_dcl_statement() %}
|
|
34
|
+
{{ return(adapter.dispatch('support_multiple_grantees_per_dcl_statement', 'dbt')()) }}
|
|
35
|
+
{% endmacro %}
|
|
36
|
+
|
|
37
|
+
{%- macro default__support_multiple_grantees_per_dcl_statement() -%}
|
|
38
|
+
{{ return(True) }}
|
|
39
|
+
{%- endmacro -%}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
{% macro should_revoke(existing_relation, full_refresh_mode=True) %}
|
|
43
|
+
|
|
44
|
+
{% if not existing_relation %}
|
|
45
|
+
{#-- The table doesn't already exist, so no grants to copy over --#}
|
|
46
|
+
{{ return(False) }}
|
|
47
|
+
{% elif full_refresh_mode %}
|
|
48
|
+
{#-- The object is being REPLACED -- whether grants are copied over depends on the value of user config --#}
|
|
49
|
+
{{ return(copy_grants()) }}
|
|
50
|
+
{% else %}
|
|
51
|
+
{#-- The table is being merged/upserted/inserted -- grants will be carried over --#}
|
|
52
|
+
{{ return(True) }}
|
|
53
|
+
{% endif %}
|
|
54
|
+
|
|
55
|
+
{% endmacro %}
|
|
56
|
+
|
|
57
|
+
{# ------- DCL STATEMENT TEMPLATES --------- #}
|
|
58
|
+
|
|
59
|
+
{% macro get_show_grant_sql(relation) %}
|
|
60
|
+
{{ return(adapter.dispatch("get_show_grant_sql", "dbt")(relation)) }}
|
|
61
|
+
{% endmacro %}
|
|
62
|
+
|
|
63
|
+
{% macro default__get_show_grant_sql(relation) %}
|
|
64
|
+
show grants on {{ relation.render() }}
|
|
65
|
+
{% endmacro %}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
{% macro get_grant_sql(relation, privilege, grantees) %}
|
|
69
|
+
{{ return(adapter.dispatch('get_grant_sql', 'dbt')(relation, privilege, grantees)) }}
|
|
70
|
+
{% endmacro %}
|
|
71
|
+
|
|
72
|
+
{%- macro default__get_grant_sql(relation, privilege, grantees) -%}
|
|
73
|
+
grant {{ privilege }} on {{ relation.render() }} to {{ grantees | join(', ') }}
|
|
74
|
+
{%- endmacro -%}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
{% macro get_revoke_sql(relation, privilege, grantees) %}
|
|
78
|
+
{{ return(adapter.dispatch('get_revoke_sql', 'dbt')(relation, privilege, grantees)) }}
|
|
79
|
+
{% endmacro %}
|
|
80
|
+
|
|
81
|
+
{%- macro default__get_revoke_sql(relation, privilege, grantees) -%}
|
|
82
|
+
revoke {{ privilege }} on {{ relation.render() }} from {{ grantees | join(', ') }}
|
|
83
|
+
{%- endmacro -%}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
{# ------- RUNTIME APPLICATION --------- #}
|
|
87
|
+
|
|
88
|
+
{% macro get_dcl_statement_list(relation, grant_config, get_dcl_macro) %}
|
|
89
|
+
{{ return(adapter.dispatch('get_dcl_statement_list', 'dbt')(relation, grant_config, get_dcl_macro)) }}
|
|
90
|
+
{% endmacro %}
|
|
91
|
+
|
|
92
|
+
{%- macro default__get_dcl_statement_list(relation, grant_config, get_dcl_macro) -%}
|
|
93
|
+
{#
|
|
94
|
+
-- Unpack grant_config into specific privileges and the set of users who need them granted/revoked.
|
|
95
|
+
-- Depending on whether this database supports multiple grantees per statement, pass in the list of
|
|
96
|
+
-- all grantees per privilege, or (if not) template one statement per privilege-grantee pair.
|
|
97
|
+
-- `get_dcl_macro` will be either `get_grant_sql` or `get_revoke_sql`
|
|
98
|
+
#}
|
|
99
|
+
{%- set dcl_statements = [] -%}
|
|
100
|
+
{%- for privilege, grantees in grant_config.items() %}
|
|
101
|
+
{%- if support_multiple_grantees_per_dcl_statement() and grantees -%}
|
|
102
|
+
{%- set dcl = get_dcl_macro(relation, privilege, grantees) -%}
|
|
103
|
+
{%- do dcl_statements.append(dcl) -%}
|
|
104
|
+
{%- else -%}
|
|
105
|
+
{%- for grantee in grantees -%}
|
|
106
|
+
{% set dcl = get_dcl_macro(relation, privilege, [grantee]) %}
|
|
107
|
+
{%- do dcl_statements.append(dcl) -%}
|
|
108
|
+
{% endfor -%}
|
|
109
|
+
{%- endif -%}
|
|
110
|
+
{%- endfor -%}
|
|
111
|
+
{{ return(dcl_statements) }}
|
|
112
|
+
{%- endmacro %}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
{% macro call_dcl_statements(dcl_statement_list) %}
|
|
116
|
+
{{ return(adapter.dispatch("call_dcl_statements", "dbt")(dcl_statement_list)) }}
|
|
117
|
+
{% endmacro %}
|
|
118
|
+
|
|
119
|
+
{% macro default__call_dcl_statements(dcl_statement_list) %}
|
|
120
|
+
{#
|
|
121
|
+
-- By default, supply all grant + revoke statements in a single semicolon-separated block,
|
|
122
|
+
-- so that they're all processed together.
|
|
123
|
+
|
|
124
|
+
-- Some databases do not support this. Those adapters will need to override this macro
|
|
125
|
+
-- to run each statement individually.
|
|
126
|
+
#}
|
|
127
|
+
{% call statement('grants') %}
|
|
128
|
+
{% for dcl_statement in dcl_statement_list %}
|
|
129
|
+
{{ dcl_statement }};
|
|
130
|
+
{% endfor %}
|
|
131
|
+
{% endcall %}
|
|
132
|
+
{% endmacro %}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
{% macro apply_grants(relation, grant_config, should_revoke) %}
|
|
136
|
+
{{ return(adapter.dispatch("apply_grants", "dbt")(relation, grant_config, should_revoke)) }}
|
|
137
|
+
{% endmacro %}
|
|
138
|
+
|
|
139
|
+
{% macro default__apply_grants(relation, grant_config, should_revoke=True) %}
|
|
140
|
+
{#-- If grant_config is {} or None, this is a no-op --#}
|
|
141
|
+
{% if grant_config %}
|
|
142
|
+
{% if should_revoke %}
|
|
143
|
+
{#-- We think previous grants may have carried over --#}
|
|
144
|
+
{#-- Show current grants and calculate diffs --#}
|
|
145
|
+
{% set current_grants_table = run_query(get_show_grant_sql(relation)) %}
|
|
146
|
+
{% set current_grants_dict = adapter.standardize_grants_dict(current_grants_table) %}
|
|
147
|
+
{% set needs_granting = diff_of_two_dicts(grant_config, current_grants_dict) %}
|
|
148
|
+
{% set needs_revoking = diff_of_two_dicts(current_grants_dict, grant_config) %}
|
|
149
|
+
{% if not (needs_granting or needs_revoking) %}
|
|
150
|
+
{{ log('On ' ~ relation.render() ~': All grants are in place, no revocation or granting needed.')}}
|
|
151
|
+
{% endif %}
|
|
152
|
+
{% else %}
|
|
153
|
+
{#-- We don't think there's any chance of previous grants having carried over. --#}
|
|
154
|
+
{#-- Jump straight to granting what the user has configured. --#}
|
|
155
|
+
{% set needs_revoking = {} %}
|
|
156
|
+
{% set needs_granting = grant_config %}
|
|
157
|
+
{% endif %}
|
|
158
|
+
{% if needs_granting or needs_revoking %}
|
|
159
|
+
{% set revoke_statement_list = get_dcl_statement_list(relation, needs_revoking, get_revoke_sql) %}
|
|
160
|
+
{% set grant_statement_list = get_dcl_statement_list(relation, needs_granting, get_grant_sql) %}
|
|
161
|
+
{% set dcl_statement_list = revoke_statement_list + grant_statement_list %}
|
|
162
|
+
{% if dcl_statement_list %}
|
|
163
|
+
{{ call_dcl_statements(dcl_statement_list) }}
|
|
164
|
+
{% endif %}
|
|
165
|
+
{% endif %}
|
|
166
|
+
{% endif %}
|
|
167
|
+
{% endmacro %}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
{% macro get_columns_in_relation(relation) -%}
|
|
2
|
+
{{ return(adapter.dispatch('get_columns_in_relation', 'dbt')(relation)) }}
|
|
3
|
+
{% endmacro %}
|
|
4
|
+
|
|
5
|
+
{% macro default__get_columns_in_relation(relation) -%}
|
|
6
|
+
{{ exceptions.raise_not_implemented(
|
|
7
|
+
'get_columns_in_relation macro not implemented for adapter '+adapter.type()) }}
|
|
8
|
+
{% endmacro %}
|
|
9
|
+
|
|
10
|
+
{# helper for adapter-specific implementations of get_columns_in_relation #}
|
|
11
|
+
{% macro sql_convert_columns_in_relation(table) -%}
|
|
12
|
+
{% set columns = [] %}
|
|
13
|
+
{% for row in table %}
|
|
14
|
+
{% do columns.append(api.Column(*row)) %}
|
|
15
|
+
{% endfor %}
|
|
16
|
+
{{ return(columns) }}
|
|
17
|
+
{% endmacro %}
|
|
18
|
+
|
|
19
|
+
{%- macro get_list_of_column_names(columns) -%}
|
|
20
|
+
{% set col_names = [] %}
|
|
21
|
+
{% for col in columns %}
|
|
22
|
+
{% do col_names.append(col.name) %}
|
|
23
|
+
{% endfor %}
|
|
24
|
+
{{ return(col_names) }}
|
|
25
|
+
{% endmacro %}
|
|
26
|
+
|
|
27
|
+
{% macro get_empty_subquery_sql(select_sql, select_sql_header=none) -%}
|
|
28
|
+
{{ return(adapter.dispatch('get_empty_subquery_sql', 'dbt')(select_sql, select_sql_header)) }}
|
|
29
|
+
{% endmacro %}
|
|
30
|
+
|
|
31
|
+
{#
|
|
32
|
+
Builds a query that results in the same schema as the given select_sql statement, without necessitating a data scan.
|
|
33
|
+
Useful for running a query in a 'pre-flight' context, such as model contract enforcement (assert_columns_equivalent macro).
|
|
34
|
+
#}
|
|
35
|
+
{% macro default__get_empty_subquery_sql(select_sql, select_sql_header=none) %}
|
|
36
|
+
{%- if select_sql_header is not none -%}
|
|
37
|
+
{{ select_sql_header }}
|
|
38
|
+
{%- endif -%}
|
|
39
|
+
select * from (
|
|
40
|
+
{{ select_sql }}
|
|
41
|
+
) as __dbt_sbq
|
|
42
|
+
where false
|
|
43
|
+
limit 0
|
|
44
|
+
{% endmacro %}
|
|
45
|
+
|
|
46
|
+
{% macro get_empty_schema_sql(columns) -%}
|
|
47
|
+
{{ return(adapter.dispatch('get_empty_schema_sql', 'dbt')(columns)) }}
|
|
48
|
+
{% endmacro %}
|
|
49
|
+
|
|
50
|
+
{% macro default__get_empty_schema_sql(columns) %}
|
|
51
|
+
{%- set col_err = [] -%}
|
|
52
|
+
{%- set col_naked_numeric = [] -%}
|
|
53
|
+
select
|
|
54
|
+
{% for i in columns %}
|
|
55
|
+
{%- set col = columns[i] -%}
|
|
56
|
+
{%- if col['data_type'] is not defined -%}
|
|
57
|
+
{%- do col_err.append(col['name']) -%}
|
|
58
|
+
{#-- If this column's type is just 'numeric' then it is missing precision/scale, raise a warning --#}
|
|
59
|
+
{%- elif col['data_type'].strip().lower() in ('numeric', 'decimal', 'number') -%}
|
|
60
|
+
{%- do col_naked_numeric.append(col['name']) -%}
|
|
61
|
+
{%- endif -%}
|
|
62
|
+
{% set col_name = adapter.quote(col['name']) if col.get('quote') else col['name'] %}
|
|
63
|
+
{{ cast('null', col['data_type']) }} as {{ col_name }}{{ ", " if not loop.last }}
|
|
64
|
+
{%- endfor -%}
|
|
65
|
+
{%- if (col_err | length) > 0 -%}
|
|
66
|
+
{{ exceptions.column_type_missing(column_names=col_err) }}
|
|
67
|
+
{%- elif (col_naked_numeric | length) > 0 -%}
|
|
68
|
+
{{ exceptions.warn("Detected columns with numeric type and unspecified precision/scale, this can lead to unintended rounding: " ~ col_naked_numeric ~ "`") }}
|
|
69
|
+
{%- endif -%}
|
|
70
|
+
{% endmacro %}
|
|
71
|
+
|
|
72
|
+
{% macro get_column_schema_from_query(select_sql, select_sql_header=none) -%}
|
|
73
|
+
{% set columns = [] %}
|
|
74
|
+
{# -- Using an 'empty subquery' here to get the same schema as the given select_sql statement, without necessitating a data scan.#}
|
|
75
|
+
{% set sql = get_empty_subquery_sql(select_sql, select_sql_header) %}
|
|
76
|
+
{% set column_schema = adapter.get_column_schema_from_query(sql) %}
|
|
77
|
+
{{ return(column_schema) }}
|
|
78
|
+
{% endmacro %}
|
|
79
|
+
|
|
80
|
+
-- here for back compat
|
|
81
|
+
{% macro get_columns_in_query(select_sql) -%}
|
|
82
|
+
{{ return(adapter.dispatch('get_columns_in_query', 'dbt')(select_sql)) }}
|
|
83
|
+
{% endmacro %}
|
|
84
|
+
|
|
85
|
+
{% macro default__get_columns_in_query(select_sql) %}
|
|
86
|
+
{% call statement('get_columns_in_query', fetch_result=True, auto_begin=False) -%}
|
|
87
|
+
{{ get_empty_subquery_sql(select_sql) }}
|
|
88
|
+
{% endcall %}
|
|
89
|
+
{{ return(load_result('get_columns_in_query').table.columns | map(attribute='name') | list) }}
|
|
90
|
+
{% endmacro %}
|
|
91
|
+
|
|
92
|
+
{% macro alter_column_type(relation, column_name, new_column_type) -%}
|
|
93
|
+
{{ return(adapter.dispatch('alter_column_type', 'dbt')(relation, column_name, new_column_type)) }}
|
|
94
|
+
{% endmacro %}
|
|
95
|
+
|
|
96
|
+
{% macro default__alter_column_type(relation, column_name, new_column_type) -%}
|
|
97
|
+
{#
|
|
98
|
+
1. Create a new column (w/ temp name and correct type)
|
|
99
|
+
2. Copy data over to it
|
|
100
|
+
3. Drop the existing column (cascade!)
|
|
101
|
+
4. Rename the new column to existing column
|
|
102
|
+
#}
|
|
103
|
+
{%- set tmp_column = column_name + "__dbt_alter" -%}
|
|
104
|
+
|
|
105
|
+
{% call statement('alter_column_type') %}
|
|
106
|
+
alter table {{ relation.render() }} add column {{ adapter.quote(tmp_column) }} {{ new_column_type }};
|
|
107
|
+
update {{ relation.render() }} set {{ adapter.quote(tmp_column) }} = {{ adapter.quote(column_name) }};
|
|
108
|
+
alter table {{ relation.render() }} drop column {{ adapter.quote(column_name) }} cascade;
|
|
109
|
+
alter table {{ relation.render() }} rename column {{ adapter.quote(tmp_column) }} to {{ adapter.quote(column_name) }}
|
|
110
|
+
{% endcall %}
|
|
111
|
+
|
|
112
|
+
{% endmacro %}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
{% macro alter_relation_add_remove_columns(relation, add_columns = none, remove_columns = none) -%}
|
|
116
|
+
{{ return(adapter.dispatch('alter_relation_add_remove_columns', 'dbt')(relation, add_columns, remove_columns)) }}
|
|
117
|
+
{% endmacro %}
|
|
118
|
+
|
|
119
|
+
{% macro default__alter_relation_add_remove_columns(relation, add_columns, remove_columns) %}
|
|
120
|
+
|
|
121
|
+
{% if add_columns is none %}
|
|
122
|
+
{% set add_columns = [] %}
|
|
123
|
+
{% endif %}
|
|
124
|
+
{% if remove_columns is none %}
|
|
125
|
+
{% set remove_columns = [] %}
|
|
126
|
+
{% endif %}
|
|
127
|
+
|
|
128
|
+
{% set sql -%}
|
|
129
|
+
|
|
130
|
+
alter {{ relation.type }} {{ relation.render() }}
|
|
131
|
+
|
|
132
|
+
{% for column in add_columns %}
|
|
133
|
+
add column {{ column.quoted }} {{ column.expanded_data_type }}{{ ',' if not loop.last }}
|
|
134
|
+
{% endfor %}{{ ',' if add_columns and remove_columns }}
|
|
135
|
+
|
|
136
|
+
{% for column in remove_columns %}
|
|
137
|
+
drop column {{ column.quoted }}{{ ',' if not loop.last }}
|
|
138
|
+
{% endfor %}
|
|
139
|
+
|
|
140
|
+
{%- endset -%}
|
|
141
|
+
|
|
142
|
+
{% do run_query(sql) %}
|
|
143
|
+
|
|
144
|
+
{% endmacro %}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{% macro collect_freshness(source, loaded_at_field, filter) %}
|
|
2
|
+
{{ return(adapter.dispatch('collect_freshness', 'dbt')(source, loaded_at_field, filter))}}
|
|
3
|
+
{% endmacro %}
|
|
4
|
+
|
|
5
|
+
{% macro default__collect_freshness(source, loaded_at_field, filter) %}
|
|
6
|
+
{% call statement('collect_freshness', fetch_result=True, auto_begin=False) -%}
|
|
7
|
+
select
|
|
8
|
+
max({{ loaded_at_field }}) as max_loaded_at,
|
|
9
|
+
{{ current_timestamp() }} as snapshotted_at
|
|
10
|
+
from {{ source }}
|
|
11
|
+
{% if filter %}
|
|
12
|
+
where {{ filter }}
|
|
13
|
+
{% endif %}
|
|
14
|
+
{% endcall %}
|
|
15
|
+
{{ return(load_result('collect_freshness')) }}
|
|
16
|
+
{% endmacro %}
|
|
17
|
+
|
|
18
|
+
{% macro collect_freshness_custom_sql(source, loaded_at_query) %}
|
|
19
|
+
{{ return(adapter.dispatch('collect_freshness_custom_sql', 'dbt')(source, loaded_at_query))}}
|
|
20
|
+
{% endmacro %}
|
|
21
|
+
|
|
22
|
+
{% macro default__collect_freshness_custom_sql(source, loaded_at_query) %}
|
|
23
|
+
{% call statement('collect_freshness_custom_sql', fetch_result=True, auto_begin=False) -%}
|
|
24
|
+
with source_query as (
|
|
25
|
+
{{ loaded_at_query }}
|
|
26
|
+
)
|
|
27
|
+
select
|
|
28
|
+
(select * from source_query) as max_loaded_at,
|
|
29
|
+
{{ current_timestamp() }} as snapshotted_at
|
|
30
|
+
{% endcall %}
|
|
31
|
+
{{ return(load_result('collect_freshness_custom_sql')) }}
|
|
32
|
+
{% endmacro %}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{% macro get_create_index_sql(relation, index_dict) -%}
|
|
2
|
+
{{ return(adapter.dispatch('get_create_index_sql', 'dbt')(relation, index_dict)) }}
|
|
3
|
+
{% endmacro %}
|
|
4
|
+
|
|
5
|
+
{% macro default__get_create_index_sql(relation, index_dict) -%}
|
|
6
|
+
{% do return(None) %}
|
|
7
|
+
{% endmacro %}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
{% macro create_indexes(relation) -%}
|
|
11
|
+
{{ adapter.dispatch('create_indexes', 'dbt')(relation) }}
|
|
12
|
+
{%- endmacro %}
|
|
13
|
+
|
|
14
|
+
{% macro default__create_indexes(relation) -%}
|
|
15
|
+
{%- set _indexes = config.get('indexes', default=[]) -%}
|
|
16
|
+
|
|
17
|
+
{% for _index_dict in _indexes %}
|
|
18
|
+
{% set create_index_sql = get_create_index_sql(relation, _index_dict) %}
|
|
19
|
+
{% if create_index_sql %}
|
|
20
|
+
{% do run_query(create_index_sql) %}
|
|
21
|
+
{% endif %}
|
|
22
|
+
{% endfor %}
|
|
23
|
+
{% endmacro %}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
{% macro get_drop_index_sql(relation, index_name) -%}
|
|
27
|
+
{{ adapter.dispatch('get_drop_index_sql', 'dbt')(relation, index_name) }}
|
|
28
|
+
{%- endmacro %}
|
|
29
|
+
|
|
30
|
+
{% macro default__get_drop_index_sql(relation, index_name) -%}
|
|
31
|
+
{{ exceptions.raise_compiler_error("`get_drop_index_sql has not been implemented for this adapter.") }}
|
|
32
|
+
{%- endmacro %}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
{% macro get_show_indexes_sql(relation) -%}
|
|
36
|
+
{{ adapter.dispatch('get_show_indexes_sql', 'dbt')(relation) }}
|
|
37
|
+
{%- endmacro %}
|
|
38
|
+
|
|
39
|
+
{% macro default__get_show_indexes_sql(relation) -%}
|
|
40
|
+
{{ exceptions.raise_compiler_error("`get_show_indexes_sql has not been implemented for this adapter.") }}
|
|
41
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
{% macro get_catalog_relations(information_schema, relations) -%}
|
|
2
|
+
{{ return(adapter.dispatch('get_catalog_relations', 'dbt')(information_schema, relations)) }}
|
|
3
|
+
{%- endmacro %}
|
|
4
|
+
|
|
5
|
+
{% macro default__get_catalog_relations(information_schema, relations) -%}
|
|
6
|
+
{% set typename = adapter.type() %}
|
|
7
|
+
{% set msg -%}
|
|
8
|
+
get_catalog_relations not implemented for {{ typename }}
|
|
9
|
+
{%- endset %}
|
|
10
|
+
|
|
11
|
+
{{ exceptions.raise_compiler_error(msg) }}
|
|
12
|
+
{%- endmacro %}
|
|
13
|
+
|
|
14
|
+
{% macro get_catalog(information_schema, schemas) -%}
|
|
15
|
+
{{ return(adapter.dispatch('get_catalog', 'dbt')(information_schema, schemas)) }}
|
|
16
|
+
{%- endmacro %}
|
|
17
|
+
|
|
18
|
+
{% macro default__get_catalog(information_schema, schemas) -%}
|
|
19
|
+
|
|
20
|
+
{% set typename = adapter.type() %}
|
|
21
|
+
{% set msg -%}
|
|
22
|
+
get_catalog not implemented for {{ typename }}
|
|
23
|
+
{%- endset %}
|
|
24
|
+
|
|
25
|
+
{{ exceptions.raise_compiler_error(msg) }}
|
|
26
|
+
{% endmacro %}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
{% macro information_schema_name(database) %}
|
|
30
|
+
{{ return(adapter.dispatch('information_schema_name', 'dbt')(database)) }}
|
|
31
|
+
{% endmacro %}
|
|
32
|
+
|
|
33
|
+
{% macro default__information_schema_name(database) -%}
|
|
34
|
+
{%- if database -%}
|
|
35
|
+
{{ database }}.INFORMATION_SCHEMA
|
|
36
|
+
{%- else -%}
|
|
37
|
+
INFORMATION_SCHEMA
|
|
38
|
+
{%- endif -%}
|
|
39
|
+
{%- endmacro %}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
{% macro list_schemas(database) -%}
|
|
43
|
+
{{ return(adapter.dispatch('list_schemas', 'dbt')(database)) }}
|
|
44
|
+
{% endmacro %}
|
|
45
|
+
|
|
46
|
+
{% macro default__list_schemas(database) -%}
|
|
47
|
+
{% set sql %}
|
|
48
|
+
select distinct schema_name
|
|
49
|
+
from {{ information_schema_name(database) }}.SCHEMATA
|
|
50
|
+
where catalog_name ilike '{{ database }}'
|
|
51
|
+
{% endset %}
|
|
52
|
+
{{ return(run_query(sql)) }}
|
|
53
|
+
{% endmacro %}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
{% macro check_schema_exists(information_schema, schema) -%}
|
|
57
|
+
{{ return(adapter.dispatch('check_schema_exists', 'dbt')(information_schema, schema)) }}
|
|
58
|
+
{% endmacro %}
|
|
59
|
+
|
|
60
|
+
{% macro default__check_schema_exists(information_schema, schema) -%}
|
|
61
|
+
{% set sql -%}
|
|
62
|
+
select count(*)
|
|
63
|
+
from {{ information_schema.replace(information_schema_view='SCHEMATA') }}
|
|
64
|
+
where catalog_name='{{ information_schema.database }}'
|
|
65
|
+
and schema_name='{{ schema }}'
|
|
66
|
+
{%- endset %}
|
|
67
|
+
{{ return(run_query(sql)) }}
|
|
68
|
+
{% endmacro %}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
{% macro list_relations_without_caching(schema_relation) %}
|
|
72
|
+
{{ return(adapter.dispatch('list_relations_without_caching', 'dbt')(schema_relation)) }}
|
|
73
|
+
{% endmacro %}
|
|
74
|
+
|
|
75
|
+
{% macro default__list_relations_without_caching(schema_relation) %}
|
|
76
|
+
{{ exceptions.raise_not_implemented(
|
|
77
|
+
'list_relations_without_caching macro not implemented for adapter '+adapter.type()) }}
|
|
78
|
+
{% endmacro %}
|
|
79
|
+
|
|
80
|
+
{% macro get_catalog_for_single_relation(relation) %}
|
|
81
|
+
{{ return(adapter.dispatch('get_catalog_for_single_relation', 'dbt')(relation)) }}
|
|
82
|
+
{% endmacro %}
|
|
83
|
+
|
|
84
|
+
{% macro default__get_catalog_for_single_relation(relation) %}
|
|
85
|
+
{{ exceptions.raise_not_implemented(
|
|
86
|
+
'get_catalog_for_single_relation macro not implemented for adapter '+adapter.type()) }}
|
|
87
|
+
{% endmacro %}
|
|
88
|
+
|
|
89
|
+
{% macro get_relations() %}
|
|
90
|
+
{{ return(adapter.dispatch('get_relations', 'dbt')()) }}
|
|
91
|
+
{% endmacro %}
|
|
92
|
+
|
|
93
|
+
{% macro default__get_relations() %}
|
|
94
|
+
{{ exceptions.raise_not_implemented(
|
|
95
|
+
'get_relations macro not implemented for adapter '+adapter.type()) }}
|
|
96
|
+
{% endmacro %}
|
|
97
|
+
|
|
98
|
+
{% macro get_relation_last_modified(information_schema, relations) %}
|
|
99
|
+
{{ return(adapter.dispatch('get_relation_last_modified', 'dbt')(information_schema, relations)) }}
|
|
100
|
+
{% endmacro %}
|
|
101
|
+
|
|
102
|
+
{% macro default__get_relation_last_modified(information_schema, relations) %}
|
|
103
|
+
{{ exceptions.raise_not_implemented(
|
|
104
|
+
'get_relation_last_modified macro not implemented for adapter ' + adapter.type()) }}
|
|
105
|
+
{% endmacro %}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{% macro alter_column_comment(relation, column_dict) -%}
|
|
2
|
+
{{ return(adapter.dispatch('alter_column_comment', 'dbt')(relation, column_dict)) }}
|
|
3
|
+
{% endmacro %}
|
|
4
|
+
|
|
5
|
+
{% macro default__alter_column_comment(relation, column_dict) -%}
|
|
6
|
+
{{ exceptions.raise_not_implemented(
|
|
7
|
+
'alter_column_comment macro not implemented for adapter '+adapter.type()) }}
|
|
8
|
+
{% endmacro %}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
{% macro alter_relation_comment(relation, relation_comment) -%}
|
|
12
|
+
{{ return(adapter.dispatch('alter_relation_comment', 'dbt')(relation, relation_comment)) }}
|
|
13
|
+
{% endmacro %}
|
|
14
|
+
|
|
15
|
+
{% macro default__alter_relation_comment(relation, relation_comment) -%}
|
|
16
|
+
{{ exceptions.raise_not_implemented(
|
|
17
|
+
'alter_relation_comment macro not implemented for adapter '+adapter.type()) }}
|
|
18
|
+
{% endmacro %}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
{% macro persist_docs(relation, model, for_relation=true, for_columns=true) -%}
|
|
22
|
+
{{ return(adapter.dispatch('persist_docs', 'dbt')(relation, model, for_relation, for_columns)) }}
|
|
23
|
+
{% endmacro %}
|
|
24
|
+
|
|
25
|
+
{% macro default__persist_docs(relation, model, for_relation, for_columns) -%}
|
|
26
|
+
{% if for_relation and config.persist_relation_docs() and model.description %}
|
|
27
|
+
{% do run_query(alter_relation_comment(relation, model.description)) %}
|
|
28
|
+
{% endif %}
|
|
29
|
+
|
|
30
|
+
{% if for_columns and config.persist_column_docs() and model.columns %}
|
|
31
|
+
{% do run_query(alter_column_comment(relation, model.columns)) %}
|
|
32
|
+
{% endif %}
|
|
33
|
+
{% endmacro %}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{% macro make_intermediate_relation(base_relation, suffix='__dbt_tmp') %}
|
|
2
|
+
{{ return(adapter.dispatch('make_intermediate_relation', 'dbt')(base_relation, suffix)) }}
|
|
3
|
+
{% endmacro %}
|
|
4
|
+
|
|
5
|
+
{% macro default__make_intermediate_relation(base_relation, suffix) %}
|
|
6
|
+
{{ return(default__make_temp_relation(base_relation, suffix)) }}
|
|
7
|
+
{% endmacro %}
|
|
8
|
+
|
|
9
|
+
{% macro make_temp_relation(base_relation, suffix='__dbt_tmp') %}
|
|
10
|
+
{#-- This ensures microbatch batches get unique temp relations to avoid clobbering --#}
|
|
11
|
+
{% if suffix == '__dbt_tmp' and model.batch %}
|
|
12
|
+
{% set suffix = suffix ~ '_' ~ model.batch.id %}
|
|
13
|
+
{% endif %}
|
|
14
|
+
|
|
15
|
+
{{ return(adapter.dispatch('make_temp_relation', 'dbt')(base_relation, suffix)) }}
|
|
16
|
+
{% endmacro %}
|
|
17
|
+
|
|
18
|
+
{% macro default__make_temp_relation(base_relation, suffix) %}
|
|
19
|
+
{%- set temp_identifier = base_relation.identifier ~ suffix -%}
|
|
20
|
+
{%- set temp_relation = base_relation.incorporate(
|
|
21
|
+
path={"identifier": temp_identifier}) -%}
|
|
22
|
+
|
|
23
|
+
{{ return(temp_relation) }}
|
|
24
|
+
{% endmacro %}
|
|
25
|
+
|
|
26
|
+
{% macro make_backup_relation(base_relation, backup_relation_type, suffix='__dbt_backup') %}
|
|
27
|
+
{{ return(adapter.dispatch('make_backup_relation', 'dbt')(base_relation, backup_relation_type, suffix)) }}
|
|
28
|
+
{% endmacro %}
|
|
29
|
+
|
|
30
|
+
{% macro default__make_backup_relation(base_relation, backup_relation_type, suffix) %}
|
|
31
|
+
{%- set backup_identifier = base_relation.identifier ~ suffix -%}
|
|
32
|
+
{%- set backup_relation = base_relation.incorporate(
|
|
33
|
+
path={"identifier": backup_identifier},
|
|
34
|
+
type=backup_relation_type
|
|
35
|
+
) -%}
|
|
36
|
+
{{ return(backup_relation) }}
|
|
37
|
+
{% endmacro %}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
{% macro truncate_relation(relation) -%}
|
|
41
|
+
{{ return(adapter.dispatch('truncate_relation', 'dbt')(relation)) }}
|
|
42
|
+
{% endmacro %}
|
|
43
|
+
|
|
44
|
+
{% macro default__truncate_relation(relation) -%}
|
|
45
|
+
{% call statement('truncate_relation') -%}
|
|
46
|
+
truncate table {{ relation.render() }}
|
|
47
|
+
{%- endcall %}
|
|
48
|
+
{% endmacro %}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
{% macro get_or_create_relation(database, schema, identifier, type) -%}
|
|
52
|
+
{{ return(adapter.dispatch('get_or_create_relation', 'dbt')(database, schema, identifier, type)) }}
|
|
53
|
+
{% endmacro %}
|
|
54
|
+
|
|
55
|
+
{% macro default__get_or_create_relation(database, schema, identifier, type) %}
|
|
56
|
+
{%- set target_relation = adapter.get_relation(database=database, schema=schema, identifier=identifier) %}
|
|
57
|
+
|
|
58
|
+
{% if target_relation %}
|
|
59
|
+
{% do return([true, target_relation]) %}
|
|
60
|
+
{% endif %}
|
|
61
|
+
|
|
62
|
+
{%- set new_relation = api.Relation.create(
|
|
63
|
+
database=database,
|
|
64
|
+
schema=schema,
|
|
65
|
+
identifier=identifier,
|
|
66
|
+
type=type
|
|
67
|
+
) -%}
|
|
68
|
+
{% do return([false, new_relation]) %}
|
|
69
|
+
{% endmacro %}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
-- a user-friendly interface into adapter.get_relation
|
|
73
|
+
{% macro load_cached_relation(relation) %}
|
|
74
|
+
{% do return(adapter.get_relation(
|
|
75
|
+
database=relation.database,
|
|
76
|
+
schema=relation.schema,
|
|
77
|
+
identifier=relation.identifier
|
|
78
|
+
)) -%}
|
|
79
|
+
{% endmacro %}
|
|
80
|
+
|
|
81
|
+
-- old name for backwards compatibility
|
|
82
|
+
{% macro load_relation(relation) %}
|
|
83
|
+
{{ return(load_cached_relation(relation)) }}
|
|
84
|
+
{% endmacro %}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{% macro create_schema(relation) -%}
|
|
2
|
+
{{ adapter.dispatch('create_schema', 'dbt')(relation) }}
|
|
3
|
+
{% endmacro %}
|
|
4
|
+
|
|
5
|
+
{% macro default__create_schema(relation) -%}
|
|
6
|
+
{%- call statement('create_schema') -%}
|
|
7
|
+
create schema if not exists {{ relation.without_identifier() }}
|
|
8
|
+
{% endcall %}
|
|
9
|
+
{% endmacro %}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
{% macro drop_schema(relation) -%}
|
|
13
|
+
{{ adapter.dispatch('drop_schema', 'dbt')(relation) }}
|
|
14
|
+
{% endmacro %}
|
|
15
|
+
|
|
16
|
+
{% macro default__drop_schema(relation) -%}
|
|
17
|
+
{%- call statement('drop_schema') -%}
|
|
18
|
+
drop schema if exists {{ relation.without_identifier() }} cascade
|
|
19
|
+
{% endcall %}
|
|
20
|
+
{% endmacro %}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{#
|
|
2
|
+
We expect a syntax error if dbt show is invoked both with a --limit flag to show
|
|
3
|
+
and with a limit predicate embedded in its inline query. No special handling is
|
|
4
|
+
provided out-of-box.
|
|
5
|
+
#}
|
|
6
|
+
{% macro get_show_sql(compiled_code, sql_header, limit) -%}
|
|
7
|
+
{%- if sql_header is not none -%}
|
|
8
|
+
{{ sql_header }}
|
|
9
|
+
{%- endif %}
|
|
10
|
+
{{ get_limit_subquery_sql(compiled_code, limit) }}
|
|
11
|
+
{% endmacro %}
|
|
12
|
+
|
|
13
|
+
{#
|
|
14
|
+
Not necessarily a true subquery anymore. Now, merely a query subordinate
|
|
15
|
+
to the calling macro.
|
|
16
|
+
#}
|
|
17
|
+
{%- macro get_limit_subquery_sql(sql, limit) -%}
|
|
18
|
+
{{ adapter.dispatch('get_limit_sql', 'dbt')(sql, limit) }}
|
|
19
|
+
{%- endmacro -%}
|
|
20
|
+
|
|
21
|
+
{% macro default__get_limit_sql(sql, limit) %}
|
|
22
|
+
{{ sql }}
|
|
23
|
+
{% if limit is not none %}
|
|
24
|
+
limit {{ limit }}
|
|
25
|
+
{%- endif -%}
|
|
26
|
+
{% endmacro %}
|