From da2b8a902ea89f0f2c13015c72c0d2a8667f0b61 Mon Sep 17 00:00:00 2001 From: Pradeep Srikakolapu Date: Thu, 30 May 2024 20:14:24 -0700 Subject: [PATCH] Updating dev requirements and requirements to run dbt-synapse adapter --- .../synapse/macros/adapters/metadata.sql | 4 ++ .../macros/materializations/tests/helpers.sql | 41 +++++++++++++++++++ dev_requirements.txt | 1 - setup.py | 4 +- 4 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 dbt/include/synapse/macros/materializations/tests/helpers.sql diff --git a/dbt/include/synapse/macros/adapters/metadata.sql b/dbt/include/synapse/macros/adapters/metadata.sql index 7d052d1..5ddbebd 100644 --- a/dbt/include/synapse/macros/adapters/metadata.sql +++ b/dbt/include/synapse/macros/adapters/metadata.sql @@ -1,6 +1,10 @@ {%- macro synapse__get_use_database_sql(database) -%} {%- endmacro -%} +{%- macro default__get_use_database_sql(database) -%} + {{ return('') }} +{%- endmacro -%} + {% macro synapse__list_schemas(database) %} {% call statement('list_schemas', fetch_result=True, auto_begin=False) -%} select name as [schema] diff --git a/dbt/include/synapse/macros/materializations/tests/helpers.sql b/dbt/include/synapse/macros/materializations/tests/helpers.sql new file mode 100644 index 0000000..c1f188b --- /dev/null +++ b/dbt/include/synapse/macros/materializations/tests/helpers.sql @@ -0,0 +1,41 @@ +{% macro synapse__get_test_sql(main_sql, fail_calc, warn_if, error_if, limit) -%} + + -- Create target schema in synapse db if it does not + IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = '{{ target.schema }}') + BEGIN + EXEC('CREATE SCHEMA [{{ target.schema }}]') + END + + {% if main_sql.strip().lower().startswith('with') %} + {% set testview %} + {{ target.schema }}.testview_{{ range(1300, 19000) | random }} + {% endset %} + + {% set sql = main_sql.replace("'", "''")%} + EXEC('create view {{testview}} as {{ sql }};') + select + {{ "top (" ~ limit ~ ')' if limit != none }} + {{ fail_calc }} as failures, + case when {{ fail_calc }} {{ warn_if }} + then 'true' else 'false' end as should_warn, + case when {{ fail_calc }} {{ error_if }} + then 'true' else 'false' end as should_error + from ( + select * from {{testview}} + ) dbt_internal_test; + + EXEC('drop view {{testview}};') + + {% else -%} + select + {{ "top (" ~ limit ~ ')' if limit != none }} + {{ fail_calc }} as failures, + case when {{ fail_calc }} {{ warn_if }} + then 'true' else 'false' end as should_warn, + case when {{ fail_calc }} {{ error_if }} + then 'true' else 'false' end as should_error + from ( + {{ main_sql }} + ) dbt_internal_test + {%- endif -%} +{%- endmacro %} diff --git a/dev_requirements.txt b/dev_requirements.txt index cb8b201..a917900 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -4,7 +4,6 @@ git+https://github.com/dbt-labs/dbt-core.git@v1.8.0#egg=dbt-core&subdirectory=co git+https://github.com/dbt-labs/dbt-adapters.git git+https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-tests-adapter git+https://github.com/dbt-labs/dbt-common.git -git+https://github.com/microsoft/dbt-fabric.git@v1.8.6 pytest==8.0.1 twine==5.0.0 diff --git a/setup.py b/setup.py index 131a427..2f00c3d 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ "Sam Debruyn", ] dbt_version = "1.8" -#dbt_fabric_requirement = "dbt-fabric==1.8.4" +dbt_fabric_requirement = "dbt-fabric==1.8.6" description = """An Azure Synapse adapter plugin for dbt""" this_directory = os.path.abspath(os.path.dirname(__file__)) @@ -73,7 +73,7 @@ def run(self): url="https://github.com/dbt-msft/dbt-synapse", packages=find_namespace_packages(include=["dbt", "dbt.*"]), include_package_data=True, - #install_requires=[dbt_fabric_requirement], + install_requires=[dbt_fabric_requirement], cmdclass={ "verify": VerifyVersionCommand, },