Skip to content

Commit

Permalink
fix instrumentation artifacts (#87)
Browse files Browse the repository at this point in the history
convert sql to sql_type param for instrumentation
fix a quoting issue with show grants
  • Loading branch information
tovganesh authored Sep 17, 2022
1 parent e5d0dfc commit 3b436dc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions dbt/adapters/impala/cloudera_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ def _merge_keys(source_dict, dest_dict):
dest_dict[key] = value
return dest_dict

def _get_sql_type(sql):
if not sql:
return ""

words = sql.split("*/")

if len(words) > 1:
sql_words = words[1].strip().split()
else:
sql_words = words[0].strip().split()

sql_type = " ".join(sql_words[:min(2, len(sql_words))]).lower()

return sql_type

def fix_tracking_payload(given_payload):
"""
Expand All @@ -106,6 +120,11 @@ def fix_tracking_payload(given_payload):
# merge valid keys from source to desired payload first
desired_payload = _merge_keys(given_payload, desired_payload)

# handle sql redaction - convert to sql type from full sql statement
if "sql" in desired_payload:
desired_payload["sql_type"] = _get_sql_type(desired_payload["sql"])
del desired_payload["sql"]

desired_keys = [
"auth",
"connection_state",
Expand All @@ -115,13 +134,11 @@ def fix_tracking_payload(given_payload):
"model_type",
"permissions",
"profile_name",
"sql",
"sql_type"
]

given_keys = given_payload.keys()

for key in desired_keys:
if key not in given_keys:
if key not in desired_payload:
# indicate that the key doesn't have valid data for the event
desired_payload[key] = "N/A"

Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/impala/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def debug_query(self) -> None:
username = self.config.credentials.username
# for impala schema/database name are the same
database = self.config.credentials.schema
sql_query = "show grant user " + username + " on database " + database
sql_query = "show grant user `" + username + "` on database " + database
response, table = self.execute(sql_query, True, True)
permissions_object = []
json_funcs = [c.jsonify for c in table.column_types]
Expand Down

0 comments on commit 3b436dc

Please sign in to comment.