Summary
analyze_query() crashes the Python process (segmentation fault, apparently unbounded recursion) when a PIVOT reads from a CTE. The same PIVOT over a physical table works.
Reproduction
pip install polyglot-sql==0.12.1
import polyglot_sql
sql = """
WITH pivot_input AS (
SELECT customer_id, category, amount FROM staged_orders
)
SELECT * FROM pivot_input
PIVOT(MAX(amount) FOR category IN ('books', 'games'))
"""
polyglot_sql.analyze_query(sql, {"dialect": "snowflake"})
Actual
The interpreter exits with Segmentation fault (core dumped). No exception is raised. The dynamic form IN (ANY ORDER BY category) crashes the same way.
Replacing FROM pivot_input with FROM staged_orders returns normally.
Expected
analyze_query() returns an analysis, or raises a catchable error, for a PIVOT whose input is a CTE. It must not terminate the host process.
Summary
analyze_query()crashes the Python process (segmentation fault, apparently unbounded recursion) when aPIVOTreads from a CTE. The samePIVOTover a physical table works.Reproduction
Actual
The interpreter exits with
Segmentation fault (core dumped). No exception is raised. The dynamic formIN (ANY ORDER BY category)crashes the same way.Replacing
FROM pivot_inputwithFROM staged_ordersreturns normally.Expected
analyze_query()returns an analysis, or raises a catchable error, for aPIVOTwhose input is a CTE. It must not terminate the host process.