-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Custom Iceberg
base_location_root
(#1289)
* update relation & add tests * switch if/else pattern * add change log * add test for dynamic table with path and subpath * modify base_location config * update to base_location_root, include schema and table name in path * resolve linting error (f-string nested double quotes) * resolve linting error (move to new line) * add unit tests & make final edits to functional tests * lint unit test * update changie * update dt test cases for iceberg to be dynamic --------- Co-authored-by: Colin Rogers <111200756+colin-rogers-dbt@users.noreply.github.com>
- Loading branch information
1 parent
b687ac4
commit 5d935ee
Showing
6 changed files
with
163 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Added support for custom iceberg base_location_root | ||
time: 2025-01-13T13:34:14.326047-08:00 | ||
custom: | ||
Author: LProcopi15 | ||
Issue: "1284" |
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
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
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,79 @@ | ||
import pytest | ||
from dbt.adapters.snowflake.relation import SnowflakeRelation | ||
|
||
|
||
@pytest.fixture | ||
def iceberg_config() -> dict: | ||
"""Fixture providing standard Iceberg configuration.""" | ||
return { | ||
"schema": "my_schema", | ||
"identifier": "my_table", | ||
"external_volume": "s3_iceberg_snow", | ||
"base_location_root": "root_path", | ||
"base_location_subpath": "subpath", | ||
} | ||
|
||
|
||
def get_actual_base_location(config: dict[str, str]) -> str: | ||
"""Get the actual base location from the configuration by parsing the DDL predicates.""" | ||
|
||
relation = SnowflakeRelation.create( | ||
schema=config["schema"], | ||
identifier=config["identifier"], | ||
) | ||
|
||
actual_ddl_predicates = relation.get_iceberg_ddl_options(config).strip() | ||
actual_base_location = actual_ddl_predicates.split("base_location = ")[1] | ||
|
||
return actual_base_location | ||
|
||
|
||
def test_iceberg_path_and_subpath(iceberg_config: dict[str, str]): | ||
"""Test when base_location_root and base_location_subpath are provided""" | ||
expected_base_location = ( | ||
f"'{iceberg_config['base_location_root']}/" | ||
f"{iceberg_config['schema']}/" | ||
f"{iceberg_config['identifier']}/" | ||
f"{iceberg_config['base_location_subpath']}'" | ||
).strip() | ||
|
||
assert get_actual_base_location(iceberg_config) == expected_base_location | ||
|
||
|
||
def test_iceberg_only_subpath(iceberg_config: dict[str, str]): | ||
"""Test when only base_location_subpath is provided""" | ||
del iceberg_config["base_location_root"] | ||
|
||
expected_base_location = ( | ||
f"'_dbt/" | ||
f"{iceberg_config['schema']}/" | ||
f"{iceberg_config['identifier']}/" | ||
f"{iceberg_config['base_location_subpath']}'" | ||
).strip() | ||
|
||
assert get_actual_base_location(iceberg_config) == expected_base_location | ||
|
||
|
||
def test_iceberg_only_path(iceberg_config: dict[str, str]): | ||
"""Test when only base_location_root is provided""" | ||
del iceberg_config["base_location_subpath"] | ||
|
||
expected_base_location = ( | ||
f"'{iceberg_config['base_location_root']}/" | ||
f"{iceberg_config['schema']}/" | ||
f"{iceberg_config['identifier']}'" | ||
).strip() | ||
|
||
assert get_actual_base_location(iceberg_config) == expected_base_location | ||
|
||
|
||
def test_iceberg_no_path(iceberg_config: dict[str, str]): | ||
"""Test when no base_location_root or is base_location_subpath provided""" | ||
del iceberg_config["base_location_root"] | ||
del iceberg_config["base_location_subpath"] | ||
|
||
expected_base_location = ( | ||
f"'_dbt/" f"{iceberg_config['schema']}/" f"{iceberg_config['identifier']}'" | ||
).strip() | ||
|
||
assert get_actual_base_location(iceberg_config) == expected_base_location |