-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
use create table as
syntax on BigQuery
#717
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
{% macro partition_by(raw_partition_by) %} | ||
{%- if raw_partition_by is none -%} | ||
{{ return('') }} | ||
{% endif %} | ||
|
||
{% set partition_by_clause %} | ||
partition by {{ raw_partition_by }} | ||
{%- endset -%} | ||
|
||
{{ return(partition_by_clause) }} | ||
{%- endmacro -%} | ||
|
||
{% macro bigquery__create_table_as(temporary, identifier, sql) -%} | ||
{{ adapter.execute_model({"name": identifier, "injected_sql": sql, "schema": schema}, 'table') }} | ||
{%- set raw_partition_by = config.get('partition_by', none) -%} | ||
|
||
create or replace table `{{ schema }}`.`{{ identifier }}` | ||
{{ partition_by(raw_partition_by) }} | ||
as ( | ||
{{ sql }} | ||
); | ||
{% endmacro %} | ||
|
||
{% macro bigquery__create_view_as(identifier, sql) -%} | ||
{{ adapter.execute_model({"name": identifier, "injected_sql": sql, "schema": schema}, 'view') }} | ||
create or replace view `{{ schema }}`.`{{ identifier }}` as ( | ||
{{ sql }} | ||
); | ||
{% endmacro %} |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
34 changes: 34 additions & 0 deletions
34
dbt/include/global_project/macros/materializations/view/bigquery_view.sql
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,34 @@ | ||
|
||
{% materialization view, adapter='bigquery' -%} | ||
|
||
{%- set identifier = model['name'] -%} | ||
{%- set non_destructive_mode = (flags.NON_DESTRUCTIVE == True) -%} | ||
{%- set existing = adapter.query_for_existing(schema) -%} | ||
{%- set existing_type = existing.get(identifier) -%} | ||
|
||
{%- if existing_type is not none -%} | ||
{%- if existing_type == 'table' and not flags.FULL_REFRESH -%} | ||
{# this is only intended for date partitioned tables, but we cant see that field in the context #} | ||
{% set error_message -%} | ||
Trying to create model '{{ identifier }}' as a view, but it already exists as a table. | ||
Either drop the '{{ schema }}.{{ identifier }}' table manually, or use --full-refresh | ||
{%- endset %} | ||
{{ exceptions.raise_compiler_error(error_message) }} | ||
{%- endif -%} | ||
|
||
{{ adapter.drop(schema, identifier, existing_type) }} | ||
{%- endif -%} | ||
|
||
-- build model | ||
{% if existing_type == 'view' and non_destructive_mode -%} | ||
{% call noop_statement('main', status="PASS", res=None) -%} | ||
-- Not running : non-destructive mode | ||
{{ sql }} | ||
{%- endcall %} | ||
{%- else -%} | ||
{% call statement('main') -%} | ||
{{ create_view_as(identifier, sql) }} | ||
{%- endcall %} | ||
{%- endif %} | ||
|
||
{%- endmaterialization %} |
File renamed without changes.
20 changes: 0 additions & 20 deletions
20
dbt/include/global_project/macros/materializations/wrapper.sql
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nice