Skip to content

Commit

Permalink
lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-cnivera committed Oct 23, 2024
1 parent 50595e5 commit 6af14b2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion semantic_model_generator/data_processing/cte_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ def remove_ltable_cte(sql_w_ltable_cte: str, table_names: list[str]) -> str:
if not is_logical_table(with_.expressions[0].alias):
raise ValueError("Analyst queries must contain the logical CTE.")

table_names_lower = [table_name.lower() for table_name in table_names]
# Iterate through all CTEs. If a CTE starts with the logical table prefix and matches a table name, remove it.
non_logical_cte = [
cte
for cte in with_.expressions
if not is_logical_table(cte.alias)
or cte.alias.replace(_LOGICAL_TABLE_PREFIX, "") not in table_names
or cte.alias.replace(_LOGICAL_TABLE_PREFIX, "").lower() not in table_names_lower
]

# Replace the original expressions list with the filtered list
Expand Down
2 changes: 1 addition & 1 deletion semantic_model_generator/data_processing/cte_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_removes_logical_table_cte(self) -> None:
Testing that we remove logical table CTEs corresponding to existing table names.
"""
query = "WITH __logical_table AS (SELECT * FROM table1) SELECT * FROM __logical_table"
table_names = ["logical_table"]
table_names = ["LOGICAL_TABLE"]
expected_query = "SELECT * FROM __logical_table"

actual_output = remove_ltable_cte(query, table_names=table_names)
Expand Down

0 comments on commit 6af14b2

Please sign in to comment.