diff --git a/dbt/adapters/bigquery.py b/dbt/adapters/bigquery.py index c981bc4aa39..5ca7aeb27df 100644 --- a/dbt/adapters/bigquery.py +++ b/dbt/adapters/bigquery.py @@ -514,12 +514,18 @@ def _agate_to_schema(cls, agate_table): def load_csv_rows(cls, profile, schema, table_name, agate_table): bq_schema = cls._agate_to_schema(agate_table) dataset = cls.get_dataset(profile, schema, None) - table = dataset.table(table_name, schema=bq_schema) + table = dataset.table(table_name) conn = cls.get_connection(profile, None) client = conn.get('handle') + + load_config = google.cloud.bigquery.LoadJobConfig() + load_config.skip_leading_rows = 1 + load_config.schema = bq_schema + with open(agate_table.original_abspath, "rb") as f: - job = table.upload_from_file(f, "CSV", rewind=True, - client=client, skip_leading_rows=1) + job = client.load_table_from_file(f, table, rewind=True, + job_config=load_config) + with cls.exception_handler(profile, "LOAD TABLE"): cls.poll_until_job_completes(job, cls.get_timeout(conn)) diff --git a/test/integration/022_bigquery_test/data/data_seed.csv b/test/integration/022_bigquery_test/data/data_seed.csv new file mode 100644 index 00000000000..afd0a31efa5 --- /dev/null +++ b/test/integration/022_bigquery_test/data/data_seed.csv @@ -0,0 +1,5 @@ +id,dupe +1,a +2,a +3,a +4,a diff --git a/test/integration/022_bigquery_test/models/view.sql b/test/integration/022_bigquery_test/models/view.sql index 9dedb1d1cf3..e3f5d1184d5 100644 --- a/test/integration/022_bigquery_test/models/view.sql +++ b/test/integration/022_bigquery_test/models/view.sql @@ -4,10 +4,10 @@ ) }} -select 1 as id, current_date as updated_at, 'a' as dupe -union all -select 2 as id, current_date as updated_at, 'a' as dupe -union all -select 3 as id, current_date as updated_at, 'a' as dupe -union all -select 4 as id, current_date as updated_at, 'a' as dupe + +select + id, + current_date as updated_at, + dupe + +from {{ ref('data_seed') }} diff --git a/test/integration/022_bigquery_test/test_simple_bigquery_view.py b/test/integration/022_bigquery_test/test_simple_bigquery_view.py index c14b23c37c6..ae39658e75d 100644 --- a/test/integration/022_bigquery_test/test_simple_bigquery_view.py +++ b/test/integration/022_bigquery_test/test_simple_bigquery_view.py @@ -15,6 +15,7 @@ def models(self): @property def project_config(self): return { + 'data-paths': ['test/integration/022_bigquery_test/data'], 'macro-paths': ['test/integration/022_bigquery_test/macros'], } @@ -26,6 +27,7 @@ def profile_config(self): def test__bigquery_simple_run(self): self.use_profile('bigquery') self.use_default_project() + self.run_dbt(['seed']) self.run_dbt() # The 'dupe' model should fail, but all others should pass