Skip to content

Commit

Permalink
Merge pull request #10 from remoteoss/fix-column-name-renaming
Browse files Browse the repository at this point in the history
fix: add option to not replace chars
  • Loading branch information
eliyarson authored Aug 20, 2024
2 parents 6c7e28a + a9a9157 commit a558c8b
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions snowflake_utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@ class TableStructure(BaseModel):
columns: dict = [str, Column]

@property
def parsed_columns(self):
return ", ".join(
f'"{str.upper(k).strip().replace("-","_")}" {v.data_type}'
for k, v in self.columns.items()
)
def parsed_columns(self, replace_chars: bool = False) -> str:
if replace_chars:
return ", ".join(
f'"{str.upper(k).strip().replace("-","_")}" {v.data_type}'
for k, v in self.columns.items()
)
else:
return ", ".join(
f'"{str.upper(k).strip()}" {v.data_type}'
for k, v in self.columns.items()
)

def parse_from_json(self):
raise NotImplementedError("Not implemented yet")
Expand Down Expand Up @@ -406,8 +412,10 @@ def current_tags(self) -> dict[str, dict[str, str]]:
tags = defaultdict(dict)
with connect() as connection:
cursor = connection.cursor()
cursor.execute(f"""select lower(column_name) as column_name, lower(tag_name) as tag_name, tag_value
from table(information_schema.tag_references_all_columns('{self.fqn}', 'table'))""")
cursor.execute(
f"""select lower(column_name) as column_name, lower(tag_name) as tag_name, tag_value
from table(information_schema.tag_references_all_columns('{self.fqn}', 'table'))"""
)
for column_name, tag_name, tag_value in cursor.fetchall():
tags[column_name][tag_name] = tag_value
return tags
Expand Down

0 comments on commit a558c8b

Please sign in to comment.