You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To help with understanding query execution,, provide the ability to draw an executed query plan, ChatGPT has suggested this code will help draw the structure
fromcollectionsimportdefaultdictfromtypingimportList, Tuple, DictclassQueryPlanTree:
def__init__(self, edges: List[Tuple[str, str, str]]):
""" Constructs a query plan tree from a list of edges. Parameters: edges: List of tuples (source, relationship, target) """self.edges=edgesself.children=defaultdict(list)
self.parents= {}
# Build adjacency list from edgesforsrc, rel, tgtinedges:
self.children[src].append((rel, tgt))
self.parents[tgt] =src# Find root (a node that has no incoming edges)self.root=Noneforsrc, _, tgtinedges:
ifsrcnotinself.parents:
self.root=srcbreakdef_build_tree(self, node: str, prefix="") ->List[str]:
""" Recursively builds the ASCII tree representation. """lines= [
f"{prefix}┌────────────┐",
f"{prefix}│ {node:^10} │",
f"{prefix}└────────────┘"
]
children=self.children.get(node, [])
ifnotchildren:
returnlines# Prepare child branchessubtrees= [self._build_tree(child, prefix+" ") for_, childinchildren]
# Combine the current node with its childrenresult= []
result.extend(lines)
result.append(prefix+" ▲")
result.append(prefix+" ┌───────┴────────┐")
# Format children horizontallyfori, subtreeinenumerate(subtrees):
ifi>0:
result.append(prefix+" │ │")
result.extend(subtree)
returnresultdefdraw(self) ->str:
""" Returns the ASCII tree as a string. """ifnotself.root:
return"No root node found."return"\n".join(self._build_tree(self.root))
# Example edges representing a query planedges= [
("Join", "parent", "Scan A"),
("Join", "parent", "Join_2"),
("Join_2", "parent", "Scan B"),
("Join_2", "parent", "Scan C")
]
# Create and render the treequery_tree=QueryPlanTree(edges)
print(query_tree.draw())
The text was updated successfully, but these errors were encountered:
To help with understanding query execution,, provide the ability to draw an executed query plan, ChatGPT has suggested this code will help draw the structure
The text was updated successfully, but these errors were encountered: