Skip to content

Commit

Permalink
More consistent results from get_columns_in_relation (dbt-labs#355)
Browse files Browse the repository at this point in the history
* More consistent results from get_columns_in_relation

* Not dispatched, full name

* Add changelog entry
  • Loading branch information
jtcohen6 authored and francescomucio committed May 16, 2022
1 parent 26c9d42 commit 98ea5e3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## dbt-spark 1.1.0 (TBD)
## dbt-spark 1.2.0 (April 28, 2022)

### Fixes
- `adapter.get_columns_in_relation` (method) and `get_columns_in_relation` (macro) now return identical responses. The previous behavior of `get_columns_in_relation` (macro) is now represented by a new macro, `get_columns_in_relation_raw` ([#354](https://github.com/dbt-labs/dbt-spark/issues/354), [#355](https://github.com/dbt-labs/dbt-spark/pull/355))

## dbt-spark 1.1.0 (April 28, 2022)

### Features
- Add session connection method ([#272](https://github.com/dbt-labs/dbt-spark/issues/272), [#279](https://github.com/dbt-labs/dbt-spark/pull/279))
Expand Down
6 changes: 4 additions & 2 deletions dbt/adapters/spark/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

logger = AdapterLogger("Spark")

GET_COLUMNS_IN_RELATION_MACRO_NAME = "get_columns_in_relation"
GET_COLUMNS_IN_RELATION_RAW_MACRO_NAME = "spark__get_columns_in_relation_raw"
LIST_SCHEMAS_MACRO_NAME = "list_schemas"
LIST_RELATIONS_MACRO_NAME = "list_relations_without_caching"
DROP_RELATION_MACRO_NAME = "drop_relation"
Expand Down Expand Up @@ -225,7 +225,9 @@ def get_columns_in_relation(self, relation: Relation) -> List[SparkColumn]:
# use get_columns_in_relation spark macro
# which would execute 'describe extended tablename' query
try:
rows: List[agate.Row] = super().get_columns_in_relation(relation)
rows: List[agate.Row] = self.execute_macro(
GET_COLUMNS_IN_RELATION_RAW_MACRO_NAME, kwargs={"relation": relation}
)
columns = self.parse_describe_extended(relation, rows)
except dbt.exceptions.RuntimeException as e:
# spark would throw error when table doesn't exist, where other
Expand Down
10 changes: 7 additions & 3 deletions dbt/include/spark/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,15 @@
{%- endcall -%}
{% endmacro %}

{% macro spark__get_columns_in_relation(relation) -%}
{% call statement('get_columns_in_relation', fetch_result=True) %}
{% macro spark__get_columns_in_relation_raw(relation) -%}
{% call statement('get_columns_in_relation_raw', fetch_result=True) %}
describe extended {{ relation.include(schema=(schema is not none)) }}
{% endcall %}
{% do return(load_result('get_columns_in_relation').table) %}
{% do return(load_result('get_columns_in_relation_raw').table) %}
{% endmacro %}

{% macro spark__get_columns_in_relation(relation) -%}
{{ return(adapter.get_columns_in_relation(relation)) }}
{% endmacro %}

{% macro spark__list_relations_without_caching(relation) %}
Expand Down

0 comments on commit 98ea5e3

Please sign in to comment.