Skip to content

Commit

Permalink
black goinception
Browse files Browse the repository at this point in the history
  • Loading branch information
woshiyanghai committed Jan 17, 2025
1 parent fd4b738 commit fed73cc
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions sql/engines/goinception.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ def get_table_ref(query_tree, db_name=None):
# 首先识别所有的临时表名
if "With" in query_tree:
logger.warning(query_tree["With"])
with_definitions = query_tree["With"].get("CTEs", []) # 假设临时表定义在CTEs键下
with_definitions = query_tree["With"].get(
"CTEs", []
) # 假设临时表定义在CTEs键下
for definition in with_definitions:
temporary_tables.add(definition["Name"]["O"]) # 获取临时表的名称

Expand All @@ -335,11 +337,15 @@ def get_table_ref(query_tree, db_name=None):
snodes = tree.find_max_tree("Source")
if snodes:
for snode in snodes:
schema_name = snode["Source"].get("Schema", {}).get("O") or db_name
schema_name = (
snode["Source"].get("Schema", {}).get("O") or db_name
)
table_name = snode["Source"].get("Name", {}).get("O", "")
# 检查表名是否为临时表,如果不是则添加到结果中
if table_name not in temporary_tables:
table_ref.append({"schema": schema_name, "name": table_name})
table_ref.append(
{"schema": schema_name, "name": table_name}
)
# assert: source node must exists if table_refs node exists.
# else:
# raise Exception("GoInception Error: not found source node")
Expand Down Expand Up @@ -385,12 +391,13 @@ def get_session_variables(instance):
set_session_sql += f"inception set session {k} = '{v}';\n"
return variables, set_session_sql


def remove_duplicates(table_list):
unique_tables = []
seen = set()
for table in table_list:
identifier = (table['schema'], table['name'])
identifier = (table["schema"], table["name"])
if identifier not in seen:
seen.add(identifier)
unique_tables.append(table)
return unique_tables
return unique_tables

0 comments on commit fed73cc

Please # to comment.