-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2448 from fishtown-analytics/fix/bigquery-create-…
…schema-macro Fix create_schema macro on bigquery (#2445)
- Loading branch information
Showing
6 changed files
with
93 additions
and
4 deletions.
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
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
43 changes: 43 additions & 0 deletions
43
test/integration/022_bigquery_test/macros/wrapped_macros.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,43 @@ | ||
{% macro my_create_schema(db_name, schema_name) %} | ||
{% if not execute %} | ||
{% do return(None) %} | ||
{% endif %} | ||
{% set relation = api.Relation.create(database=db_name, schema=schema_name).without_identifier() %} | ||
{% do create_schema(relation) %} | ||
{% endmacro %} | ||
|
||
{% macro my_drop_schema(db_name, schema_name) %} | ||
{% if not execute %} | ||
{% do return(None) %} | ||
{% endif %} | ||
{% set relation = api.Relation.create(database=db_name, schema=schema_name).without_identifier() %} | ||
{% do drop_schema(relation) %} | ||
{% endmacro %} | ||
|
||
|
||
{% macro my_create_table_as(db_name, schema_name, table_name) %} | ||
{% if not execute %} | ||
{% do return(None) %} | ||
{% endif %} | ||
{% set relation = api.Relation.create(database=db_name, schema=schema_name, identifier=table_name) %} | ||
{% do run_query(create_table_as(false, relation, 'select 1 as id')) %} | ||
{% endmacro %} | ||
|
||
|
||
{% macro ensure_one_relation_in(db_name, schema_name) %} | ||
{% if not execute %} | ||
{% do return(None) %} | ||
{% endif %} | ||
{% set relation = api.Relation.create(database=db_name, schema=schema_name).without_identifier() %} | ||
{% set results = list_relations_without_caching(relation) %} | ||
{% set rlen = (results | length) %} | ||
{% if rlen != 1 %} | ||
{% do exceptions.raise_compiler_error('Incorect number of results (expected 1): ' ~ rlen) %} | ||
{% endif %} | ||
{% set result = results[0] %} | ||
{% set columns = get_columns_in_relation(result) %} | ||
{% set clen = (columns | length) %} | ||
{% if clen != 1 %} | ||
{% do exceptions.raise_compiler_error('Incorrect number of columns (expected 1): ' ~ clen) %} | ||
{% endif %} | ||
{% endmacro %} |
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