PyDough code succeeds with pydough.explain_llm(), but fails with pydough.to_sql().
Error generating SQL:
Traceback (most recent call last):
File "/home/juankx/svc/PyDough/pydough_test.py", line 182, in <module>
sql = pydough.to_sql(unqualified_node, session=tester.session)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/juankx/svc/PyDough/pydough/evaluation/evaluate_unqualified.py", line 166, in to_sql
relational: RelationalRoot = convert_ast_to_relational(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/juankx/svc/PyDough/pydough/conversion/relational_converter.py", line 1892, in convert_ast_to_relational
output: TranslationOutput = rel_translator.rel_translation(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/juankx/svc/PyDough/pydough/conversion/relational_converter.py", line 1519, in rel_translation
context = self.rel_translation(*preceding_hybrid)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/juankx/svc/PyDough/pydough/conversion/relational_converter.py", line 1519, in rel_translation
context = self.rel_translation(*preceding_hybrid)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/juankx/svc/PyDough/pydough/conversion/relational_converter.py", line 1519, in rel_translation
context = self.rel_translation(*preceding_hybrid)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Previous line repeated 2 more times]
File "/home/juankx/svc/PyDough/pydough/conversion/relational_converter.py", line 1615, in rel_translation
result = self.handle_children(result, hybrid, pipeline_idx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/juankx/svc/PyDough/pydough/conversion/relational_converter.py", line 939, in handle_children
assert isinstance(key_expr, HybridChildRefExpr)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
Minimal reproducible example (TPCH):
a = orders.CALCULATE(year=YEAR(order_date)).PARTITION(name="a_years", by=year).CALCULATE(
year=year, total_a=SUM(orders.total_price)
)
b = orders.CALCULATE(year=YEAR(order_date)).PARTITION(name="b_years", by=year).CALCULATE(
other_year=year, total_b=COUNT(orders)
)
result = a.CROSS(b).WHERE(year == other_year).CALCULATE(year, total_a, total_b)
Additional Context / Workarounds
The bug can be prevented by doing b.CROSS(a) instead of a.CROSS(b)
TPCH collections used:
orders
├── order_date
└── total_price
PyDough code succeeds with pydough.explain_llm(), but fails with pydough.to_sql().
Error generating SQL:
Minimal reproducible example (TPCH):
Additional Context / Workarounds
The bug can be prevented by doing
b.CROSS(a)instead ofa.CROSS(b)TPCH collections used: