-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Fix scenarios where --empty
flag pushes limit 0
into metadata queries
#1100
Changes from all commits
0e02477
c259215
6d6bc21
a4042d4
799e595
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: Fixes | ||
body: Fix scenario where using the `--empty` flag causes metadata queries to contain | ||
limit clauses | ||
time: 2024-06-28T19:01:40.558234-04:00 | ||
custom: | ||
Author: mikealfare | ||
Issue: "1033" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
SEED = """ | ||
my_id,my_value | ||
1,a | ||
2,b | ||
3,c | ||
""".strip() | ||
|
||
|
||
SCHEMA = """ | ||
version: 2 | ||
|
||
seeds: | ||
- name: my_seed | ||
description: "This is my_seed" | ||
columns: | ||
- name: id | ||
description: "This is my_seed.my_id" | ||
""" | ||
|
||
CONTROL = """ | ||
select * from {{ ref("my_seed") }} | ||
""" | ||
|
||
|
||
GET_COLUMNS_IN_RELATION = """ | ||
{{ config(materialized="table") }} | ||
{% set columns = adapter.get_columns_in_relation(ref("my_seed")) %} | ||
select * from {{ ref("my_seed") }} | ||
""" | ||
|
||
|
||
ALTER_COLUMN_TYPE = """ | ||
{{ config(materialized="table") }} | ||
{{ alter_column_type(ref("my_seed"), "MY_VALUE", "varchar") }} | ||
select * from {{ ref("my_seed") }} | ||
""" | ||
|
||
|
||
ALTER_RELATION_COMMENT = """ | ||
{{ config( | ||
materialized="table", | ||
persist_docs={"relations": True}, | ||
) }} | ||
select * from {{ ref("my_seed") }} | ||
""" | ||
|
||
|
||
ALTER_COLUMN_COMMENT = """ | ||
{{ config( | ||
materialized="table", | ||
persist_docs={"columns": True}, | ||
) }} | ||
select * from {{ ref("my_seed") }} | ||
""" | ||
|
||
|
||
ALTER_RELATION_ADD_REMOVE_COLUMNS = """ | ||
{{ config(materialized="table") }} | ||
{% set my_seed = adapter.Relation.create(this.database, this.schema, "my_seed", "table") %} | ||
{% set my_column = api.Column("my_column", "varchar") %} | ||
{% do alter_relation_add_remove_columns(my_seed, [my_column], none) %} | ||
{% do alter_relation_add_remove_columns(my_seed, none, [my_column]) %} | ||
select * from {{ ref("my_seed") }} | ||
""" | ||
|
||
|
||
TRUNCATE_RELATION = """ | ||
{{ config(materialized="table") }} | ||
{% set my_seed = adapter.Relation.create(this.database, this.schema, "my_seed", "table") %} | ||
{{ truncate_relation(my_seed) }} | ||
select * from {{ ref("my_seed") }} | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
from dbt.tests.adapter.empty.test_empty import BaseTestEmpty, BaseTestEmptyInlineSourceRef | ||
from dbt.tests.util import run_dbt | ||
import pytest | ||
|
||
from tests.functional.adapter.empty import _models | ||
|
||
|
||
class TestSnowflakeEmpty(BaseTestEmpty): | ||
|
@@ -7,3 +11,41 @@ class TestSnowflakeEmpty(BaseTestEmpty): | |
|
||
class TestSnowflakeEmptyInlineSourceRef(BaseTestEmptyInlineSourceRef): | ||
pass | ||
|
||
|
||
class TestMetadataWithEmptyFlag: | ||
@pytest.fixture(scope="class") | ||
def seeds(self): | ||
return {"my_seed.csv": _models.SEED} | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"schema.yml": _models.SCHEMA, | ||
"control.sql": _models.CONTROL, | ||
"get_columns_in_relation.sql": _models.GET_COLUMNS_IN_RELATION, | ||
"alter_column_type.sql": _models.ALTER_COLUMN_TYPE, | ||
"alter_relation_comment.sql": _models.ALTER_RELATION_COMMENT, | ||
"alter_column_comment.sql": _models.ALTER_COLUMN_COMMENT, | ||
"alter_relation_add_remove_columns.sql": _models.ALTER_RELATION_ADD_REMOVE_COLUMNS, | ||
"truncate_relation.sql": _models.TRUNCATE_RELATION, | ||
} | ||
|
||
@pytest.fixture(scope="class", autouse=True) | ||
def setup(self, project): | ||
run_dbt(["seed"]) | ||
|
||
@pytest.mark.parametrize( | ||
"model", | ||
[ | ||
"control", | ||
"get_columns_in_relation", | ||
"alter_column_type", | ||
"alter_relation_comment", | ||
"alter_column_comment", | ||
"alter_relation_add_remove_columns", | ||
"truncate_relation", | ||
], | ||
) | ||
def test_run(self, project, model): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of these tests pass even without fixing |
||
run_dbt(["run", "--empty", "--select", model]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this will move into
dbt-tests-adapter
and then imported here afterwards.