-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 #2547 from azhard/bigquery-alter-column-type
Add support for altering BigQuery column types
- Loading branch information
Showing
6 changed files
with
80 additions
and
2 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
10 changes: 10 additions & 0 deletions
10
test/integration/056_column_type_tests/bq_models_alter_type/altered_schema.yml
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,10 @@ | ||
version: 2 | ||
models: | ||
- name: model | ||
tests: | ||
- is_type: | ||
column_map: | ||
int64_col: ['string', 'not number'] | ||
float64_col: ['float', 'number'] | ||
numeric_col: ['numeric', 'number'] | ||
string_col: ['string', 'not number'] |
6 changes: 6 additions & 0 deletions
6
test/integration/056_column_type_tests/bq_models_alter_type/model.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,6 @@ | ||
{{ config(materialized='table') }} | ||
select | ||
CAST(1 as int64) as int64_col, | ||
CAST(2.0 as float64) as float64_col, | ||
CAST(3.0 as numeric) as numeric_col, | ||
CAST('3' as string) as string_col, |
5 changes: 5 additions & 0 deletions
5
test/integration/056_column_type_tests/macros/test_alter_column_type.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,5 @@ | ||
-- Macro to alter a column type | ||
{% macro test_alter_column_type(model_name, column_name, new_column_type) %} | ||
{% set relation = ref(model_name) %} | ||
{{ alter_column_type(relation, column_name, new_column_type) }} | ||
{% endmacro %} |
28 changes: 28 additions & 0 deletions
28
test/integration/056_column_type_tests/test_alter_column_types.py
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,28 @@ | ||
from test.integration.base import DBTIntegrationTest, use_profile | ||
import yaml | ||
|
||
|
||
class TestAlterColumnTypes(DBTIntegrationTest): | ||
@property | ||
def schema(self): | ||
return '056_alter_column_types' | ||
|
||
def run_and_alter_and_test(self, alter_column_type_args): | ||
self.assertEqual(len(self.run_dbt(['run'])), 1) | ||
self.run_dbt(['run-operation', 'test_alter_column_type', '--args', alter_column_type_args]) | ||
self.assertEqual(len(self.run_dbt(['test'])), 1) | ||
|
||
|
||
class TestBigQueryAlterColumnTypes(TestAlterColumnTypes): | ||
@property | ||
def models(self): | ||
return 'bq_models_alter_type' | ||
|
||
@use_profile('bigquery') | ||
def test_bigquery_column_types(self): | ||
alter_column_type_args = yaml.safe_dump({ | ||
'model_name': 'model', | ||
'column_name': 'int64_col', | ||
'new_column_type': 'string' | ||
}) | ||
self.run_and_alter_and_test(alter_column_type_args) |