|
3 | 3 | import pytest |
4 | 4 | from dbt.exceptions import DbtRuntimeError |
5 | 5 |
|
| 6 | +from dbt.adapters.databricks import constants |
| 7 | +from dbt.adapters.databricks.global_state import GlobalState |
6 | 8 | from dbt.adapters.databricks.relation_configs.tblproperties import ( |
7 | 9 | TblPropertiesConfig, |
8 | 10 | TblPropertiesProcessor, |
@@ -56,3 +58,42 @@ def test_from_model_node__with_incorrect_tblproperties(self): |
56 | 58 | match="tblproperties must be a dictionary", |
57 | 59 | ): |
58 | 60 | _ = TblPropertiesProcessor.from_relation_config(model) |
| 61 | + |
| 62 | + def test_from_model_node__with_uniform_iceberg_adds_properties(self): |
| 63 | + GlobalState.set_use_managed_iceberg(False) |
| 64 | + model = Mock() |
| 65 | + model.config.extra = { |
| 66 | + "table_format": constants.ICEBERG_TABLE_FORMAT, |
| 67 | + "tblproperties": {"custom_prop": "value"}, |
| 68 | + } |
| 69 | + spec = TblPropertiesProcessor.from_relation_config(model) |
| 70 | + # Should have both custom property AND UniForm properties |
| 71 | + assert spec == TblPropertiesConfig( |
| 72 | + tblproperties={ |
| 73 | + "custom_prop": "value", |
| 74 | + "delta.enableIcebergCompatV2": "true", |
| 75 | + "delta.universalFormat.enabledFormats": constants.ICEBERG_TABLE_FORMAT, |
| 76 | + } |
| 77 | + ) |
| 78 | + |
| 79 | + def test_from_model_node__with_managed_iceberg_no_uniform_properties(self): |
| 80 | + GlobalState.set_use_managed_iceberg(True) |
| 81 | + model = Mock() |
| 82 | + model.config.extra = { |
| 83 | + "table_format": constants.ICEBERG_TABLE_FORMAT, |
| 84 | + "tblproperties": {"custom_prop": "value"}, |
| 85 | + } |
| 86 | + spec = TblPropertiesProcessor.from_relation_config(model) |
| 87 | + # Should only have the custom property, NOT the UniForm properties |
| 88 | + assert spec == TblPropertiesConfig(tblproperties={"custom_prop": "value"}) |
| 89 | + |
| 90 | + def test_from_model_node__with_iceberg_no_flag_no_properties(self): |
| 91 | + GlobalState.set_use_managed_iceberg(None) |
| 92 | + model = Mock() |
| 93 | + model.config.extra = { |
| 94 | + "table_format": constants.ICEBERG_TABLE_FORMAT, |
| 95 | + "tblproperties": {}, |
| 96 | + } |
| 97 | + spec = TblPropertiesProcessor.from_relation_config(model) |
| 98 | + # Should not have UniForm properties without explicit use_managed_iceberg=False |
| 99 | + assert spec == TblPropertiesConfig(tblproperties={}) |
0 commit comments