Skip to content

KL-5: expression-derived CTE output columns don't surface the real operand column #14

Description

@devops-den

What it does wrong

Expression-derived CTE output columns don't surface the real column read inside the expression.

;WITH OrderTotals AS (
    SELECT CustomerId, SUM(Amount) AS 'Total' FROM dbo.Orders GROUP BY CustomerId
)
SELECT OT.[Total] FROM OrderTotals OT

'Total' is a computed expression (SUM(Amount)), not a passthrough of a real dbo.Orders column — there is no single source column to bind the name Total to, and SPXray correctly refuses to invent a physical column called Total on dbo.Orders (never-invent holds, this part already passes). What it does not yet do is look inside the expression and note that Amount is a real column being read.

Why it matters

A migration report under-counts which columns a procedure actually touches whenever they're wrapped in an aggregate or expression — Amount genuinely is read from dbo.Orders, but the report won't say so.

Test

Pinned as a strict-xfail: tests/test_known_limitations.py::test_KL5_expression_derived_cte_output_not_resolved.

Why this needs the AST backend

Extracting the operand out of SUM(Amount) (or CASE WHEN x THEN y END, or any arbitrary expression) needs real expression parsing, not a simple AS-binding regex. Part of the planned v1.2 AST backend (see README roadmap).

Metadata

Metadata

Assignees

No one assigned

    Labels

    known-limitationA documented, pinned parser limitation (see tests/test_known_limitations.py)needs-ast-backendBlocked on the planned AST-based parser backend

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions