Skip to content

Commit

Permalink
query with cte to one integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ea-rus committed Nov 10, 2024
1 parent 8ac9fe2 commit b65132d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mindsdb_sql/planner/query_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,19 @@ def find_objects(node, is_table, **kwargs):
mdb_entities.append(node)

query_traversal(query, find_objects)

# cte names are not mdb objects
if query.cte:
cte_names = [
cte.name.parts[-1]
for cte in query.cte
]
mdb_entities = [
item
for item in mdb_entities
if '.'.join(item.parts) not in cte_names
]

return {
'mdb_entities': mdb_entities,
'integrations': integrations,
Expand Down Expand Up @@ -672,6 +685,16 @@ def plan_delete(self, query: Delete):
))

def plan_cte(self, query):
query_info = self.get_query_info(query)

if (
len(query_info['integrations']) == 1
and len(query_info['mdb_entities']) == 0
and len(query_info['user_functions']) == 0
):
# single integration, will be planned later
return

for cte in query.cte:
step = self.plan_select(cte.query)
name = cte.name.parts[-1]
Expand Down

0 comments on commit b65132d

Please sign in to comment.