Skip to content

Commit

Permalink
Initial handling of decorrelation setup
Browse files Browse the repository at this point in the history
  • Loading branch information
knassre-bodo committed Feb 6, 2025
1 parent 4818c59 commit 17116d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 11 additions & 0 deletions pydough/conversion/hybrid_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ def __init__(
self._is_connection_root: bool = is_connection_root
self._agg_keys: list[HybridExpr] | None = None
self._join_keys: list[tuple[HybridExpr, HybridExpr]] | None = None
self._correlated_children: set[int] = set()
if isinstance(root_operation, HybridPartition):
self._join_keys = []

Expand Down Expand Up @@ -935,6 +936,14 @@ def children(self) -> list[HybridConnection]:
"""
return self._children

@property
def correlated_children(self) -> set[int]:
"""
The set of indices of children that contain correlated references to
the current hybrid tree.
"""
return self._correlated_children

@property
def successor(self) -> Optional["HybridTree"]:
"""
Expand Down Expand Up @@ -1634,6 +1643,8 @@ def make_hybrid_correl_expr(
collection, back_expr.term_name, remaining_steps_back
)
parent_result = self.make_hybrid_expr(parent_tree, new_expr, {}, False)
if not isinstance(parent_result, HybridCorrelExpr):
parent_tree.correlated_children.add(len(parent_tree.children))
# Restore parent_tree back onto the stack, since evaluating `back_expr`
# does not change the program's current placement in the sutbtrees.
self.stack.append(parent_tree)
Expand Down
8 changes: 5 additions & 3 deletions pydough/conversion/relational_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
)
from pydough.types import BooleanType, Int64Type, UnknownType

from .hybrid_decorrelater import decorrelate_hybrid
from .hybrid_tree import (
ConnectionType,
HybridBackRefExpr,
Expand Down Expand Up @@ -996,10 +997,11 @@ def convert_ast_to_relational(
final_terms: set[str] = node.calc_terms
node = translator.preprocess_root(node)

# Convert the QDAG node to the hybrid form, then invoke the relational
# conversion procedure. The first element in the returned list is the
# final rel node.
# Convert the QDAG node to the hybrid form, decorrelate it, then invoke
# the relational conversion procedure. The first element in the returned
# list is the final rel node.
hybrid: HybridTree = HybridTranslator(configs).make_hybrid_tree(node, None)
decorrelate_hybrid(hybrid)
renamings: dict[str, str] = hybrid.pipeline[-1].renamings
output: TranslationOutput = translator.rel_translation(
None, hybrid, len(hybrid.pipeline) - 1
Expand Down

0 comments on commit 17116d4

Please sign in to comment.