From 2cad5b8f7857242e5cbdc4939bfd5af3425441ac Mon Sep 17 00:00:00 2001 From: Pradeep Srikakolapu Date: Tue, 10 Sep 2024 19:41:12 -0700 Subject: [PATCH 1/2] Addressing Issue #222 and #223 --- dbt/adapters/fabric/fabric_column.py | 1 + dbt/adapters/fabric/fabric_relation.py | 6 ++--- .../macros/materializations/seeds/helpers.sql | 23 +++++++++++++++++++ .../materializations/snapshots/helpers.sql | 2 +- dev_requirements.txt | 6 ++--- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/dbt/adapters/fabric/fabric_column.py b/dbt/adapters/fabric/fabric_column.py index 4632276b..8801bf3c 100644 --- a/dbt/adapters/fabric/fabric_column.py +++ b/dbt/adapters/fabric/fabric_column.py @@ -10,6 +10,7 @@ class FabricColumn(Column): "FLOAT": "FLOAT", "INTEGER": "INT", "BOOLEAN": "BIT", + "DATETIME2(6)": "DATETIME2(6)", } @classmethod diff --git a/dbt/adapters/fabric/fabric_relation.py b/dbt/adapters/fabric/fabric_relation.py index 2ca2c7fb..a061e614 100644 --- a/dbt/adapters/fabric/fabric_relation.py +++ b/dbt/adapters/fabric/fabric_relation.py @@ -18,10 +18,10 @@ def get_relation_type(cls) -> Type[FabricRelationType]: @classmethod def render_limited(self) -> str: - rendered = self.render(self=self) + rendered = self.render() if self.limit is None: return rendered elif self.limit == 0: - return f"(select * from {rendered} where 1=0) _dbt_top_subq" + return f"(select * from {rendered} where 1=0) {self._render_limited_alias()}" else: - return f"(select TOP {self.limit} * from {rendered}) _dbt_top_subq" + return f"(select TOP {self.limit} * from {rendered}) {self._render_limited_alias()}" diff --git a/dbt/include/fabric/macros/materializations/seeds/helpers.sql b/dbt/include/fabric/macros/materializations/seeds/helpers.sql index f4768890..03e83315 100644 --- a/dbt/include/fabric/macros/materializations/seeds/helpers.sql +++ b/dbt/include/fabric/macros/materializations/seeds/helpers.sql @@ -57,3 +57,26 @@ {# Return SQL so we can render it out into the compiled files #} {{ return(statements[0]) }} {% endmacro %} + +{% macro fabric__create_csv_table(model, agate_table) %} + {%- set column_override = model['config'].get('column_types', {}) -%} + {%- set quote_seed_column = model['config'].get('quote_columns', None) -%} + + {% set sql %} + create table {{ this.render() }} ( + {%- for col_name in agate_table.column_names -%} + {%- set inferred_type = adapter.convert_type(agate_table, loop.index0) -%} + {%- set type = column_override.get(col_name, inferred_type) -%} + {{ log(inferred_type ~ 'column data type inferred for '~ type )}} + {%- set column_name = (col_name | string) -%} + {{ adapter.quote_seed_column(column_name, quote_seed_column) }} {{ type }} {%- if not loop.last -%}, {%- endif -%} + {%- endfor -%} + ) + {% endset %} + + {% call statement('_') -%} + {{ sql }} + {%- endcall %} + + {{ return(sql) }} +{% endmacro %} diff --git a/dbt/include/fabric/macros/materializations/snapshots/helpers.sql b/dbt/include/fabric/macros/materializations/snapshots/helpers.sql index bf7c77a5..29d4934c 100644 --- a/dbt/include/fabric/macros/materializations/snapshots/helpers.sql +++ b/dbt/include/fabric/macros/materializations/snapshots/helpers.sql @@ -11,7 +11,7 @@ {% set columns %} {% for column in columns %} - , CAST(NULL AS {{column.data_type}}) AS {{column_name}} + , CAST(NULL AS {{column.data_type}}) AS {{column.name}} {% endfor %} {% endset %} diff --git a/dev_requirements.txt b/dev_requirements.txt index a42c6b9a..d3313a49 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -6,10 +6,10 @@ git+https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-tests-adapter git+https://github.com/dbt-labs/dbt-common.git pytest==8.0.1 -twine==5.0.0 -wheel==0.42 +twine==5.1.1 +wheel==0.44.0 pre-commit==3.5.0;python_version<"3.9" -pre-commit==3.6.2;python_version>="3.9" +pre-commit==3.8.0;python_version>="3.9" pytest-dotenv==0.5.2 flaky==3.7.0 pytest-xdist==3.5.0 From c376134f5e4cd650a528c4ba7dfa30469ef3b198 Mon Sep 17 00:00:00 2001 From: Pradeep Srikakolapu Date: Tue, 10 Sep 2024 19:45:18 -0700 Subject: [PATCH 2/2] Addressing Issue #222 and #223 --- dbt/adapters/fabric/fabric_column.py | 1 - .../macros/materializations/seeds/helpers.sql | 23 ------------------- 2 files changed, 24 deletions(-) diff --git a/dbt/adapters/fabric/fabric_column.py b/dbt/adapters/fabric/fabric_column.py index 8801bf3c..4632276b 100644 --- a/dbt/adapters/fabric/fabric_column.py +++ b/dbt/adapters/fabric/fabric_column.py @@ -10,7 +10,6 @@ class FabricColumn(Column): "FLOAT": "FLOAT", "INTEGER": "INT", "BOOLEAN": "BIT", - "DATETIME2(6)": "DATETIME2(6)", } @classmethod diff --git a/dbt/include/fabric/macros/materializations/seeds/helpers.sql b/dbt/include/fabric/macros/materializations/seeds/helpers.sql index 03e83315..f4768890 100644 --- a/dbt/include/fabric/macros/materializations/seeds/helpers.sql +++ b/dbt/include/fabric/macros/materializations/seeds/helpers.sql @@ -57,26 +57,3 @@ {# Return SQL so we can render it out into the compiled files #} {{ return(statements[0]) }} {% endmacro %} - -{% macro fabric__create_csv_table(model, agate_table) %} - {%- set column_override = model['config'].get('column_types', {}) -%} - {%- set quote_seed_column = model['config'].get('quote_columns', None) -%} - - {% set sql %} - create table {{ this.render() }} ( - {%- for col_name in agate_table.column_names -%} - {%- set inferred_type = adapter.convert_type(agate_table, loop.index0) -%} - {%- set type = column_override.get(col_name, inferred_type) -%} - {{ log(inferred_type ~ 'column data type inferred for '~ type )}} - {%- set column_name = (col_name | string) -%} - {{ adapter.quote_seed_column(column_name, quote_seed_column) }} {{ type }} {%- if not loop.last -%}, {%- endif -%} - {%- endfor -%} - ) - {% endset %} - - {% call statement('_') -%} - {{ sql }} - {%- endcall %} - - {{ return(sql) }} -{% endmacro %}