dbt-firebolt 1.8.3__py3-none-any.whl → 1.9.1__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 (56) hide show
  1. dbt/adapters/firebolt/__init__.py +1 -1
  2. dbt/adapters/firebolt/connections.py +4 -2
  3. dbt/adapters/firebolt/impl.py +38 -8
  4. {dbt_firebolt-1.8.3.dist-info → dbt_firebolt-1.9.1.dist-info}/METADATA +3 -3
  5. dbt_firebolt-1.9.1.dist-info/RECORD +13 -0
  6. {dbt_firebolt-1.8.3.dist-info → dbt_firebolt-1.9.1.dist-info}/WHEEL +1 -1
  7. dbt/include/firebolt/dbt_project.yml +0 -6
  8. dbt/include/firebolt/macros/adapters/apply_grants.sql +0 -37
  9. dbt/include/firebolt/macros/adapters/relation.sql +0 -49
  10. dbt/include/firebolt/macros/adapters.sql +0 -197
  11. dbt/include/firebolt/macros/catalog.sql +0 -103
  12. dbt/include/firebolt/macros/dbt_external_tables/create_external_table.sql +0 -137
  13. dbt/include/firebolt/macros/dbt_external_tables/dropif.sql +0 -6
  14. dbt/include/firebolt/macros/dbt_external_tables/get_external_build_plan.sql +0 -18
  15. dbt/include/firebolt/macros/materializations/clone.sql +0 -3
  16. dbt/include/firebolt/macros/materializations/materialized_view.sql +0 -3
  17. dbt/include/firebolt/macros/materializations/models/incremental/column_helpers.sql +0 -21
  18. dbt/include/firebolt/macros/materializations/models/incremental/incremental.sql +0 -131
  19. dbt/include/firebolt/macros/materializations/models/incremental/is_incremental.sql +0 -14
  20. dbt/include/firebolt/macros/materializations/models/incremental/merge.sql +0 -38
  21. dbt/include/firebolt/macros/materializations/models/incremental/on_schema_change.sql +0 -90
  22. dbt/include/firebolt/macros/materializations/models/incremental/strategies.sql +0 -132
  23. dbt/include/firebolt/macros/materializations/seed.sql +0 -42
  24. dbt/include/firebolt/macros/materializations/table.sql +0 -40
  25. dbt/include/firebolt/macros/materializations/test.sql +0 -15
  26. dbt/include/firebolt/macros/materializations/view.sql +0 -39
  27. dbt/include/firebolt/macros/relations/materialized_view/alter.sql +0 -11
  28. dbt/include/firebolt/macros/relations/materialized_view/create.sql +0 -3
  29. dbt/include/firebolt/macros/relations/materialized_view/describe.sql +0 -3
  30. dbt/include/firebolt/macros/relations/materialized_view/drop.sql +0 -3
  31. dbt/include/firebolt/macros/relations/materialized_view/refresh.sql +0 -3
  32. dbt/include/firebolt/macros/relations/table/create.sql +0 -74
  33. dbt/include/firebolt/macros/relations/table/drop.sql +0 -3
  34. dbt/include/firebolt/macros/relations/table/rename.sql +0 -6
  35. dbt/include/firebolt/macros/relations/table/replace.sql +0 -3
  36. dbt/include/firebolt/macros/relations/view/create.sql +0 -16
  37. dbt/include/firebolt/macros/relations/view/drop.sql +0 -3
  38. dbt/include/firebolt/macros/relations/view/rename.sql +0 -6
  39. dbt/include/firebolt/macros/relations/view/replace.sql +0 -3
  40. dbt/include/firebolt/macros/utils/array_append.sql +0 -3
  41. dbt/include/firebolt/macros/utils/array_concat.sql +0 -3
  42. dbt/include/firebolt/macros/utils/array_construct.sql +0 -3
  43. dbt/include/firebolt/macros/utils/bool_or.sql +0 -5
  44. dbt/include/firebolt/macros/utils/cast_bool_to_text.sql +0 -7
  45. dbt/include/firebolt/macros/utils/dateadd.sql +0 -9
  46. dbt/include/firebolt/macros/utils/datediff.sql +0 -9
  47. dbt/include/firebolt/macros/utils/except.sql +0 -6
  48. dbt/include/firebolt/macros/utils/intersect.sql +0 -6
  49. dbt/include/firebolt/macros/utils/listagg.sql +0 -27
  50. dbt/include/firebolt/macros/utils/position.sql +0 -3
  51. dbt/include/firebolt/macros/utils/right.sql +0 -12
  52. dbt/include/firebolt/macros/utils/split_part.sql +0 -14
  53. dbt/include/firebolt/macros/utils/timestamps.sql +0 -14
  54. dbt_firebolt-1.8.3.dist-info/RECORD +0 -60
  55. {dbt_firebolt-1.8.3.dist-info → dbt_firebolt-1.9.1.dist-info}/LICENSE +0 -0
  56. {dbt_firebolt-1.8.3.dist-info → dbt_firebolt-1.9.1.dist-info}/top_level.txt +0 -0
@@ -7,7 +7,7 @@ from dbt.adapters.firebolt.connections import (
7
7
  from dbt.adapters.firebolt.impl import FireboltAdapter
8
8
  from dbt.include import firebolt
9
9
 
10
- __version__ = "1.8.3"
10
+ __version__ = "1.9.1"
11
11
 
12
12
  Plugin = AdapterPlugin(
13
13
  adapter=FireboltAdapter, # type: ignore
@@ -20,6 +20,7 @@ from dbt_common.exceptions import (
20
20
  )
21
21
  from firebolt.client import DEFAULT_API_URL
22
22
  from firebolt.client.auth import Auth, ClientCredentials, UsernamePassword
23
+ from firebolt.common._types import ExtendedType
23
24
  from firebolt.db import ARRAY, DECIMAL
24
25
  from firebolt.db import connect as sdk_connect
25
26
  from firebolt.db.connection import Connection as SDKConnection
@@ -191,8 +192,8 @@ class FireboltConnectionManager(SQLConnectionManager):
191
192
  raise NotImplementedError('`cancel` is not implemented for this adapter!')
192
193
 
193
194
  @classmethod
194
- def data_type_code_to_name( # type: ignore[override] # FIR-29423
195
- cls, type_code: Union[type, ARRAY, DECIMAL]
195
+ def data_type_code_to_name(
196
+ cls, type_code: Union[type, ExtendedType] # type: ignore[override] # FIR-29423
196
197
  ) -> str:
197
198
  """
198
199
  Convert a Firebolt data type code to a string representing the data type.
@@ -218,6 +219,7 @@ class FireboltConnectionManager(SQLConnectionManager):
218
219
  return 'bytea'
219
220
  else:
220
221
  return 'text'
222
+ return 'text'
221
223
 
222
224
 
223
225
  def _determine_auth(credentials: FireboltCredentials) -> Auth:
@@ -1,7 +1,6 @@
1
1
  import re
2
2
  import time
3
3
  from dataclasses import dataclass
4
- from datetime import datetime
5
4
  from typing import Any, List, Mapping, Optional, Union
6
5
 
7
6
  import agate
@@ -29,21 +28,45 @@ from dbt.adapters.firebolt.connections import FireboltConnectionManager
29
28
  from dbt.adapters.firebolt.relation import FireboltRelation
30
29
 
31
30
 
31
+ def quote_columns(columns: Union[str, List[str]]) -> Union[str, List[str]]:
32
+ if isinstance(columns, str):
33
+ return f'"{columns}"'
34
+ quoted_columns = []
35
+ for col in columns:
36
+ if col.startswith('"') and col.endswith('"'):
37
+ quoted_columns.append(col)
38
+ else:
39
+ quoted_columns.append(f'"{col}"')
40
+ return quoted_columns
41
+
42
+
32
43
  @dataclass
33
44
  class FireboltIndexConfig(dbtClassMixin):
34
45
  index_type: str
46
+ index_name: Optional[str] = None
35
47
  join_columns: Optional[Union[str, List[str]]] = None
36
48
  key_columns: Optional[Union[str, List[str]]] = None
37
49
  dimension_column: Optional[Union[str, List[str]]] = None
38
50
  aggregation: Optional[Union[str, List[str]]] = None
39
51
 
52
+ def __post_init__(self) -> None:
53
+ # quote unquoted columns
54
+ if self.join_columns:
55
+ self.join_columns = quote_columns(self.join_columns)
56
+ if self.key_columns:
57
+ self.key_columns = quote_columns(self.key_columns)
58
+ if self.dimension_column:
59
+ self.dimension_column = quote_columns(self.dimension_column)
60
+
40
61
  def render_name(self, relation: FireboltRelation) -> str:
41
62
  """
42
63
  Name an index according to the following format, joined by `_`:
43
64
  index type, relation name, key/join columns, timestamp (unix & UTC)
44
65
  example index name: join_my_model_customer_id_1633504263.
45
66
  """
46
- now_unix = str(int(time.mktime(datetime.utcnow().timetuple())))
67
+ if self.index_name:
68
+ return self.index_name
69
+ now_unix = str(int(time.time()))
47
70
  # If column_names is a list with > 1 members, join with _,
48
71
  # otherwise do not. We were getting index names like
49
72
  # join__idx__emf_customers__f_i_r_s_t___n_a_m_e__165093112.
@@ -51,14 +74,23 @@ class FireboltIndexConfig(dbtClassMixin):
51
74
  spine_col = (
52
75
  '_'.join(column_names) if isinstance(column_names, list) else column_names
53
76
  )
77
+ # Additional hash to ensure uniqueness after spaces are removed
78
+ column_hash = str(hash(spine_col))[:5]
54
79
  inputs = [
55
80
  f'{self.index_type}_idx',
56
81
  relation.identifier,
57
82
  spine_col,
83
+ column_hash,
58
84
  now_unix,
59
85
  ]
60
- string = '__'.join([x for x in inputs if x is not None])
61
- return string
86
+ index_name = '__'.join([x for x in inputs if x is not None])
87
+ if len(index_name) > 255:
88
+ # Firebolt index names must be <= 255 characters.
89
+ # If the index name is too long, hash it.
90
+ return f'{self.index_type}_idx_{hash(index_name)}'
91
+ # Remove any spaces or quotes from the index name.
92
+ index_name = index_name.replace(' ', '_').replace('"', '')
93
+ return index_name
62
94
 
63
95
  @classmethod
64
96
  def parse(cls, raw_index: Optional[Mapping]) -> Optional['FireboltIndexConfig']:
@@ -88,13 +120,12 @@ class FireboltIndexConfig(dbtClassMixin):
88
120
  'for join indexes.'
89
121
  )
90
122
  if index_config.index_type.upper() == 'AGGREGATING' and not (
91
- index_config.key_columns and index_config.aggregation
123
+ index_config.aggregation
92
124
  ):
93
125
  raise CompilationError(
94
126
  'Invalid aggregating index definition:\n'
95
127
  f' Got: {index_config}.\n'
96
- ' key_columns and aggregation must be specified '
97
- 'for aggregating indexes.'
128
+ ' aggregation must be specified for aggregating indexes.'
98
129
  )
99
130
  return index_config
100
131
  except ValidationError as exc:
@@ -274,7 +305,6 @@ class FireboltAdapter(SQLAdapter):
274
305
  columns: the number of rows that are different between the two
275
306
  relations and the number of mismatched rows.
276
307
  """
277
- # This method only really exists for test reasons.
278
308
  names: List[str]
279
309
  if column_names is None:
280
310
  columns = self.get_columns_in_relation(relation_a)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
- Name: dbt-firebolt
3
- Version: 1.8.3
2
+ Name: dbt_firebolt
3
+ Version: 1.9.1
4
4
  Summary: The Firebolt adapter plugin for dbt (data build tool)
5
5
  Home-page: https://github.com/firebolt-db/dbt-firebolt
6
6
  Author: Firebolt
@@ -78,7 +78,7 @@ The table below shows which dbt and Firebolt features are supported by the adapt
78
78
  | Incremental materializations - insert_overwrite | :white_check_mark: |
79
79
  | Incremental materializations - delete+insert | :white_check_mark: |
80
80
  | Incremental materializations - merge | :x: |
81
- | Snapshots | :x: |
81
+ | Snapshots | :white_check_mark: |
82
82
  | Seeds | :white_check_mark: |
83
83
  | Tests | :white_check_mark: |
84
84
  | Documentation | :white_check_mark: |
@@ -0,0 +1,13 @@
1
+ dbt/adapters/firebolt/__init__.py,sha256=jTWhFz0VsnTZFi4djXBOhAHvUJaeQvrHDSiVpDTfKM4,411
2
+ dbt/adapters/firebolt/__version__.py,sha256=zRlZGglif76ZVuWWSjsH_MMPgtVQqmj-SryYJW25FL4,69
3
+ dbt/adapters/firebolt/column.py,sha256=COo_wjhCFgS3GFcPIPcoq7WAWgzN6DB2XqG-gk51WBc,539
4
+ dbt/adapters/firebolt/connections.py,sha256=-R97hfke32n4j0cTUwd4A5xAwD8PqXVgnG7BPetQKcg,8010
5
+ dbt/adapters/firebolt/impl.py,sha256=eIqnXzoMoyHq2lp1yMz7O62WJ0apM16H8IssTTwDMiw,15075
6
+ dbt/adapters/firebolt/relation.py,sha256=Xg3Nrjw3UrF_qwnuGbPT97rSXRiDP1GlIAoBF4b7QnY,1922
7
+ dbt/adapters/firebolt/relation_configs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ dbt/include/firebolt/__init__.py,sha256=vBGWeG-dHHkimfnX8axBJ4IgAowFw8xADmo6Auzn2xc,52
9
+ dbt_firebolt-1.9.1.dist-info/LICENSE,sha256=Nn0EGvW3qmoZpBV_JVM3iPukFf3RiNCIizrWe_2oTHk,11354
10
+ dbt_firebolt-1.9.1.dist-info/METADATA,sha256=Vay4PDqyfZmqmUUuWUA9A4ChEngOmwZ-o5e-M6DLkYk,5237
11
+ dbt_firebolt-1.9.1.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
12
+ dbt_firebolt-1.9.1.dist-info/top_level.txt,sha256=B2YH4he17ajilEWOGCKHbRcEJlCuZKwCcgFcLPntLsE,4
13
+ dbt_firebolt-1.9.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: setuptools (75.3.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,6 +0,0 @@
1
-
2
- name: dbt_firebolt
3
- version: 1.0
4
- config-version: 2
5
-
6
- macro-paths: ['macros']
@@ -1,37 +0,0 @@
1
- {% macro firebolt__get_show_grant_sql(relation) %}
2
- {# Usually called from apply_grants. Should not be called directly. #}
3
- {{ adapter.raise_grant_error() }}
4
- {% endmacro %}
5
-
6
-
7
- {%- macro firebolt__get_grant_sql(relation, privilege, grantee) -%}
8
- {# Usually called from apply_grants. Should not be called directly. #}
9
- {{ adapter.raise_grant_error() }}
10
- {%- endmacro -%}
11
-
12
-
13
- {%- macro firebolt__get_revoke_sql(relation, privilege, grantee) -%}
14
- {# Usually called from apply_grants. Should not be called directly. #}
15
- {{ adapter.raise_grant_error() }}
16
- {%- endmacro -%}
17
-
18
-
19
- {% macro firebolt__copy_grants() %}
20
- {{ return(True) }}
21
- {% endmacro %}
22
-
23
-
24
- {% macro firebolt__apply_grants(relation, grant_config, should_revoke) %}
25
- {% if grant_config %}
26
- {{ adapter.raise_grant_error() }}
27
- {% endif %}
28
- {% endmacro %}
29
-
30
-
31
- {%- macro firebolt__get_dcl_statement_list(relation, grant_config, get_dcl_macro) -%}
32
- {# Firebolt does not support DCL statements yet #}
33
- {% if grant_config %}
34
- {{ adapter.raise_grant_error() }}
35
- {% endif %}
36
- {{ return([]) }}
37
- {%- endmacro %}
@@ -1,49 +0,0 @@
1
- {% macro firebolt__rename_relation(source, target) -%}
2
- {# Create new relation, do CTAS to swap it, remove original relation.
3
- Must check whether relation is view or table, because process is
4
- different for the two. #}
5
- {% set all_relations = (list_relations_without_caching(source)) %}
6
- {% set tables = adapter.filter_table(all_relations, 'type', 'table') %}
7
- {% set views = adapter.filter_table(all_relations, 'type', 'view') %}
8
- {% if (views.rows | length) > 0 %}
9
- {% call statement('view_definition', fetch_result=True) %}
10
-
11
- SELECT view_definition FROM information_schema.views
12
- WHERE table_name = '{{ source.identifier }}'
13
- {%- endcall %}
14
- {% if load_result('view_definition')['data'] %}
15
- {# For some reason this ocassionally returns an empty set.
16
- In that case do nothing. Don't even ask why I have to jump through
17
- the stupid hoops to get the value out of the result in the next line. #}
18
- {% set view_ddl = load_result('view_definition')['data'][0][0] %}
19
- {% set view_ddl = view_ddl.replace(source.identifier,
20
- target.identifier) %}
21
- {% call statement('new_view') %}
22
-
23
- DROP VIEW {{ source.identifier }};
24
- {{ view_ddl }};
25
- {% endcall %}
26
- {% endif %}
27
- {% elif (tables.rows | length) > 0 %}
28
- {# There were no views, so retrieve table. (There must be a table.) #}
29
- {% set table_type = adapter.filter_table(all_relations, 'table_type', '') %}
30
- {% call statement('tables') %}
31
-
32
- CREATE {{ table_type }} TABLE {{ target.identifier }} AS
33
- SELECT * FROM {{ source.identifier }};
34
- DROP TABLE {{ source.identifier }};
35
- {%- endcall %}
36
- {% endif %}
37
- {% endmacro %}
38
-
39
-
40
- {% macro firebolt__drop_relation(relation) -%}
41
- {#-
42
- Drop relation. Drop both table and view because relation doesn't always
43
- have a table_type specified.
44
- #}
45
- {% call statement('drop') %}
46
-
47
- DROP {{ relation.type | upper }} IF EXISTS {{ relation }} CASCADE;
48
- {% endcall %}
49
- {% endmacro %}
@@ -1,197 +0,0 @@
1
- {% macro firebolt__drop_schema(schema_relation) -%}
2
- {# Drop tables and views for schema_relation.
3
- Args:
4
- schema_relation (dict): Contains values for database and schema.
5
- Until schemas are supported this macro will drop all tables and views.
6
- #}
7
- {% set all_relations = (list_relations_without_caching(schema_relation)) %}
8
-
9
- {% set views = adapter.filter_table(all_relations, 'type', 'view') %}
10
- {% set tables = adapter.filter_table(all_relations, 'type', 'table') %}
11
- {% do drop_relations_loop(views) %}
12
- {% do drop_relations_loop(tables) %}
13
- {% endmacro %}
14
-
15
-
16
- {% macro drop_relations_loop(relations) %}
17
- {% for row in relations %}
18
- {%- set relation = api.Relation.create(database=target.database,
19
- schema=target.schema,
20
- identifier=row[1],
21
- type=row[3]) -%}
22
- {{ adapter.drop_relation(relation) }}
23
- {%- endfor %}
24
- {% endmacro %}
25
-
26
-
27
- {% macro firebolt__list_schemas(database) %}
28
- {# Return current schema. Name is a misnomer.
29
- TODO: Should this actually return all schemas? #}
30
- {% call statement('list_schemas', fetch_result=True, auto_begin=False) %}
31
-
32
- SELECT 'public' AS schema
33
- {% endcall %}
34
- {{ return(load_result('list_schemas').table) }}
35
- {% endmacro %}
36
-
37
-
38
- {% macro firebolt__create_schema(relation) -%}
39
- {# stub. Not yet supported in Firebolt. #}
40
- {%- call statement('create_schema') %}
41
-
42
- SELECT 'create_schema'
43
- {% endcall %}
44
- {% endmacro %}
45
-
46
-
47
- {% macro firebolt__alter_column_type(relation, column_name, new_column_type) -%}
48
- {# Stub: alter statements not currently available in Firebolt. #}
49
- {% call statement('alter_column_type') %}
50
-
51
- SELECT 'alter_column_type'
52
- {% endcall %}
53
- {% endmacro %}
54
-
55
-
56
- {% macro firebolt__check_schema_exists(information_schema, schema) -%}
57
- {# Stub. Will be replaced by query later. #}
58
- {% call statement('check_schema_exists', fetch_result=True, auto_begin=True) %}
59
-
60
- SELECT 'schema_exists'
61
- {% endcall %}
62
- {{ return(load_result('check_schema_exists').table) }}
63
- {% endmacro %}
64
-
65
-
66
- {% macro make_create_index_sql(relation,
67
- index_name,
68
- create_statement,
69
- spine_col,
70
- other_col) -%}
71
- {# Create and return SQL for generating a join or aggregating index.
72
- Args:
73
- relation (dict):
74
- index_name (str): name of the index
75
- create_statement (str): either "CREATE JOIN INDEX" or
76
- "CREATE AND GENERATE AGGREGATING INDEX"
77
- spine_col ([str]):
78
- if agg index, key columns
79
- if join index, join column
80
- other_col ([str]):
81
- if agg index, aggregating columns
82
- if join index, dimension column
83
- #}
84
- {{ create_statement }} "{{ index_name }}" ON {{ relation }} (
85
- {% if spine_col is iterable and spine_col is not string -%}
86
- {{ spine_col | join(', ') }},
87
- {% else -%}
88
- {{ spine_col }},
89
- {% endif -%}
90
- {% if other_col is iterable and other_col is not string -%}
91
- {{ other_col | join(', ') }}
92
- {%- else -%}
93
- {{ other_col }}
94
- {%- endif -%}
95
- );
96
- {% endmacro %}
97
-
98
-
99
- {% macro drop_index(index_name, index_type) -%}
100
- {# Drop aggregating or join index. #}
101
- {% call statement('drop_index', auto_begin=False) %}
102
-
103
- DROP {{ index_type | upper }} INDEX "{{ index_name }}"
104
- {% endcall %}
105
- {% endmacro %}
106
-
107
-
108
- {% macro firebolt__get_create_index_sql(relation, index_dict) -%}
109
- {# Return aggregating or join index SQL string. #}
110
- {# Parse index inputs and send parsed input to make_create_index_sql #}
111
- {%- set index_config = adapter.parse_index(index_dict) -%}
112
- {%- set index_name = index_config.render_name(relation) -%}
113
- {%- set index_type = index_config.index_type | upper -%}
114
- {%- if index_type == "JOIN" -%}
115
- {{ make_create_index_sql(relation,
116
- index_name,
117
- "CREATE JOIN INDEX",
118
- index_config.join_columns,
119
- index_config.dimension_column) }}
120
- {%- elif index_type == "AGGREGATING" -%}
121
- {{ make_create_index_sql(relation,
122
- index_name,
123
- "CREATE AND GENERATE AGGREGATING INDEX",
124
- index_config.key_columns,
125
- index_config.aggregation) }}
126
- {%- endif -%}
127
- {%- endmacro %}
128
-
129
-
130
- {% macro sql_convert_columns_in_relation_firebolt(rows) -%}
131
- {% set columns = [] %}
132
- {% for row in rows %}
133
- {% do columns.append(api.Column(*row)) %}
134
- {% endfor %}
135
- {{ return(columns) }}
136
- {% endmacro %}
137
-
138
-
139
- {% macro firebolt__get_columns_in_relation(relation) -%}
140
- {#-
141
- Return column information for table identified by relation as
142
- List[FireboltColumn].
143
- Args: relation: dbt Relation
144
- -#}
145
- {% set sql %}
146
- SELECT column_name, data_type from information_schema.columns
147
- WHERE table_name = '{{ relation.identifier }}'
148
- {% endset %}
149
- {%- set result = run_query(sql) -%}
150
- {% set columns = [] %}
151
- {% for row in result %}
152
- {% do columns.append(adapter.get_column_class().from_description(row['column_name'],
153
- adapter.resolve_special_columns(row['data_type']))) %}
154
- {% endfor %}
155
- {% do return(columns) %}
156
- {% endmacro %}
157
-
158
-
159
- {% macro firebolt__list_relations_without_caching(relation) %}
160
- {# Return all views and tables as agate table.
161
- Args:
162
- relation (dict): Contains values for database and schema.
163
-
164
- dbt has a relations cache. Using this macro will list all
165
- the relations in the current schema using a direct DB query,
166
- rather than checking the cache. So the name is a misnomer. Should
167
- be list_relations_bypassing_cache or something.
168
- #}
169
- {% call statement('list_tables_without_caching', fetch_result=True) %}
170
-
171
- SELECT
172
- table_catalog AS "database",
173
- table_name AS "name",
174
- '{{ relation.schema }}' AS "schema",
175
- CASE
176
- WHEN table_type = 'VIEW' THEN 'view'
177
- ELSE 'table'
178
- END AS "type"
179
- FROM
180
- information_schema.tables
181
- {% endcall %}
182
- {% set info_table = load_result('list_tables_without_caching').table %}
183
- {{ return(info_table) }}
184
- {% endmacro %}
185
-
186
- {% macro firebolt__truncate_relation(relation) -%}
187
- {#
188
- Truncate relation. Actual macro is drop_relation in ./adapters/relation.sql.
189
- #}
190
-
191
- {# Firebolt doesn't currently support TRUNCATE, so DROP CASCADE.
192
- This should only be called from reset_csv_table, where it's followed by
193
- `create_csv_table`, so not recreating the table here. To retrieve old code,
194
- see commit f9984f6d61b8a1b877bc107b102eeb30eba54f35
195
- This will be replaced by `CREATE OR REPLACE`. #}
196
- {{ adapter.drop_relation(relation) }}
197
- {% endmacro %}
@@ -1,103 +0,0 @@
1
- {# This is for building docs. Right now it's an incomplete description of
2
- the columns (for instance, `is_nullable` is missing) but more could be added later. #}
3
-
4
- {% macro firebolt__get_catalog(information_schema, schemas) -%}
5
-
6
- {% set query %}
7
- with tables as (
8
- {{ firebolt__get_catalog_tables_sql(information_schema) }}
9
- {{ firebolt__get_catalog_schemas_where_clause_sql(schemas) }}
10
- ),
11
- columns as (
12
- {{ firebolt__get_catalog_columns_sql(information_schema) }}
13
- {{ firebolt__get_catalog_schemas_where_clause_sql(schemas) }}
14
- )
15
- {{ firebolt__get_catalog_results_sql() }}
16
- {%- endset -%}
17
-
18
- {{ return(run_query(query)) }}
19
-
20
- {%- endmacro %}
21
-
22
- {% macro firebolt__get_catalog_relations(information_schema, relations) -%}
23
-
24
- {% set query %}
25
- with tables as (
26
- {{ firebolt__get_catalog_tables_sql(information_schema) }}
27
- {{ firebolt__get_catalog_relations_where_clause_sql(relations) }}
28
- ),
29
- columns as (
30
- {{ firebolt__get_catalog_columns_sql(information_schema) }}
31
- {{ firebolt__get_catalog_relations_where_clause_sql(relations) }}
32
- )
33
- {{ firebolt__get_catalog_results_sql() }}
34
- {%- endset -%}
35
-
36
- {{ return(run_query(query)) }}
37
-
38
- {%- endmacro %}
39
-
40
-
41
- {% macro firebolt__get_catalog_tables_sql(information_schema) -%}
42
- SELECT
43
- tbls.table_catalog AS table_database,
44
- tbls.table_schema as table_schema,
45
- table_type,
46
- tbls.table_name as table_name,
47
- CASE
48
- WHEN table_type = 'VIEW' THEN 'VIEW'
49
- ELSE 'TABLE'
50
- END AS relation_type
51
- FROM
52
- information_schema.tables tbls
53
- {%- endmacro %}
54
-
55
-
56
- {% macro firebolt__get_catalog_columns_sql(information_schema) -%}
57
- select
58
- table_catalog as "table_database",
59
- table_schema as "table_schema",
60
- table_name as "table_name",
61
- column_name as "column_name",
62
- ordinal_position as "column_index",
63
- data_type as "column_type"
64
- from information_schema.columns
65
- {%- endmacro %}
66
-
67
- {% macro firebolt__get_catalog_results_sql() -%}
68
- SELECT *
69
- FROM tables
70
- JOIN columns USING ("table_database", "table_schema", "table_name")
71
- ORDER BY "column_index"
72
- {%- endmacro %}
73
-
74
-
75
- {% macro firebolt__get_catalog_schemas_where_clause_sql(schemas) -%}
76
- WHERE ({%- for schema in schemas -%}
77
- UPPER("table_schema") = UPPER('{{ schema }}'){%- if not loop.last %} OR {% endif -%}
78
- {%- endfor -%})
79
- {%- endmacro %}
80
-
81
-
82
- {% macro firebolt__get_catalog_relations_where_clause_sql(relations) -%}
83
- WHERE (
84
- {%- for relation in relations -%}
85
- {% if relation.schema and relation.identifier %}
86
- (
87
- UPPER("table_schema") = UPPER('{{ relation.schema }}')
88
- AND UPPER("table_name") = UPPER('{{ relation.identifier }}')
89
- )
90
- {% elif relation.schema %}
91
- (
92
- UPPER("table_schema") = UPPER('{{ relation.schema }}')
93
- )
94
- {% else %}
95
- {% do exceptions.raise_compiler_error(
96
- '`get_catalog_relations` requires a list of relations, each with a schema'
97
- ) %}
98
- {% endif %}
99
-
100
- {%- if not loop.last %} OR {% endif -%}
101
- {%- endfor -%}
102
- )
103
- {%- endmacro %}