PyDough code (without the max_recursion_depth_exceeded calculation) succeeds with pydough.explain_llm(), but fails with pydough.to_sql().
Error generating SQL:
maximum recursion depth exceeded
$0.key_0
Minimal reproducible example (TPCH):
# Step 1: Prepare order data with customer name and year
invoice_info = orders.CALCULATE(
order_year=YEAR(order_date),
key=customer.key,
order_total=total_price
)
# Step 2: Partition by customer to calculate total per customer
customer_level = invoice_info.PARTITION(
name="customer_groups",
by=(key)
).CALCULATE(
max_recursion_depth_exceeded=SUM(invoice_info.order_total),
key_0_error=SUM(orders.total_price)
)
Additional Context / Workarounds
Behavior Shift: Removing the max_recursion_depth_exceeded calculation produces a $0.key_0 error instead, and pydough.explain_llm() succeeds at this point.
Workaround: The bug can be prevented by changing key=customer.key to cust_id=customer.key in Step 1.
TPCH collections used:
orders
├── order_date
├── total_price
└── customer [one member of customers]
customers
├── key
└── orders [multiple orders]
PyDough code (without the
max_recursion_depth_exceededcalculation) succeeds withpydough.explain_llm(), but fails withpydough.to_sql().Error generating SQL:
maximum recursion depth exceeded$0.key_0Minimal reproducible example (TPCH):
Additional Context / Workarounds
Behavior Shift: Removing the
max_recursion_depth_exceededcalculation produces a$0.key_0error instead, andpydough.explain_llm()succeeds at this point.Workaround: The bug can be prevented by changing
key=customer.keytocust_id=customer.keyin Step 1.TPCH collections used: