Skip to content

Commit

Permalink
style: align with project code style
Browse files Browse the repository at this point in the history
and remove types
  • Loading branch information
roslovets committed Jun 30, 2023
1 parent 70058a3 commit 0fe5485
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions dbt/adapters/athena/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,19 +645,19 @@ def persist_docs_to_glue(
glue_client = client.session.client("glue", region_name=client.region_name, config=get_boto3_config())

# By default, there is no need to update Glue Table
need_udpate_table: bool = False
need_udpate_table = False
# Get Table from Glue
table: Dict[str, Any] = glue_client.get_table(DatabaseName=relation.schema, Name=relation.name)["Table"]
table = glue_client.get_table(DatabaseName=relation.schema, Name=relation.name)["Table"]
# Prepare new version of Glue Table picking up significant fields
updated_table: Dict[str, Any] = self._get_table_input(table)
updated_table = self._get_table_input(table)
# Update table description
if persist_relation_docs:
# Prepare dbt description
clean_table_description: str = clean_sql_comment(model["description"])
clean_table_description = clean_sql_comment(model["description"])
# Get current description from Glue
current_table_description: str = table.get("Description", "")
current_table_description = table.get("Description", "")
# Get current description parameter from Glue
current_table_comment: str = table["Parameters"].get("comment", "")
current_table_comment = table["Parameters"].get("comment", "")
# Update description if it's different
if clean_table_description != current_table_description or clean_table_description != current_table_comment:
updated_table["Description"] = clean_table_description
Expand All @@ -667,16 +667,15 @@ def persist_docs_to_glue(
# Update column comments
if persist_column_docs:
# Process every column
col_obj: Dict[str, Any]
for col_obj in updated_table["StorageDescriptor"]["Columns"]:
# Get column description from dbt
col_name: str = col_obj["Name"]
col_comment: Optional[str] = model["columns"].get(col_name, {}).get("description", None)
col_name = col_obj["Name"]
col_comment = model["columns"].get(col_name, {}).get("description", None)
if col_comment is not None:
# Get current column comment from Glue
current_col_comment: str = col_obj.get("Comment", "")
current_col_comment = col_obj.get("Comment", "")
# Prepare column description from dbt
clean_col_comment: str = clean_sql_comment(col_comment)
clean_col_comment = clean_sql_comment(col_comment)
# Update column description if it's different
if current_col_comment != clean_col_comment:
col_obj["Comment"] = clean_col_comment
Expand Down Expand Up @@ -856,15 +855,15 @@ def is_list(self, value: Any) -> bool:
return isinstance(value, list)

@staticmethod
def _get_table_input(table: Dict[str, Any]) -> Dict[str, Any]:
def _get_table_input(table):
"""
Prepare Glue Table dictionary to be a table_input argument of update_table() method.
This is needed because update_table() does not accept some read-only fields of table dictionary
returned by get_table() method.
This code was derived from awswrangler==3.2.1.
"""
table_input: Dict[str, Any] = {}
table_input = {}
for k, v in table.items():
if k in [
"Name",
Expand Down
2 changes: 1 addition & 1 deletion dbt/include/athena/macros/adapters/persist_docs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% set persist_relation_docs = for_relation and config.persist_relation_docs() and model.description %}
{% set persist_column_docs = for_columns and config.persist_column_docs() and model.columns %}
{% set skip_archive = not is_incremental() %}
{% if (persist_relation_docs or persist_column_docs) %}
{% if persist_relation_docs or persist_column_docs %}
{% do adapter.persist_docs_to_glue(relation,
model,
persist_relation_docs,
Expand Down

0 comments on commit 0fe5485

Please sign in to comment.