Skip to content
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

Fix get columns in relation #197

Merged
merged 3 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixes

- Fix column-level `persist_docs` on Delta tables, add tests ([#180](https://github.com/fishtown-analytics/dbt-spark/pull/180))
- Fix `get_columns_in_relation` when called on models created in the same run ([#197](https://github.com/dbt-labs/dbt-spark/pull/197))

## dbt-spark 0.20.0rc1 (June 8, 2021)

Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/spark/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def get_columns_in_relation(self, relation: Relation) -> List[SparkColumn]:
for cached_relation in cached_relations
if str(cached_relation) == str(relation)),
None)
if cached_relation is None:
if cached_relation is None or cached_relation.information is None:
rows: List[agate.Row] = super().get_columns_in_relation(relation)
columns = self.parse_describe_extended(relation, rows)
else:
Expand Down
1 change: 1 addition & 0 deletions test/custom/get_columns_in_relation/models/child.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
{% set cols = adapter.get_columns_in_relation(ref('child')) %}
{% for col in cols %}
{{ adapter.quote(col.column) }}{%- if not loop.last %},{{ '\n ' }}{% endif %}
{% endfor %}
FROM {{ ref('child') }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from test.custom.base import DBTSparkIntegrationTest, use_profile


class TestGetColumnInRelationInSameRun(DBTSparkIntegrationTest):
@property
def schema(self):
return "get_columns_in_relation"

@property
def models(self):
return "models"

def run_and_test(self):
self.run_dbt(["run"])
self.assertTablesEqual("child", "get_columns_from_child")

@use_profile("apache_spark")
def test_get_columns_in_relation_in_same_run_apache_spark(self):
self.run_and_test()

@use_profile("databricks_cluster")
def test_get_columns_in_relation_in_same_run_databricks_cluster(self):
self.run_and_test()

@use_profile("databricks_sql_endpoint")
def test_get_columns_in_relation_in_same_run_databricks_sql_endpoint(self):
self.run_and_test()