diff --git a/.devcontainer/devcontainer-lock.json b/.devcontainer/devcontainer-lock.json deleted file mode 100644 index a3500695..00000000 --- a/.devcontainer/devcontainer-lock.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "features": { - "ghcr.io/devcontainers/features/docker-in-docker:2": { - "version": "2.7.1", - "resolved": "ghcr.io/devcontainers/features/docker-in-docker@sha256:f6a73ee06601d703db7d95d03e415cab229e78df92bb5002e8559bcfc047fec6", - "integrity": "sha256:f6a73ee06601d703db7d95d03e415cab229e78df92bb5002e8559bcfc047fec6" - } - } -} diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a706161e..a359181f 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ "name": "Python 3", "image": "mcr.microsoft.com/devcontainers/python:1-3.10-bookworm", "features": { - "ghcr.io/devcontainers/features/docker-in-docker:2": {} + "ghcr.io/devcontainers/features/docker-in-docker:2.12.0": {} }, "forwardPorts": [1433], "postStartCommand": "/bin/bash ./.devcontainer/setup_odbc.sh & /bin/bash ./.devcontainer/setup_env.sh", diff --git a/.gitignore b/.gitignore index 1e5f776c..d11d5ddc 100644 --- a/.gitignore +++ b/.gitignore @@ -97,4 +97,4 @@ env.bak/ venv.bak/ .mise.toml -**devcontainer-lock.json** +devcontainer-lock.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 9beac3fb..a5a9742f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### v1.8.4 + +- Minor fix to tests with CTEs which do not start on first line. https://github.com/dbt-msft/dbt-sqlserver/issues/560 + ### v1.8.3 - Minor fix in no lock behaviour https://github.com/dbt-msft/dbt-sqlserver/pull/557 diff --git a/dbt/adapters/sqlserver/__version__.py b/dbt/adapters/sqlserver/__version__.py index eaf9d19e..f2493fc9 100644 --- a/dbt/adapters/sqlserver/__version__.py +++ b/dbt/adapters/sqlserver/__version__.py @@ -1 +1 @@ -version = "1.8.3" +version = "1.8.4" diff --git a/dbt/include/sqlserver/macros/materializations/tests.sql b/dbt/include/sqlserver/macros/materializations/tests.sql index 36d79af7..a0d79bb2 100644 --- a/dbt/include/sqlserver/macros/materializations/tests.sql +++ b/dbt/include/sqlserver/macros/materializations/tests.sql @@ -7,40 +7,23 @@ EXEC('CREATE SCHEMA [{{ target.schema }}]') END - {% set with_statement_pattern = 'with .+ as\s*\(' %} - {% set re = modules.re %} - {% set is_match = re.search(with_statement_pattern, main_sql, re.IGNORECASE) %} + {% set testview %} + [{{ target.schema }}.testview_{{ range(1300, 19000) | random }}] + {% endset %} - {% if is_match %} - {% 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; - {% 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}};') - 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/tests/functional/adapter/mssql/test_test_with.py b/tests/functional/adapter/mssql/test_test_with.py index 6cf6476a..83e1d7fc 100644 --- a/tests/functional/adapter/mssql/test_test_with.py +++ b/tests/functional/adapter/mssql/test_test_with.py @@ -84,6 +84,20 @@ {% endtest %} """ +with_test_multiline = """ +{% test with_test_multiline(model, field) %} +-- comments +with + +test_sample AS ( + SELECT {{ field }} FROM {{ model }} + GROUP BY {{ field }} + HAVING COUNT(*) > 2 +) +SELECT * FROM test_sample +{% endtest %} +""" + class BaseSQLTestWith: @pytest.fixture(scope="class") @@ -99,6 +113,7 @@ def macros(self): "with_statement_pass.sql": with_test_pass_sql, "with_statement_fail.sql": with_test_fail_sql, "with_statement_comments.sql": with_test_with_comments_sql, + "with_test_multiline.sql": with_test_multiline, } @pytest.fixture(scope="class")