Skip to content

CLUSTER/MERGE reject a named WINDOW clause instead of preserving it through the rewrite #183

Description

@conradbzura

Description

A named WINDOW w AS (...) clause on a CLUSTER/MERGE query, referenced by a surviving projection (SUM(score) OVER w), is not carried through the whole-query rewrite. As of #181, giql.expanders._genomic.transplant raises a clear ValueError for it (rather than the earlier silent drop that emitted a dangling OVER w → non-executable SQL). This issue tracks supporting it instead of rejecting it.

SELECT SUM(score) OVER w AS s, CLUSTER(interval) AS cid FROM peaks WINDOW w AS (PARTITION BY chrom)

Motivation

WINDOW is standard SQL supported by DuckDB and DataFusion. A dropped/rejected WINDOW is the same non-executable failure class as the dropped WITH (#174). It was deliberately left out of #181's scope because preserving it correctly is not a simple outer re-attach.

Root cause / why it is not a one-line fix

CLUSTER duplicates the user's non-CLUSTER projections into both the inner __giql_lag_calc subquery (so the columns are available to the window/adjacency computation) and the outer query. A SUM(score) OVER w projection therefore appears at both levels, so the WINDOW w AS (...) definition must be threaded into the inner subquery too — an outer-only re-attach (the mechanism _PRESERVED_ROOT_ARGS uses for LIMIT/OFFSET/DISTINCT/QUALIFY) leaves the inner OVER w dangling. MERGE has an analogous inner/outer split.

Expected outcome

A CLUSTER/MERGE query carrying a named WINDOW clause referenced by a surviving projection transpiles to executable SQL that defines the window at whatever level(s) reference it, rather than raising. Until then the #181 ValueError is the correct interim behavior (loud, not silent).

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or capability

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions