Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions api/app/sta2rest/visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,9 @@ def visit_ExpandNode(self, node: ExpandNode, parent=None):
for relationship in join_relationships:
sub_query = sub_query.join(relationship)

sub_query_from = sub_query.subquery()
columns_to_select = []
for column in sub_query.columns:
for column in sub_query_from.c:
if column.name not in labels:
columns_to_select.append(column)
else:
Expand All @@ -439,7 +440,7 @@ def visit_ExpandNode(self, node: ExpandNode, parent=None):
)

if columns_to_select is not None:
sub_query = select(*columns_to_select).select_from(sub_query)
sub_query = select(*columns_to_select).select_from(sub_query_from)

expand_queries.append(
[
Expand Down Expand Up @@ -799,7 +800,7 @@ def visit_QueryNode(self, node: QueryNode):
limited_count_query_str = str(
select(func.count())
.select_from(
query_estimate_count.limit(COUNT_ESTIMATE_THRESHOLD)
query_estimate_count.limit(COUNT_ESTIMATE_THRESHOLD).subquery()
)
.compile(
dialect=engine.dialect,
Expand Down Expand Up @@ -827,8 +828,9 @@ def visit_QueryNode(self, node: QueryNode):
top_value -= 1

main_query = main_query.limit(top_value).offset(skip_value)
main_query_subquery = main_query.subquery("main_query_source")
columns_to_select = []
for column in main_query.selected_columns:
for column in main_query_subquery.c:
if column.name not in labels:
columns_to_select.append(column)
else:
Expand All @@ -850,11 +852,11 @@ def visit_QueryNode(self, node: QueryNode):
if columns_to_select is not None:
main_query = (
select(*columns_to_select)
.select_from(main_query.subquery())
.select_from(main_query_subquery)
.alias("main_query")
)
else:
main_query = main_query.alias("main_query")
main_query = main_query_subquery.alias("main_query")

if result_format == "DataArray":
if not node.expand:
Expand Down Expand Up @@ -913,10 +915,10 @@ def visit_QueryNode(self, node: QueryNode):
value = select_query[0].name
else:
value = select_query[0].right
main_query_subquery = main_query.subquery()
main_query_json = main_query.subquery("main_query_json")
main_query = select(
main_query_subquery.c.json.op("->")(text(f"'{value}'"))
).select_from(main_query_subquery)
main_query_json.c.json.op("->")(text(f"'{value}'"))
).select_from(main_query_json)

main_query_str = str(
main_query.compile(
Expand Down