-
Notifications
You must be signed in to change notification settings - Fork 209
bigquery storage_uri updates #1129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
colin-rogers-dbt
merged 21 commits into
main
from
dbt-bigquery/use-external_volume-for-uri
Jun 3, 2025
Merged
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b8d8d81
add repro test
colin-rogers-dbt 2b95bdb
Revert "add repro test"
colin-rogers-dbt 56add79
add file_format as a top level integration config field and update st…
colin-rogers-dbt b318d0f
Merge branch 'main' into dbt-bigquery/use-external_volume-for-uri
colin-rogers-dbt 7a1b26a
add test case
colin-rogers-dbt d2c3754
add change log entry
colin-rogers-dbt d49f785
Merge remote-tracking branch 'fork/dbt-bigquery/use-external_volume-f…
colin-rogers-dbt cd7cc5f
update FakeCatalogIntegrationConfig
colin-rogers-dbt ae2edfa
add repro test
colin-rogers-dbt c9bde2e
Revert "add repro test"
colin-rogers-dbt 3277f7e
Merge branch 'main' into dbt-bigquery/use-external_volume-for-uri
colin-rogers-dbt 1820af5
swap generic for biglake_metastore
colin-rogers-dbt 756ce42
split out info schema catalog integration type for bigquery
colin-rogers-dbt ada14ee
add info schema
colin-rogers-dbt accb9c1
add base_location_subpath + unit tests
colin-rogers-dbt f43998e
merge main
colin-rogers-dbt 62c4d5a
add / update changelogs
colin-rogers-dbt 9e307be
move changelogs to the right directory
colin-rogers-dbt 647a91b
move changelogs to the right directory
colin-rogers-dbt 54e4abf
handle base_location_subpath being None
colin-rogers-dbt 08d36b6
update catalog defaults to info_schema
colin-rogers-dbt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
dbt-bigquery/.changes/unreleased/Features-20250529-092932.yaml
This file contains hidden or 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 @@ | ||
| kind: Features | ||
| body: generate storage_uri from external_volume, base_location_root and base_location_subpath | ||
| time: 2025-05-29T09:29:32.913024-07:00 | ||
| custom: | ||
| Author: colin-rogers-dbt | ||
| Issue: "1129" |
6 changes: 6 additions & 0 deletions
6
dbt-bigquery/.changes/unreleased/Under the Hood-20250603-114705.yaml
This file contains hidden or 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 @@ | ||
| kind: Under the Hood | ||
| body: populate file_format from top level integration config field | ||
| time: 2025-06-03T11:47:05.292026-07:00 | ||
| custom: | ||
| Author: colin-rogers-dbt | ||
| Issue: "1129" |
6 changes: 6 additions & 0 deletions
6
dbt-bigquery/.changes/unreleased/Under the Hood-20250603-114746.yaml
This file contains hidden or 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 @@ | ||
| kind: Under the Hood | ||
| body: Rename and separate out info schema and biglake catalog integrations | ||
| time: 2025-06-03T11:47:46.831408-07:00 | ||
| custom: | ||
| Author: colin-rogers-dbt | ||
| Issue: "1129" |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| from dbt.adapters.bigquery.catalogs._generic import ( | ||
| BigQueryCatalogIntegration, | ||
| BigQueryCatalogRelation, | ||
| ) | ||
| from dbt.adapters.bigquery.catalogs._biglake_metastore import BigLakeCatalogIntegration | ||
| from dbt.adapters.bigquery.catalogs._info_schema import BigQueryInfoSchemaCatalogIntegration | ||
| from dbt.adapters.bigquery.catalogs._relation import BigQueryCatalogRelation |
43 changes: 43 additions & 0 deletions
43
dbt-bigquery/src/dbt/adapters/bigquery/catalogs/_biglake_metastore.py
This file contains hidden or 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 @@ | ||
| from typing import Optional | ||
|
|
||
| from dbt.adapters.catalogs import CatalogIntegration | ||
| from dbt.adapters.contracts.relation import RelationConfig | ||
|
|
||
| from dbt.adapters.bigquery import constants | ||
| from dbt.adapters.bigquery.catalogs._relation import BigQueryCatalogRelation | ||
|
|
||
|
|
||
| class BigLakeCatalogIntegration(CatalogIntegration): | ||
| catalog_type = constants.BIGLAKE_CATALOG_TYPE | ||
| allows_writes = True | ||
|
|
||
| def build_relation(self, model: RelationConfig) -> BigQueryCatalogRelation: | ||
| """ | ||
| Args: | ||
| model: `config.model` (not `model`) from the jinja context | ||
| """ | ||
|
|
||
| return BigQueryCatalogRelation( | ||
| catalog_type=self.catalog_type, | ||
| catalog_name=self.catalog_name, | ||
| table_format=self.table_format, | ||
| file_format=self.file_format, | ||
| external_volume=self.external_volume, | ||
| storage_uri=self._calculate_storage_uri(model), | ||
| ) | ||
|
|
||
| def _calculate_storage_uri(self, model: RelationConfig) -> Optional[str]: | ||
| if not model.config: | ||
| return None | ||
|
|
||
| if model_storage_uri := model.config.get("storage_uri"): | ||
| return model_storage_uri | ||
|
|
||
| if not self.external_volume: | ||
| return None | ||
|
|
||
| prefix = model.config.get("base_location_root") or "_dbt" | ||
| storage_uri = f"{self.external_volume}/{prefix}/{model.schema}/{model.name}" | ||
| if suffix := model.config.get("base_location_subpath"): | ||
| storage_uri = f"{storage_uri}/{suffix}" | ||
| return storage_uri |
50 changes: 0 additions & 50 deletions
50
dbt-bigquery/src/dbt/adapters/bigquery/catalogs/_generic.py
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
dbt-bigquery/src/dbt/adapters/bigquery/catalogs/_info_schema.py
This file contains hidden or 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,25 @@ | ||
| from dbt.adapters.catalogs import CatalogIntegration | ||
| from dbt.adapters.contracts.relation import RelationConfig | ||
|
|
||
| from dbt.adapters.bigquery import constants | ||
| from dbt.adapters.bigquery.catalogs._relation import BigQueryCatalogRelation | ||
|
|
||
|
|
||
| class BigQueryInfoSchemaCatalogIntegration(CatalogIntegration): | ||
| catalog_type = constants.DEFAULT_INFO_SCHEMA_CATALOG.catalog_type | ||
| allows_writes = True | ||
|
|
||
| def build_relation(self, model: RelationConfig) -> BigQueryCatalogRelation: | ||
| """ | ||
| Args: | ||
| model: `config.model` (not `model`) from the jinja context | ||
| """ | ||
|
|
||
| return BigQueryCatalogRelation( | ||
| catalog_type=self.catalog_type, | ||
| catalog_name=self.catalog_name, | ||
| table_format=self.table_format, | ||
| file_format=self.file_format, | ||
| external_volume=self.external_volume, | ||
| storage_uri=None, | ||
| ) | ||
16 changes: 16 additions & 0 deletions
16
dbt-bigquery/src/dbt/adapters/bigquery/catalogs/_relation.py
This file contains hidden or 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,16 @@ | ||
| from dataclasses import dataclass | ||
| from typing import Optional | ||
|
|
||
| from dbt.adapters.catalogs import CatalogRelation | ||
|
|
||
| from dbt.adapters.bigquery import constants | ||
|
|
||
|
|
||
| @dataclass | ||
| class BigQueryCatalogRelation(CatalogRelation): | ||
| catalog_type: str = constants.BIGLAKE_CATALOG_TYPE | ||
colin-rogers-dbt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| catalog_name: Optional[str] = constants.DEFAULT_INFO_SCHEMA_CATALOG.name | ||
| table_format: Optional[str] = constants.INFO_SCHEMA_TABLE_FORMAT | ||
| file_format: Optional[str] = constants.INFO_SCHEMA_FILE_FORMAT | ||
| external_volume: Optional[str] = None | ||
| storage_uri: Optional[str] = None | ||
This file contains hidden or 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 hidden or 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 hidden or 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
67 changes: 67 additions & 0 deletions
67
dbt-bigquery/tests/functional/adapter/catalog_integrations/test_catalog_integration.py
This file contains hidden or 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,67 @@ | ||
| import os | ||
| from datetime import datetime as dt | ||
| import pytest | ||
| from dbt.tests.adapter.catalog_integrations.test_catalog_integration import ( | ||
| BaseCatalogIntegrationValidation, | ||
| ) | ||
| from dbt.tests.util import run_dbt | ||
|
|
||
| _BQ_BUCKET = os.getenv("BIGQUERY_TEST_ICEBERG_BUCKET") | ||
| _STATIC_URI = f"gs://{_BQ_BUCKET}/{str(dt.now())}" | ||
|
|
||
| MODEL__BASIC_ICEBERG_TABLE = """ | ||
| {{ config(materialized='table', catalog='basic_iceberg_catalog') }} | ||
| select 1 as id | ||
| """ | ||
|
|
||
| MODEL__SPECIFY_LOCATION_TABLE = """ | ||
| {{ config(materialized='table', catalog='basic_iceberg_catalog', | ||
| base_location_root='custom_location') }} | ||
| select 1 as id | ||
| """ | ||
|
|
||
| MODEL__SPECIFY_URI_TABLE = ( | ||
| """ | ||
| {{ config(materialized='table', catalog='basic_iceberg_catalog', | ||
| storage_uri='""" | ||
| + _STATIC_URI | ||
| + """') }} | ||
| select 1 as id | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| class TestGenericCatalogIntegration(BaseCatalogIntegrationValidation): | ||
|
|
||
| @pytest.fixture(scope="class") | ||
| def catalogs(self): | ||
| return { | ||
| "catalogs": [ | ||
| { | ||
| "name": "basic_iceberg_catalog", | ||
| "active_write_integration": "basic_iceberg_catalog_integration", | ||
| "write_integrations": [ | ||
| { | ||
| "name": "basic_iceberg_catalog_integration", | ||
| "catalog_type": "biglake_metastore", | ||
| "file_format": "parquet", | ||
| "table_format": "iceberg", | ||
| "external_volume": f"gs://{_BQ_BUCKET}", | ||
colin-rogers-dbt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| ], | ||
| }, | ||
| ] | ||
| } | ||
|
|
||
| @pytest.fixture(scope="class") | ||
| def models(self): | ||
| return { | ||
| "models": { | ||
| "basic_iceberg_table.sql": MODEL__BASIC_ICEBERG_TABLE, | ||
| "specify_location_table.sql": MODEL__SPECIFY_LOCATION_TABLE, | ||
| "specify_uri_table.sql": MODEL__SPECIFY_URI_TABLE, | ||
| } | ||
| } | ||
|
|
||
| def test_basic_iceberg_catalog_integration(self, project): | ||
| run_dbt(["run"]) | ||
This file contains hidden or 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,70 @@ | ||
| import unittest | ||
| from types import SimpleNamespace | ||
| from unittest.mock import MagicMock | ||
| from dbt.adapters.bigquery.catalogs import BigLakeCatalogIntegration | ||
| from dbt.adapters.contracts.relation import RelationConfig | ||
|
|
||
|
|
||
| class TestBigLakeCatalogIntegration(unittest.TestCase): | ||
| def setUp(self): | ||
| self.integration = BigLakeCatalogIntegration( | ||
| config=SimpleNamespace( | ||
| name="test_biglake_catalog_integration", | ||
| external_volume="test_external_volume", | ||
| catalog_type="biglake", | ||
| catalog_name="test_catalog_name", | ||
| table_format="test_table_format", | ||
| file_format="test_file_format", | ||
| ) | ||
| ) | ||
| self.integration.external_volume = "test_external_volume" | ||
|
|
||
| def test_storage_uri_no_inputs(self): | ||
| model = MagicMock(spec=RelationConfig) | ||
| model.config = {"has": "a_value"} | ||
| model.schema = "test_schema" | ||
| model.name = "test_model_name" | ||
|
|
||
| expected_uri = "test_external_volume/_dbt/test_schema/test_model_name" | ||
| result = self.integration._calculate_storage_uri(model) | ||
| self.assertEqual(expected_uri, result) | ||
|
|
||
| def test_storage_uri_base_location_root(self): | ||
| model = MagicMock(spec=RelationConfig) | ||
| model.config = {"base_location_root": "foo"} | ||
| model.schema = "test_schema" | ||
| model.name = "test_model_name" | ||
|
|
||
| expected_uri = "test_external_volume/foo/test_schema/test_model_name" | ||
| result = self.integration._calculate_storage_uri(model) | ||
| self.assertEqual(expected_uri, result) | ||
|
|
||
| def test_storage_uri_base_location_subpath(self): | ||
| model = MagicMock(spec=RelationConfig) | ||
| model.config = {"base_location_subpath": "bar"} | ||
| model.schema = "test_schema" | ||
| model.name = "test_model_name" | ||
|
|
||
| expected_uri = "test_external_volume/_dbt/test_schema/test_model_name/bar" | ||
| result = self.integration._calculate_storage_uri(model) | ||
| self.assertEqual(expected_uri, result) | ||
|
|
||
| def test_storage_uri_base_location_root_and_subpath(self): | ||
| model = MagicMock(spec=RelationConfig) | ||
| model.config = {"base_location_root": "foo", "base_location_subpath": "bar"} | ||
| model.schema = "test_schema" | ||
| model.name = "test_model_name" | ||
|
|
||
| expected_uri = "test_external_volume/foo/test_schema/test_model_name/bar" | ||
| result = self.integration._calculate_storage_uri(model) | ||
| self.assertEqual(expected_uri, result) | ||
|
|
||
| def test_storage_uri_from_model_config(self): | ||
| model = MagicMock(spec=RelationConfig) | ||
| model.config = {"storage_uri": "custom_storage_uri"} | ||
| model.schema = "test_schema" | ||
| model.name = "test_model_name" | ||
|
|
||
| expected_uri = "custom_storage_uri" | ||
| result = self.integration._calculate_storage_uri(model) | ||
| self.assertEqual(expected_uri, result) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.