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

update external table columns #252

Merged
merged 26 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 25 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ sources:
columns: &cols-of-the-people
- name: id
data_type: int64
description: id_of_the_person
- name: first_name
data_type: string
- name: last_name
Expand Down
3 changes: 3 additions & 0 deletions macros/common/stage_external_sources.sql
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@

{% endfor %}

{% set update_columns = dbt_external_tables.update_external_table_columns(node) %}
{{ update_columns }}

Comment on lines +69 to +71
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. is my understanding that this operation should happen after (and separated from) the actual staging of the tables?
  2. If update_external_table_columns returns an empty string (as is the case with the default__ version) then it is a no-op?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Yes, it just updates the schema with operations that can only be done via the API, see:
    https://github.com/dbt-labs/dbt-bigquery/blob/6c0afe4cfb69761dada5d16150fe632b8f72bf39/dbt/adapters/bigquery/impl.py#L609
    It adds descriptions and policyTags effectively creating the same behaviour as when you create a normal model.

  2. So I added the default__update_external_table_columns because I thought that this was how you should implement a macro that is BigQuery specific.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps i was looking for something more conventional (for this repo/ dbt macros) like

  1. fetching config,
  2. if config is not empty, then do the thingy
Suggested change
{% set update_columns = dbt_external_tables.update_external_table_columns(node) %}
{{ update_columns }}
{% set update_columns = dbt_external_tables.update_external_table_columns(node) %}
{%- if update_columns -%}
{{ update_columns }}

{% endfor %}

{% endmacro %}
7 changes: 7 additions & 0 deletions macros/common/update_external_table_columns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% macro update_external_table_columns(source_node) %}
{{ return(adapter.dispatch('update_external_table_columns', 'dbt_external_tables')(source_node)) }}
{% endmacro %}

{% macro default__update_external_table_columns(source_node) %}

{% endmacro %}
1 change: 0 additions & 1 deletion macros/plugins/bigquery/create_external_table.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% macro bigquery__create_external_table(source_node) %}

{%- set columns = source_node.columns.values() -%}
{%- set external = source_node.external -%}
{%- set partitions = external.partitions -%}
Expand Down
5 changes: 5 additions & 0 deletions macros/plugins/bigquery/update_external_table_columns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% macro bigquery__update_external_table_columns(source_node) %}
{%- set columns = source_node.columns -%}
{%- set relation = source(source_node.source_name, source_node.name) -%}
{%- do adapter.update_columns(relation, columns) -%}
{% endmacro %}
Loading