From c1bae974c2a83d13b312f0dcba4373699cb1573e Mon Sep 17 00:00:00 2001 From: Alex Launi Date: Sat, 3 Aug 2024 12:10:09 -0400 Subject: [PATCH 1/2] Update `standardize_grants_dict` to handle potential case mismatches in grants table response Match case to column names returned rather than hardcoding. Fixes: #1086 --- dbt/adapters/spark/impl.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/dbt/adapters/spark/impl.py b/dbt/adapters/spark/impl.py index d33ebde20..f0f2312c3 100644 --- a/dbt/adapters/spark/impl.py +++ b/dbt/adapters/spark/impl.py @@ -496,11 +496,24 @@ def python_submission_helpers(self) -> Dict[str, Type[PythonJobHelper]]: } def standardize_grants_dict(self, grants_table: "agate.Table") -> dict: + def get_cased_column_name_for_column(tuple_data: Tuple[str], column_name: str) -> str: + for item in tuple_data: + if item.lower() == column_name.lower(): + return item + raise DbtRuntimeError( + f'Column "{column_name}" not found in grants table columns `{', '.join(grants_table.column_names)}`.' + ) + + column_names = grants_table.column_names + principal_column_name = get_cased_column_name_for_column(column_names, "Principal") + privilege_column_name = get_cased_column_name_for_column(column_names, "ActionType") + object_type_column_name = get_cased_column_name_for_column(column_names, "ObjectType") + grants_dict: Dict[str, List[str]] = {} for row in grants_table: - grantee = row["Principal"] - privilege = row["ActionType"] - object_type = row["ObjectType"] + grantee = row[principal_column_name] + privilege = row[privilege_column_name] + object_type = row[object_type_column_name] # we only want to consider grants on this object # (view or table both appear as 'TABLE') From b501e65924f333f95e45ccfa8e71b257800d2f79 Mon Sep 17 00:00:00 2001 From: Alex Launi Date: Sat, 3 Aug 2024 13:25:51 -0400 Subject: [PATCH 2/2] fix string interpolation syntax error --- dbt/adapters/spark/impl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt/adapters/spark/impl.py b/dbt/adapters/spark/impl.py index f0f2312c3..088f69a5b 100644 --- a/dbt/adapters/spark/impl.py +++ b/dbt/adapters/spark/impl.py @@ -501,7 +501,7 @@ def get_cased_column_name_for_column(tuple_data: Tuple[str], column_name: str) - if item.lower() == column_name.lower(): return item raise DbtRuntimeError( - f'Column "{column_name}" not found in grants table columns `{', '.join(grants_table.column_names)}`.' + f'Column "{column_name}" not found in grants table columns `{", ".join(grants_table.column_names)}`.' ) column_names = grants_table.column_names