Skip to content

analyze_query crashes the process on PIVOT over a CTE #470

Description

@kvlonge

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions