Skip to content

Commit

Permalink
fix: populate database and schema values for bigquery in exported dbt…
Browse files Browse the repository at this point in the history
… sources (#543)

* Improve the specification of database and schema when the server type is BigQuery

* Make tables appear last

* update CHANGELOG

---------

Co-authored-by: Dr. Simon Harrer <[email protected]>
  • Loading branch information
syou6162 and simonharrer authored Dec 18, 2024
1 parent 8dc3b31 commit b6f45de
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Modify the arguments to narrow down the import target with `--dbt-model` (#532)
- SodaCL: Prevent `KeyError: 'fail'` from happening when testing with SodaCL
- fix: populate database and schema values for bigquery in exported dbt sources (#543)
- Fixing the options for importing and exporting to standard output (#544)

## [0.10.15] - 2024-10-26
Expand Down
11 changes: 8 additions & 3 deletions datacontract/export/dbt_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def to_dbt_staging_sql(data_contract_spec: DataContractSpecification, model_name


def to_dbt_sources_yaml(data_contract_spec: DataContractSpecification, server: str = None):
source = {"name": data_contract_spec.id, "tables": []}
source = {"name": data_contract_spec.id}
dbt = {
"version": 2,
"sources": [source],
Expand All @@ -72,9 +72,14 @@ def to_dbt_sources_yaml(data_contract_spec: DataContractSpecification, server: s
adapter_type = None
if found_server is not None:
adapter_type = found_server.type
source["database"] = found_server.database
source["schema"] = found_server.schema_
if adapter_type == "bigquery":
source["database"] = found_server.project
source["schema"] = found_server.dataset
else:
source["database"] = found_server.database
source["schema"] = found_server.schema_

source["tables"] = []
for model_key, model_value in data_contract_spec.models.items():
dbt_model = _to_dbt_source_table(model_key, model_value, adapter_type)
source["tables"].append(dbt_model)
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/dbt/export/datacontract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ servers:
type: bigquery
environment: production
account: my-account
database: my-database
schema: my-schema
project: my-database
dataset: my-schema
roles:
- name: analyst_us
description: Access to the data for US region
Expand Down

0 comments on commit b6f45de

Please sign in to comment.