dbt-adapters 0.1.0a1__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.

Potentially problematic release.


This version of dbt-adapters might be problematic. Click here for more details.

Files changed (147) hide show
  1. dbt/__init__.py +0 -0
  2. dbt/adapters/__about__.py +1 -0
  3. dbt/adapters/__init__.py +7 -0
  4. dbt/adapters/base/README.md +13 -0
  5. dbt/adapters/base/__init__.py +15 -0
  6. dbt/adapters/base/column.py +166 -0
  7. dbt/adapters/base/connections.py +426 -0
  8. dbt/adapters/base/impl.py +1654 -0
  9. dbt/adapters/base/meta.py +131 -0
  10. dbt/adapters/base/plugin.py +32 -0
  11. dbt/adapters/base/query_headers.py +101 -0
  12. dbt/adapters/base/relation.py +471 -0
  13. dbt/adapters/cache.py +521 -0
  14. dbt/adapters/capability.py +52 -0
  15. dbt/adapters/clients/__init__.py +0 -0
  16. dbt/adapters/clients/jinja.py +24 -0
  17. dbt/adapters/contracts/__init__.py +0 -0
  18. dbt/adapters/contracts/connection.py +228 -0
  19. dbt/adapters/contracts/macros.py +11 -0
  20. dbt/adapters/contracts/relation.py +125 -0
  21. dbt/adapters/events/README.md +57 -0
  22. dbt/adapters/events/__init__.py +0 -0
  23. dbt/adapters/events/adapter_types.proto +517 -0
  24. dbt/adapters/events/adapter_types_pb2.py +208 -0
  25. dbt/adapters/events/base_types.py +40 -0
  26. dbt/adapters/events/logging.py +83 -0
  27. dbt/adapters/events/types.py +423 -0
  28. dbt/adapters/exceptions/__init__.py +40 -0
  29. dbt/adapters/exceptions/alias.py +24 -0
  30. dbt/adapters/exceptions/cache.py +68 -0
  31. dbt/adapters/exceptions/compilation.py +255 -0
  32. dbt/adapters/exceptions/connection.py +16 -0
  33. dbt/adapters/exceptions/database.py +51 -0
  34. dbt/adapters/factory.py +246 -0
  35. dbt/adapters/protocol.py +173 -0
  36. dbt/adapters/reference_keys.py +39 -0
  37. dbt/adapters/relation_configs/README.md +25 -0
  38. dbt/adapters/relation_configs/__init__.py +12 -0
  39. dbt/adapters/relation_configs/config_base.py +44 -0
  40. dbt/adapters/relation_configs/config_change.py +24 -0
  41. dbt/adapters/relation_configs/config_validation.py +57 -0
  42. dbt/adapters/sql/__init__.py +2 -0
  43. dbt/adapters/sql/connections.py +195 -0
  44. dbt/adapters/sql/impl.py +273 -0
  45. dbt/adapters/utils.py +69 -0
  46. dbt/include/global_project/__init__.py +4 -0
  47. dbt/include/global_project/dbt_project.yml +7 -0
  48. dbt/include/global_project/docs/overview.md +43 -0
  49. dbt/include/global_project/macros/adapters/apply_grants.sql +167 -0
  50. dbt/include/global_project/macros/adapters/columns.sql +137 -0
  51. dbt/include/global_project/macros/adapters/freshness.sql +16 -0
  52. dbt/include/global_project/macros/adapters/indexes.sql +41 -0
  53. dbt/include/global_project/macros/adapters/metadata.sql +96 -0
  54. dbt/include/global_project/macros/adapters/persist_docs.sql +33 -0
  55. dbt/include/global_project/macros/adapters/relation.sql +79 -0
  56. dbt/include/global_project/macros/adapters/schema.sql +20 -0
  57. dbt/include/global_project/macros/adapters/show.sql +22 -0
  58. dbt/include/global_project/macros/adapters/timestamps.sql +44 -0
  59. dbt/include/global_project/macros/adapters/validate_sql.sql +10 -0
  60. dbt/include/global_project/macros/etc/datetime.sql +62 -0
  61. dbt/include/global_project/macros/etc/statement.sql +52 -0
  62. dbt/include/global_project/macros/generic_test_sql/accepted_values.sql +27 -0
  63. dbt/include/global_project/macros/generic_test_sql/not_null.sql +9 -0
  64. dbt/include/global_project/macros/generic_test_sql/relationships.sql +23 -0
  65. dbt/include/global_project/macros/generic_test_sql/unique.sql +12 -0
  66. dbt/include/global_project/macros/get_custom_name/get_custom_alias.sql +36 -0
  67. dbt/include/global_project/macros/get_custom_name/get_custom_database.sql +32 -0
  68. dbt/include/global_project/macros/get_custom_name/get_custom_schema.sql +60 -0
  69. dbt/include/global_project/macros/materializations/configs.sql +21 -0
  70. dbt/include/global_project/macros/materializations/hooks.sql +35 -0
  71. dbt/include/global_project/macros/materializations/models/clone/can_clone_table.sql +7 -0
  72. dbt/include/global_project/macros/materializations/models/clone/clone.sql +67 -0
  73. dbt/include/global_project/macros/materializations/models/clone/create_or_replace_clone.sql +7 -0
  74. dbt/include/global_project/macros/materializations/models/incremental/column_helpers.sql +80 -0
  75. dbt/include/global_project/macros/materializations/models/incremental/incremental.sql +92 -0
  76. dbt/include/global_project/macros/materializations/models/incremental/is_incremental.sql +13 -0
  77. dbt/include/global_project/macros/materializations/models/incremental/merge.sql +131 -0
  78. dbt/include/global_project/macros/materializations/models/incremental/on_schema_change.sql +144 -0
  79. dbt/include/global_project/macros/materializations/models/incremental/strategies.sql +79 -0
  80. dbt/include/global_project/macros/materializations/models/materialized_view.sql +121 -0
  81. dbt/include/global_project/macros/materializations/models/table.sql +64 -0
  82. dbt/include/global_project/macros/materializations/models/view.sql +72 -0
  83. dbt/include/global_project/macros/materializations/seeds/helpers.sql +128 -0
  84. dbt/include/global_project/macros/materializations/seeds/seed.sql +60 -0
  85. dbt/include/global_project/macros/materializations/snapshots/helpers.sql +181 -0
  86. dbt/include/global_project/macros/materializations/snapshots/snapshot.sql +99 -0
  87. dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql +25 -0
  88. dbt/include/global_project/macros/materializations/snapshots/strategies.sql +174 -0
  89. dbt/include/global_project/macros/materializations/tests/helpers.sql +14 -0
  90. dbt/include/global_project/macros/materializations/tests/test.sql +60 -0
  91. dbt/include/global_project/macros/materializations/tests/where_subquery.sql +15 -0
  92. dbt/include/global_project/macros/python_model/python.sql +103 -0
  93. dbt/include/global_project/macros/relations/column/columns_spec_ddl.sql +89 -0
  94. dbt/include/global_project/macros/relations/create.sql +23 -0
  95. dbt/include/global_project/macros/relations/create_backup.sql +17 -0
  96. dbt/include/global_project/macros/relations/create_intermediate.sql +17 -0
  97. dbt/include/global_project/macros/relations/drop.sql +41 -0
  98. dbt/include/global_project/macros/relations/drop_backup.sql +14 -0
  99. dbt/include/global_project/macros/relations/materialized_view/alter.sql +55 -0
  100. dbt/include/global_project/macros/relations/materialized_view/create.sql +10 -0
  101. dbt/include/global_project/macros/relations/materialized_view/drop.sql +14 -0
  102. dbt/include/global_project/macros/relations/materialized_view/refresh.sql +9 -0
  103. dbt/include/global_project/macros/relations/materialized_view/rename.sql +10 -0
  104. dbt/include/global_project/macros/relations/materialized_view/replace.sql +10 -0
  105. dbt/include/global_project/macros/relations/rename.sql +35 -0
  106. dbt/include/global_project/macros/relations/rename_intermediate.sql +14 -0
  107. dbt/include/global_project/macros/relations/replace.sql +50 -0
  108. dbt/include/global_project/macros/relations/schema.sql +8 -0
  109. dbt/include/global_project/macros/relations/table/create.sql +60 -0
  110. dbt/include/global_project/macros/relations/table/drop.sql +14 -0
  111. dbt/include/global_project/macros/relations/table/rename.sql +10 -0
  112. dbt/include/global_project/macros/relations/table/replace.sql +10 -0
  113. dbt/include/global_project/macros/relations/view/create.sql +27 -0
  114. dbt/include/global_project/macros/relations/view/drop.sql +14 -0
  115. dbt/include/global_project/macros/relations/view/rename.sql +10 -0
  116. dbt/include/global_project/macros/relations/view/replace.sql +66 -0
  117. dbt/include/global_project/macros/utils/any_value.sql +9 -0
  118. dbt/include/global_project/macros/utils/array_append.sql +8 -0
  119. dbt/include/global_project/macros/utils/array_concat.sql +7 -0
  120. dbt/include/global_project/macros/utils/array_construct.sql +12 -0
  121. dbt/include/global_project/macros/utils/bool_or.sql +9 -0
  122. dbt/include/global_project/macros/utils/cast_bool_to_text.sql +7 -0
  123. dbt/include/global_project/macros/utils/concat.sql +7 -0
  124. dbt/include/global_project/macros/utils/data_types.sql +129 -0
  125. dbt/include/global_project/macros/utils/date_spine.sql +75 -0
  126. dbt/include/global_project/macros/utils/date_trunc.sql +7 -0
  127. dbt/include/global_project/macros/utils/dateadd.sql +14 -0
  128. dbt/include/global_project/macros/utils/datediff.sql +14 -0
  129. dbt/include/global_project/macros/utils/escape_single_quotes.sql +8 -0
  130. dbt/include/global_project/macros/utils/except.sql +9 -0
  131. dbt/include/global_project/macros/utils/generate_series.sql +53 -0
  132. dbt/include/global_project/macros/utils/hash.sql +7 -0
  133. dbt/include/global_project/macros/utils/intersect.sql +9 -0
  134. dbt/include/global_project/macros/utils/last_day.sql +15 -0
  135. dbt/include/global_project/macros/utils/length.sql +11 -0
  136. dbt/include/global_project/macros/utils/listagg.sql +30 -0
  137. dbt/include/global_project/macros/utils/literal.sql +7 -0
  138. dbt/include/global_project/macros/utils/position.sql +11 -0
  139. dbt/include/global_project/macros/utils/replace.sql +14 -0
  140. dbt/include/global_project/macros/utils/right.sql +12 -0
  141. dbt/include/global_project/macros/utils/safe_cast.sql +9 -0
  142. dbt/include/global_project/macros/utils/split_part.sql +26 -0
  143. dbt/include/global_project/tests/generic/builtin.sql +30 -0
  144. dbt_adapters-0.1.0a1.dist-info/METADATA +81 -0
  145. dbt_adapters-0.1.0a1.dist-info/RECORD +147 -0
  146. dbt_adapters-0.1.0a1.dist-info/WHEEL +4 -0
  147. dbt_adapters-0.1.0a1.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,8 @@
1
+ {% macro array_append(array, new_element) -%}
2
+ {{ return(adapter.dispatch('array_append', 'dbt')(array, new_element)) }}
3
+ {%- endmacro %}
4
+
5
+ {# new_element must be the same data type as elements in array to match postgres functionality #}
6
+ {% macro default__array_append(array, new_element) -%}
7
+ array_append({{ array }}, {{ new_element }})
8
+ {%- endmacro %}
@@ -0,0 +1,7 @@
1
+ {% macro array_concat(array_1, array_2) -%}
2
+ {{ return(adapter.dispatch('array_concat', 'dbt')(array_1, array_2)) }}
3
+ {%- endmacro %}
4
+
5
+ {% macro default__array_concat(array_1, array_2) -%}
6
+ array_cat({{ array_1 }}, {{ array_2 }})
7
+ {%- endmacro %}
@@ -0,0 +1,12 @@
1
+ {% macro array_construct(inputs=[], data_type=api.Column.translate_type('integer')) -%}
2
+ {{ return(adapter.dispatch('array_construct', 'dbt')(inputs, data_type)) }}
3
+ {%- endmacro %}
4
+
5
+ {# all inputs must be the same data type to match postgres functionality #}
6
+ {% macro default__array_construct(inputs, data_type) -%}
7
+ {% if inputs|length > 0 %}
8
+ array[ {{ inputs|join(' , ') }} ]
9
+ {% else %}
10
+ array[]::{{data_type}}[]
11
+ {% endif %}
12
+ {%- endmacro %}
@@ -0,0 +1,9 @@
1
+ {% macro bool_or(expression) -%}
2
+ {{ return(adapter.dispatch('bool_or', 'dbt') (expression)) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__bool_or(expression) -%}
6
+
7
+ bool_or({{ expression }})
8
+
9
+ {%- endmacro %}
@@ -0,0 +1,7 @@
1
+ {% macro cast_bool_to_text(field) %}
2
+ {{ adapter.dispatch('cast_bool_to_text', 'dbt') (field) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__cast_bool_to_text(field) %}
6
+ cast({{ field }} as {{ api.Column.translate_type('string') }})
7
+ {% endmacro %}
@@ -0,0 +1,7 @@
1
+ {% macro concat(fields) -%}
2
+ {{ return(adapter.dispatch('concat', 'dbt')(fields)) }}
3
+ {%- endmacro %}
4
+
5
+ {% macro default__concat(fields) -%}
6
+ {{ fields|join(' || ') }}
7
+ {%- endmacro %}
@@ -0,0 +1,129 @@
1
+ {# string ------------------------------------------------- #}
2
+
3
+ {%- macro type_string() -%}
4
+ {{ return(adapter.dispatch('type_string', 'dbt')()) }}
5
+ {%- endmacro -%}
6
+
7
+ {% macro default__type_string() %}
8
+ {{ return(api.Column.translate_type("string")) }}
9
+ {% endmacro %}
10
+
11
+ -- This will return 'text' by default
12
+ -- On Postgres + Snowflake, that's equivalent to varchar (no size)
13
+ -- Redshift will treat that as varchar(256)
14
+
15
+
16
+ {# timestamp ------------------------------------------------- #}
17
+
18
+ {%- macro type_timestamp() -%}
19
+ {{ return(adapter.dispatch('type_timestamp', 'dbt')()) }}
20
+ {%- endmacro -%}
21
+
22
+ {% macro default__type_timestamp() %}
23
+ {{ return(api.Column.translate_type("timestamp")) }}
24
+ {% endmacro %}
25
+
26
+ /*
27
+ POSTGRES
28
+ https://www.postgresql.org/docs/current/datatype-datetime.html:
29
+ The SQL standard requires that writing just `timestamp`
30
+ be equivalent to `timestamp without time zone`, and
31
+ PostgreSQL honors that behavior.
32
+ `timestamptz` is accepted as an abbreviation for `timestamp with time zone`;
33
+ this is a PostgreSQL extension.
34
+
35
+ SNOWFLAKE
36
+ https://docs.snowflake.com/en/sql-reference/data-types-datetime.html#timestamp
37
+ The TIMESTAMP_* variation associated with TIMESTAMP is specified by the
38
+ TIMESTAMP_TYPE_MAPPING session parameter. The default is TIMESTAMP_NTZ.
39
+
40
+ BIGQUERY
41
+ TIMESTAMP means 'timestamp with time zone'
42
+ DATETIME means 'timestamp without time zone'
43
+ TODO: shouldn't this return DATETIME instead of TIMESTAMP, for consistency with other databases?
44
+ e.g. dateadd returns a DATETIME
45
+
46
+ /* Snowflake:
47
+ https://docs.snowflake.com/en/sql-reference/data-types-datetime.html#timestamp
48
+ The TIMESTAMP_* variation associated with TIMESTAMP is specified by the TIMESTAMP_TYPE_MAPPING session parameter. The default is TIMESTAMP_NTZ.
49
+ */
50
+
51
+
52
+ {# float ------------------------------------------------- #}
53
+
54
+ {%- macro type_float() -%}
55
+ {{ return(adapter.dispatch('type_float', 'dbt')()) }}
56
+ {%- endmacro -%}
57
+
58
+ {% macro default__type_float() %}
59
+ {{ return(api.Column.translate_type("float")) }}
60
+ {% endmacro %}
61
+
62
+ {# numeric ------------------------------------------------- #}
63
+
64
+ {%- macro type_numeric() -%}
65
+ {{ return(adapter.dispatch('type_numeric', 'dbt')()) }}
66
+ {%- endmacro -%}
67
+
68
+ /*
69
+ This one can't be just translate_type, since precision/scale make it a bit more complicated.
70
+
71
+ On most databases, the default (precision, scale) is something like:
72
+ Redshift: (18, 0)
73
+ Snowflake: (38, 0)
74
+ Postgres: (<=131072, 0)
75
+
76
+ https://www.postgresql.org/docs/current/datatype-numeric.html:
77
+ Specifying NUMERIC without any precision or scale creates an “unconstrained numeric”
78
+ column in which numeric values of any length can be stored, up to the implementation limits.
79
+ A column of this kind will not coerce input values to any particular scale,
80
+ whereas numeric columns with a declared scale will coerce input values to that scale.
81
+ (The SQL standard requires a default scale of 0, i.e., coercion to integer precision.
82
+ We find this a bit useless. If you're concerned about portability, always specify
83
+ the precision and scale explicitly.)
84
+ */
85
+
86
+ {% macro default__type_numeric() %}
87
+ {{ return(api.Column.numeric_type("numeric", 28, 6)) }}
88
+ {% endmacro %}
89
+
90
+
91
+ {# bigint ------------------------------------------------- #}
92
+
93
+ {%- macro type_bigint() -%}
94
+ {{ return(adapter.dispatch('type_bigint', 'dbt')()) }}
95
+ {%- endmacro -%}
96
+
97
+ -- We don't have a conversion type for 'bigint' in TYPE_LABELS,
98
+ -- so this actually just returns the string 'bigint'
99
+
100
+ {% macro default__type_bigint() %}
101
+ {{ return(api.Column.translate_type("bigint")) }}
102
+ {% endmacro %}
103
+
104
+ -- Good news: BigQuery now supports 'bigint' (and 'int') as an alias for 'int64'
105
+
106
+ {# int ------------------------------------------------- #}
107
+
108
+ {%- macro type_int() -%}
109
+ {{ return(adapter.dispatch('type_int', 'dbt')()) }}
110
+ {%- endmacro -%}
111
+
112
+ {%- macro default__type_int() -%}
113
+ {{ return(api.Column.translate_type("integer")) }}
114
+ {%- endmacro -%}
115
+
116
+ -- returns 'int' everywhere, except BigQuery, where it returns 'int64'
117
+ -- (but BigQuery also now accepts 'int' as a valid alias for 'int64')
118
+
119
+ {# bool ------------------------------------------------- #}
120
+
121
+ {%- macro type_boolean() -%}
122
+ {{ return(adapter.dispatch('type_boolean', 'dbt')()) }}
123
+ {%- endmacro -%}
124
+
125
+ {%- macro default__type_boolean() -%}
126
+ {{ return(api.Column.translate_type("boolean")) }}
127
+ {%- endmacro -%}
128
+
129
+ -- returns 'boolean' everywhere. BigQuery accepts 'boolean' as a valid alias for 'bool'
@@ -0,0 +1,75 @@
1
+ {% macro get_intervals_between(start_date, end_date, datepart) -%}
2
+ {{ return(adapter.dispatch('get_intervals_between', 'dbt')(start_date, end_date, datepart)) }}
3
+ {%- endmacro %}
4
+
5
+ {% macro default__get_intervals_between(start_date, end_date, datepart) -%}
6
+ {%- call statement('get_intervals_between', fetch_result=True) %}
7
+
8
+ select {{ dbt.datediff(start_date, end_date, datepart) }}
9
+
10
+ {%- endcall -%}
11
+
12
+ {%- set value_list = load_result('get_intervals_between') -%}
13
+
14
+ {%- if value_list and value_list['data'] -%}
15
+ {%- set values = value_list['data'] | map(attribute=0) | list %}
16
+ {{ return(values[0]) }}
17
+ {%- else -%}
18
+ {{ return(1) }}
19
+ {%- endif -%}
20
+
21
+ {%- endmacro %}
22
+
23
+
24
+
25
+
26
+ {% macro date_spine(datepart, start_date, end_date) %}
27
+ {{ return(adapter.dispatch('date_spine', 'dbt')(datepart, start_date, end_date)) }}
28
+ {%- endmacro %}
29
+
30
+ {% macro default__date_spine(datepart, start_date, end_date) %}
31
+
32
+
33
+ {# call as follows:
34
+
35
+ date_spine(
36
+ "day",
37
+ "to_date('01/01/2016', 'mm/dd/yyyy')",
38
+ "dbt.dateadd(week, 1, current_date)"
39
+ ) #}
40
+
41
+
42
+ with rawdata as (
43
+
44
+ {{dbt.generate_series(
45
+ dbt.get_intervals_between(start_date, end_date, datepart)
46
+ )}}
47
+
48
+ ),
49
+
50
+ all_periods as (
51
+
52
+ select (
53
+ {{
54
+ dbt.dateadd(
55
+ datepart,
56
+ "row_number() over (order by 1) - 1",
57
+ start_date
58
+ )
59
+ }}
60
+ ) as date_{{datepart}}
61
+ from rawdata
62
+
63
+ ),
64
+
65
+ filtered as (
66
+
67
+ select *
68
+ from all_periods
69
+ where date_{{datepart}} <= {{ end_date }}
70
+
71
+ )
72
+
73
+ select * from filtered
74
+
75
+ {% endmacro %}
@@ -0,0 +1,7 @@
1
+ {% macro date_trunc(datepart, date) -%}
2
+ {{ return(adapter.dispatch('date_trunc', 'dbt') (datepart, date)) }}
3
+ {%- endmacro %}
4
+
5
+ {% macro default__date_trunc(datepart, date) -%}
6
+ date_trunc('{{datepart}}', {{date}})
7
+ {%- endmacro %}
@@ -0,0 +1,14 @@
1
+ {% macro dateadd(datepart, interval, from_date_or_timestamp) %}
2
+ {{ return(adapter.dispatch('dateadd', 'dbt')(datepart, interval, from_date_or_timestamp)) }}
3
+ {% endmacro %}
4
+
5
+
6
+ {% macro default__dateadd(datepart, interval, from_date_or_timestamp) %}
7
+
8
+ dateadd(
9
+ {{ datepart }},
10
+ {{ interval }},
11
+ {{ from_date_or_timestamp }}
12
+ )
13
+
14
+ {% endmacro %}
@@ -0,0 +1,14 @@
1
+ {% macro datediff(first_date, second_date, datepart) %}
2
+ {{ return(adapter.dispatch('datediff', 'dbt')(first_date, second_date, datepart)) }}
3
+ {% endmacro %}
4
+
5
+
6
+ {% macro default__datediff(first_date, second_date, datepart) -%}
7
+
8
+ datediff(
9
+ {{ datepart }},
10
+ {{ first_date }},
11
+ {{ second_date }}
12
+ )
13
+
14
+ {%- endmacro %}
@@ -0,0 +1,8 @@
1
+ {% macro escape_single_quotes(expression) %}
2
+ {{ return(adapter.dispatch('escape_single_quotes', 'dbt') (expression)) }}
3
+ {% endmacro %}
4
+
5
+ {# /*Default to replacing a single apostrophe with two apostrophes: they're -> they''re*/ #}
6
+ {% macro default__escape_single_quotes(expression) -%}
7
+ {{ expression | replace("'","''") }}
8
+ {%- endmacro %}
@@ -0,0 +1,9 @@
1
+ {% macro except() %}
2
+ {{ return(adapter.dispatch('except', 'dbt')()) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__except() %}
6
+
7
+ except
8
+
9
+ {% endmacro %}
@@ -0,0 +1,53 @@
1
+ {% macro get_powers_of_two(upper_bound) %}
2
+ {{ return(adapter.dispatch('get_powers_of_two', 'dbt')(upper_bound)) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__get_powers_of_two(upper_bound) %}
6
+
7
+ {% if upper_bound <= 0 %}
8
+ {{ exceptions.raise_compiler_error("upper bound must be positive") }}
9
+ {% endif %}
10
+
11
+ {% for _ in range(1, 100) %}
12
+ {% if upper_bound <= 2 ** loop.index %}{{ return(loop.index) }}{% endif %}
13
+ {% endfor %}
14
+
15
+ {% endmacro %}
16
+
17
+
18
+ {% macro generate_series(upper_bound) %}
19
+ {{ return(adapter.dispatch('generate_series', 'dbt')(upper_bound)) }}
20
+ {% endmacro %}
21
+
22
+ {% macro default__generate_series(upper_bound) %}
23
+
24
+ {% set n = dbt.get_powers_of_two(upper_bound) %}
25
+
26
+ with p as (
27
+ select 0 as generated_number union all select 1
28
+ ), unioned as (
29
+
30
+ select
31
+
32
+ {% for i in range(n) %}
33
+ p{{i}}.generated_number * power(2, {{i}})
34
+ {% if not loop.last %} + {% endif %}
35
+ {% endfor %}
36
+ + 1
37
+ as generated_number
38
+
39
+ from
40
+
41
+ {% for i in range(n) %}
42
+ p as p{{i}}
43
+ {% if not loop.last %} cross join {% endif %}
44
+ {% endfor %}
45
+
46
+ )
47
+
48
+ select *
49
+ from unioned
50
+ where generated_number <= {{upper_bound}}
51
+ order by generated_number
52
+
53
+ {% endmacro %}
@@ -0,0 +1,7 @@
1
+ {% macro hash(field) -%}
2
+ {{ return(adapter.dispatch('hash', 'dbt') (field)) }}
3
+ {%- endmacro %}
4
+
5
+ {% macro default__hash(field) -%}
6
+ md5(cast({{ field }} as {{ api.Column.translate_type('string') }}))
7
+ {%- endmacro %}
@@ -0,0 +1,9 @@
1
+ {% macro intersect() %}
2
+ {{ return(adapter.dispatch('intersect', 'dbt')()) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__intersect() %}
6
+
7
+ intersect
8
+
9
+ {% endmacro %}
@@ -0,0 +1,15 @@
1
+ {% macro last_day(date, datepart) %}
2
+ {{ return(adapter.dispatch('last_day', 'dbt') (date, datepart)) }}
3
+ {% endmacro %}
4
+
5
+ {%- macro default_last_day(date, datepart) -%}
6
+ cast(
7
+ {{dbt.dateadd('day', '-1',
8
+ dbt.dateadd(datepart, '1', dbt.date_trunc(datepart, date))
9
+ )}}
10
+ as date)
11
+ {%- endmacro -%}
12
+
13
+ {% macro default__last_day(date, datepart) -%}
14
+ {{dbt.default_last_day(date, datepart)}}
15
+ {%- endmacro %}
@@ -0,0 +1,11 @@
1
+ {% macro length(expression) -%}
2
+ {{ return(adapter.dispatch('length', 'dbt') (expression)) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__length(expression) %}
6
+
7
+ length(
8
+ {{ expression }}
9
+ )
10
+
11
+ {%- endmacro -%}
@@ -0,0 +1,30 @@
1
+ {% macro listagg(measure, delimiter_text="','", order_by_clause=none, limit_num=none) -%}
2
+ {{ return(adapter.dispatch('listagg', 'dbt') (measure, delimiter_text, order_by_clause, limit_num)) }}
3
+ {%- endmacro %}
4
+
5
+ {% macro default__listagg(measure, delimiter_text, order_by_clause, limit_num) -%}
6
+
7
+ {% if limit_num -%}
8
+ array_to_string(
9
+ array_slice(
10
+ array_agg(
11
+ {{ measure }}
12
+ ){% if order_by_clause -%}
13
+ within group ({{ order_by_clause }})
14
+ {%- endif %}
15
+ ,0
16
+ ,{{ limit_num }}
17
+ ),
18
+ {{ delimiter_text }}
19
+ )
20
+ {%- else %}
21
+ listagg(
22
+ {{ measure }},
23
+ {{ delimiter_text }}
24
+ )
25
+ {% if order_by_clause -%}
26
+ within group ({{ order_by_clause }})
27
+ {%- endif %}
28
+ {%- endif %}
29
+
30
+ {%- endmacro %}
@@ -0,0 +1,7 @@
1
+ {%- macro string_literal(value) -%}
2
+ {{ return(adapter.dispatch('string_literal', 'dbt') (value)) }}
3
+ {%- endmacro -%}
4
+
5
+ {% macro default__string_literal(value) -%}
6
+ '{{ value }}'
7
+ {%- endmacro %}
@@ -0,0 +1,11 @@
1
+ {% macro position(substring_text, string_text) -%}
2
+ {{ return(adapter.dispatch('position', 'dbt') (substring_text, string_text)) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__position(substring_text, string_text) %}
6
+
7
+ position(
8
+ {{ substring_text }} in {{ string_text }}
9
+ )
10
+
11
+ {%- endmacro -%}
@@ -0,0 +1,14 @@
1
+ {% macro replace(field, old_chars, new_chars) -%}
2
+ {{ return(adapter.dispatch('replace', 'dbt') (field, old_chars, new_chars)) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__replace(field, old_chars, new_chars) %}
6
+
7
+ replace(
8
+ {{ field }},
9
+ {{ old_chars }},
10
+ {{ new_chars }}
11
+ )
12
+
13
+
14
+ {% endmacro %}
@@ -0,0 +1,12 @@
1
+ {% macro right(string_text, length_expression) -%}
2
+ {{ return(adapter.dispatch('right', 'dbt') (string_text, length_expression)) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__right(string_text, length_expression) %}
6
+
7
+ right(
8
+ {{ string_text }},
9
+ {{ length_expression }}
10
+ )
11
+
12
+ {%- endmacro -%}
@@ -0,0 +1,9 @@
1
+ {% macro safe_cast(field, type) %}
2
+ {{ return(adapter.dispatch('safe_cast', 'dbt') (field, type)) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__safe_cast(field, type) %}
6
+ {# most databases don't support this function yet
7
+ so we just need to use cast #}
8
+ cast({{field}} as {{type}})
9
+ {% endmacro %}
@@ -0,0 +1,26 @@
1
+ {% macro split_part(string_text, delimiter_text, part_number) %}
2
+ {{ return(adapter.dispatch('split_part', 'dbt') (string_text, delimiter_text, part_number)) }}
3
+ {% endmacro %}
4
+
5
+ {% macro default__split_part(string_text, delimiter_text, part_number) %}
6
+
7
+ split_part(
8
+ {{ string_text }},
9
+ {{ delimiter_text }},
10
+ {{ part_number }}
11
+ )
12
+
13
+ {% endmacro %}
14
+
15
+ {% macro _split_part_negative(string_text, delimiter_text, part_number) %}
16
+
17
+ split_part(
18
+ {{ string_text }},
19
+ {{ delimiter_text }},
20
+ length({{ string_text }})
21
+ - length(
22
+ replace({{ string_text }}, {{ delimiter_text }}, '')
23
+ ) + 2 + {{ part_number }}
24
+ )
25
+
26
+ {% endmacro %}
@@ -0,0 +1,30 @@
1
+ /* {#
2
+ Generic tests can be defined in `macros/` or in `tests/generic`.
3
+ These four tests are built into the dbt-core global project.
4
+ To support extensibility to other adapters and SQL dialects,
5
+ they call 'dispatched' macros. By default, they will use
6
+ the SQL defined in `global_project/macros/generic_test_sql`
7
+ #} */
8
+
9
+ {% test unique(model, column_name) %}
10
+ {% set macro = adapter.dispatch('test_unique', 'dbt') %}
11
+ {{ macro(model, column_name) }}
12
+ {% endtest %}
13
+
14
+
15
+ {% test not_null(model, column_name) %}
16
+ {% set macro = adapter.dispatch('test_not_null', 'dbt') %}
17
+ {{ macro(model, column_name) }}
18
+ {% endtest %}
19
+
20
+
21
+ {% test accepted_values(model, column_name, values, quote=True) %}
22
+ {% set macro = adapter.dispatch('test_accepted_values', 'dbt') %}
23
+ {{ macro(model, column_name, values, quote) }}
24
+ {% endtest %}
25
+
26
+
27
+ {% test relationships(model, column_name, to, field) %}
28
+ {% set macro = adapter.dispatch('test_relationships', 'dbt') %}
29
+ {{ macro(model, column_name, to, field) }}
30
+ {% endtest %}
@@ -0,0 +1,81 @@
1
+ Metadata-Version: 2.1
2
+ Name: dbt-adapters
3
+ Version: 0.1.0a1
4
+ Summary: The set of adapter protocols and base functionality that supports integration with dbt-core
5
+ Project-URL: Homepage, https://github.com/dbt-labs/dbt-adapters
6
+ Project-URL: Documentation, https://docs.getdbt.com
7
+ Project-URL: Repository, https://github.com/dbt-labs/dbt-adapters.git
8
+ Project-URL: Issues, https://github.com/dbt-labs/dbt-adapters/issues
9
+ Project-URL: Changelog, https://github.com/dbt-labs/dbt-adapters/blob/main/CHANGELOG.md
10
+ Author-email: dbt Labs <info@dbtlabs.com>
11
+ Maintainer-email: dbt Labs <info@dbtlabs.com>
12
+ License-File: LICENSE
13
+ Keywords: adapter,adapters,database,dbt,dbt Cloud,dbt Core,dbt Labs,dbt-core,elt
14
+ Classifier: Development Status :: 2 - Pre-Alpha
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Operating System :: MacOS :: MacOS X
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Requires-Python: >=3.8.0
24
+ Requires-Dist: agate<2.0
25
+ Requires-Dist: dbt-common<1.0
26
+ Requires-Dist: mashumaro[msgpack]<4.0
27
+ Requires-Dist: protobuf<5.0
28
+ Requires-Dist: pytz>=2015.7
29
+ Requires-Dist: typing-extensions<5.0
30
+ Provides-Extra: lint
31
+ Requires-Dist: black; extra == 'lint'
32
+ Requires-Dist: flake8; extra == 'lint'
33
+ Requires-Dist: flake8-pyproject; extra == 'lint'
34
+ Requires-Dist: mypy; extra == 'lint'
35
+ Requires-Dist: types-protobuf; extra == 'lint'
36
+ Requires-Dist: types-pytz; extra == 'lint'
37
+ Provides-Extra: test
38
+ Requires-Dist: pytest; extra == 'test'
39
+ Requires-Dist: pytest-dotenv; extra == 'test'
40
+ Requires-Dist: pytest-xdist; extra == 'test'
41
+ Description-Content-Type: text/markdown
42
+
43
+ # Adapter
44
+
45
+ This package is responsible for:
46
+
47
+ - defining database connection methods
48
+ - caching information from databases
49
+ - determining how relations are defined
50
+
51
+ There are two major adapter types: base and sql
52
+
53
+ # Directories
54
+
55
+ ## `base`
56
+
57
+ Defines the base implementation Adapters can use to build out full functionality.
58
+
59
+ ## `sql`
60
+
61
+ Defines a sql implementation for adapters that initially inherits the base implementation
62
+ and comes with some pre-made methods and macros that can be overwritten as needed per adapter.
63
+ (most common type of adapter.)
64
+
65
+ # Files
66
+
67
+ ## `cache.py`
68
+
69
+ Cached information from the database.
70
+
71
+ ## `factory.py`
72
+
73
+ Defines how we generate adapter objects
74
+
75
+ ## `protocol.py`
76
+
77
+ Defines various interfaces for various adapter objects. Helps mypy correctly resolve methods.
78
+
79
+ ## `reference_keys.py`
80
+
81
+ Configures naming scheme for cache elements to be universal.