Skip to content

Commit

Permalink
Update standardize_grants_dict to handle potential case mismatches …
Browse files Browse the repository at this point in the history
…in grants table response

Match case to column names returned rather than hardcoding.
Fixes: dbt-labs#1086
  • Loading branch information
lamalex committed Aug 3, 2024
1 parent 34451f4 commit 281fd60
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions dbt/adapters/spark/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,25 @@ def python_submission_helpers(self) -> Dict[str, Type[PythonJobHelper]]:
"all_purpose_cluster": AllPurposeClusterPythonJobHelper,
}

def standardize_grants_dict(self, grants_table: agate.Table) -> dict:
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')
Expand Down

0 comments on commit 281fd60

Please sign in to comment.