Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Fixes

- Handle `SHOW GRANTS` result columns case-insensitively so grant reconciliation does not crash when connectors return lowercase names (thanks @TangoEnSkai!) ([#1650](https://github.com/databricks/dbt-databricks/pull/1650) resolves [#782](https://github.com/databricks/dbt-databricks/issues/782))
- Replace an existing table or view with a metric view using backup-and-create instead of `CREATE OR REPLACE VIEW ... WITH METRICS` ([#1640](https://github.com/databricks/dbt-databricks/pull/1640) resolves [#1639](https://github.com/databricks/dbt-databricks/issues/1639))
- Interpolate lazily-formatted `databricks.sql` log records when mirroring them into dbt logs ([#1642](https://github.com/databricks/dbt-databricks/pull/1642) resolves [#1637](https://github.com/databricks/dbt-databricks/issues/1637))

Expand Down
14 changes: 14 additions & 0 deletions dbt/adapters/databricks/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,20 @@ def _has_dbr_capability_parse(self, capability_name: str) -> bool:
def _v2_to_v1_type(self, catalog_type: str) -> str:
return self._V2_TO_V1_TYPE.get(catalog_type, catalog_type)

def standardize_grants_dict(self, grants_table: "Table") -> dict[str, list[str]]:
column_names = {name.lower(): name for name in grants_table.column_names}
grants_dict: dict[str, list[str]] = {}

for row in grants_table:
grantee = row[column_names["principal"]]
privilege = row[column_names["actiontype"]]
object_type = row[column_names["objecttype"]]

if object_type == "TABLE" and privilege != "OWN":
grants_dict.setdefault(privilege, []).append(grantee)

return grants_dict

@property
def _behavior_flags(self) -> list[BehaviorFlag]:
return [
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,30 @@ def _stub_spog_probe(self):
):
yield

@pytest.mark.parametrize(
"column_names",
[
["Principal", "ActionType", "ObjectType", "ObjectKey"],
["principal", "actiontype", "objecttype", "objectkey"],
["principal", "actionType", "objectType", "objectKey"],
],
)
def test_standardize_grants_dict_ignores_column_name_case(self, column_names):
grants_table = agate.Table(
[
["analysts", "SELECT", "TABLE", "catalog.schema.model"],
["engineers", "SELECT", "TABLE", "catalog.schema.model"],
["owner", "OWN", "TABLE", "catalog.schema.model"],
["catalog_user", "USE CATALOG", "CATALOG", "catalog"],
],
column_names=column_names,
)
adapter = DatabricksAdapter(self._get_config(), get_context("spawn"))

assert adapter.standardize_grants_dict(grants_table) == {
"SELECT": ["analysts", "engineers"]
}

def test_two_catalog_settings(self):
with pytest.raises(DbtConfigError) as excinfo:
self._get_config(
Expand Down