Skip to content

Commit

Permalink
fix alias with multiple internal underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
wongjingping authored and rishsriv committed Jul 10, 2024
1 parent b2ab505 commit 63ca8a2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion defog_utils/utils_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,9 @@ def generate_aliases_dict(
if "_" in table_name:
# get the first letter of each subword delimited by "_"
table_name = table_name.strip("_")
alias = "".join([word[0] for word in table_name.split("_")]).lower()
# use re to split on one or more underscores
words = re.split(r"_+", table_name)
alias = "".join(word[0] for word in words).lower()
else:
# if camelCase, get the first letter of each subword
# otherwise defaults to just getting the 1st letter of the table_name
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,10 +624,10 @@ def test_generate_aliases_with_reserved_keywords(self):
self.assertEqual(result, expected_result)

def test_generate_aliases_with_dots_and_underscores(self):
table_names = ["db.schema.table1", "db.schema.table2", "db.schema.table3", "_uncompressed"]
table_names = ["db.schema.table1", "db.schema.table2", "db.schema.table3", "_uncompressed___long_name_"]
result = generate_aliases(table_names)
print(result)
expected_result = "-- db.schema.table1 AS t1\n-- db.schema.table2 AS t2\n-- db.schema.table3 AS t3\n-- _uncompressed AS u\n"
expected_result = "-- db.schema.table1 AS t1\n-- db.schema.table2 AS t2\n-- db.schema.table3 AS t3\n-- _uncompressed___long_name_ AS uln\n"
self.assertEqual(result, expected_result)


Expand Down

0 comments on commit 63ca8a2

Please sign in to comment.