diff --git a/dbt/adapters/snowflake/impl.py b/dbt/adapters/snowflake/impl.py index 7ccff9f8a..5194c017d 100644 --- a/dbt/adapters/snowflake/impl.py +++ b/dbt/adapters/snowflake/impl.py @@ -54,6 +54,7 @@ class SnowflakeConfig(AdapterConfig): # extended formats table_format: Optional[str] = None external_volume: Optional[str] = None + base_location: Optional[str] = None base_location_subpath: Optional[str] = None diff --git a/dbt/adapters/snowflake/relation.py b/dbt/adapters/snowflake/relation.py index 54db21924..d8233a6cf 100644 --- a/dbt/adapters/snowflake/relation.py +++ b/dbt/adapters/snowflake/relation.py @@ -204,7 +204,10 @@ def get_ddl_prefix_for_alter(self) -> str: return "" def get_iceberg_ddl_options(self, config: RelationConfig) -> str: - base_location: str = f"_dbt/{self.schema}/{self.name}" + if base_path := config.get("base_location"): + base_location: str = f"{base_path}" + else: + base_location: str = f"_dbt/{self.schema}/{self.name}" if subpath := config.get("base_location_subpath"): base_location += f"/{subpath}" diff --git a/tests/functional/iceberg/models.py b/tests/functional/iceberg/models.py index 6433f74bf..23f6a1c9f 100644 --- a/tests/functional/iceberg/models.py +++ b/tests/functional/iceberg/models.py @@ -23,6 +23,37 @@ select * from {{ ref('first_table') }} """ +_MODEL_BASIC_ICEBERG_MODEL_WITH_PATH = """ +{{ + config( + transient = "true", + materialized = "table", + cluster_by=['id'], + table_format="iceberg", + external_volume="s3_iceberg_snow", + base_location="base_path", + ) +}} + +select * from {{ ref('first_table') }} +""" + +_MODEL_BASIC_ICEBERG_MODEL_WITH_PATH_SUBPATH = """ +{{ + config( + transient = "true", + materialized = "table", + cluster_by=['id'], + table_format="iceberg", + external_volume="s3_iceberg_snow", + base_location="base_path", + base_location_subpath="subpath", + ) +}} + +select * from {{ ref('first_table') }} +""" + _MODEL_BASIC_DYNAMIC_TABLE_MODEL = """ {{ config( materialized='dynamic_table', @@ -36,6 +67,21 @@ select * from {{ ref('first_table') }} """ +_MODEL_BASIC_DYNAMIC_TABLE_MODEL_WITH_PATH = """ +{{ + config( + transient = "true", + materialized = "table", + cluster_by=['id'], + table_format="iceberg", + external_volume="s3_iceberg_snow", + base_location="base_path", + ) +}} + +select * from {{ ref('first_table') }} +""" + _MODEL_BASIC_DYNAMIC_TABLE_MODEL_WITH_SUBPATH = """ {{ config( materialized='dynamic_table', @@ -82,4 +128,4 @@ ) }} select 1 as id -""" +""" \ No newline at end of file diff --git a/tests/functional/iceberg/test_table_basic.py b/tests/functional/iceberg/test_table_basic.py index e835a5fce..7eaeb619c 100644 --- a/tests/functional/iceberg/test_table_basic.py +++ b/tests/functional/iceberg/test_table_basic.py @@ -7,7 +7,10 @@ from tests.functional.iceberg.models import ( _MODEL_BASIC_TABLE_MODEL, _MODEL_BASIC_ICEBERG_MODEL, + _MODEL_BASIC_ICEBERG_MODEL_WITH_PATH, + _MODEL_BASIC_ICEBERG_MODEL_WITH_PATH_SUBPATH, _MODEL_BASIC_DYNAMIC_TABLE_MODEL, + _MODEL_BASIC_DYNAMIC_TABLE_MODEL_WITH_PATH, _MODEL_BASIC_DYNAMIC_TABLE_MODEL_WITH_SUBPATH, _MODEL_BUILT_ON_ICEBERG_TABLE, _MODEL_TABLE_BEFORE_SWAP, @@ -26,9 +29,12 @@ def models(self): return { "first_table.sql": _MODEL_BASIC_TABLE_MODEL, "iceberg_table.sql": _MODEL_BASIC_ICEBERG_MODEL, + "iceberg_tableb.sql": _MODEL_BASIC_ICEBERG_MODEL_WITH_PATH, + "iceberg_tablec.sql": _MODEL_BASIC_ICEBERG_MODEL_WITH_PATH_SUBPATH, "table_built_on_iceberg_table.sql": _MODEL_BUILT_ON_ICEBERG_TABLE, "dynamic_table.sql": _MODEL_BASIC_DYNAMIC_TABLE_MODEL, - "dynamic_tableb.sql": _MODEL_BASIC_DYNAMIC_TABLE_MODEL_WITH_SUBPATH, + "dynamic_tableb.sql": _MODEL_BASIC_DYNAMIC_TABLE_MODEL_WITH_PATH, + "dynamic_tablec.sql": _MODEL_BASIC_DYNAMIC_TABLE_MODEL_WITH_SUBPATH, } def test_iceberg_tables_build_and_can_be_referred(self, project):