Skip to content

Commit

Permalink
Use contract column order in create table (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank authored Mar 20, 2023
1 parent 1cb3c7c commit ea08334
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230315-120554.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Modify create_table_as to use contract column order
time: 2023-03-15T12:05:54.52431-04:00
custom:
Author: gshank
Issue: "579"
3 changes: 2 additions & 1 deletion dbt/include/bigquery/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@

create or replace table {{ relation }}
{% if config.get('contract', False) %}
{{ get_assert_columns_equivalent(sql) }}
{{ get_assert_columns_equivalent(compiled_code) }}
{{ get_columns_spec_ddl() }}
{%- set compiled_code = get_select_subquery(compiled_code) %}
{% endif %}
{{ partition_by(partition_config) }}
{{ cluster_by(raw_cluster_by) }}
Expand Down
14 changes: 9 additions & 5 deletions tests/functional/adapter/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
create or replace table {0} (
id integer not null ,
color string ,
date_day date
date_day string
)
OPTIONS()
as (
select
1 as id,
'blue' as color,
cast('2019-01-01' as date) as date_day
select id,
color,
date_day from
(
select 'blue' as color,
1 as id,
'2019-01-01' as date_day
) as model_subq
);
"""

Expand Down

0 comments on commit ea08334

Please sign in to comment.