-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dbt-msft:master' into seed-logic-fix
- Loading branch information
Showing
12 changed files
with
450 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version = "1.8.0" | ||
version = "1.8.0rc1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{% macro sqlserver__get_test_sql(main_sql, fail_calc, warn_if, error_if, limit) -%} | ||
|
||
-- Create target schema if it does not | ||
USE [{{ target.database }}]; | ||
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = '{{ target.schema }}') | ||
BEGIN | ||
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) %} | ||
|
||
{% 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; | ||
|
||
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import pytest | ||
from dbt.tests.util import get_connection, run_dbt | ||
|
||
model_sql = """ | ||
SELECT 1 AS data | ||
""" | ||
|
||
table_mat = """ | ||
{{ | ||
config({ | ||
"materialized": 'table' | ||
}) | ||
}} | ||
SELECT 1 AS data | ||
""" | ||
|
||
view_mat = """ | ||
{{ | ||
config({ | ||
"materialized": 'view' | ||
}) | ||
}} | ||
SELECT 1 AS data | ||
""" | ||
|
||
schema = """ | ||
version: 2 | ||
models: | ||
- name: mat_object | ||
""" | ||
|
||
|
||
class BaseTableView: | ||
def create_object(self, project, sql): | ||
with get_connection(project.adapter): | ||
project.adapter.execute(sql, fetch=True) | ||
|
||
|
||
class TestTabletoView(BaseTableView): | ||
"""Test if changing from a table object to a view object correctly replaces""" | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"mat_object.sql": view_mat, "schema.yml": schema} | ||
|
||
def test_passes(self, project): | ||
self.create_object( | ||
project, f"SELECT * INTO {project.test_schema}.mat_object FROM ({model_sql}) t" | ||
) | ||
run_dbt(["run"]) | ||
|
||
|
||
class TestViewtoTable(BaseTableView): | ||
"""Test if changing from a view object to a table object correctly replaces""" | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"mat_object.sql": table_mat, "schema.yml": schema} | ||
|
||
def test_passes(self, project): | ||
self.create_object(project, f"CREATE VIEW {project.test_schema}.mat_object AS {model_sql}") | ||
run_dbt(["run"]) |
Oops, something went wrong.