public final class OutputColumn extends Object
sources is the list of
input columns this output depends on; derived distinguishes a
direct column reference (e.g. SELECT id) from a computed
expression (e.g. SELECT salary*2 AS doubled or
SELECT a.x + a.y); aggregate marks the output as the
result of an aggregate function call (e.g. COUNT(*),
SUM(salary)); windowSpec (slice 13) carries
PARTITION BY / OVER ORDER BY refs when the projection is a window
function.
Slice 4 introduced derived; slice 6 added aggregate
and lifted the empty-sources restriction for aggregates only (e.g.
COUNT(*) has no column refs); slice 13 added windowSpec
and lifts the empty-sources restriction for window functions
(e.g. ROW_NUMBER() OVER (...) has no column refs).
Note on flag propagation: derived, aggregate,
and windowSpec are local to a single statement's output. They
are not propagated transitively. If a CTE defines
total = SUM(salary), that CTE's output has
aggregate=true; an outer query that re-projects the CTE's
total column (SELECT total FROM cte) is a direct
reference and so the outer's output has aggregate=false (and
derived=false). Consumers that need a transitive view should
walk SemanticProgram.getLineage()
and inspect each upstream OutputColumn.
Window-function invariant (slice 13): when windowSpec
!= null, aggregate MUST be false. Window functions
are row-preserving (analytic), not row-collapsing, so the per-output
aggregate flag stays false even when the window function is a name
that overlaps with an aggregate (e.g. AVG(salary) OVER (...)).
The constructor enforces this invariant.
| Constructor and Description |
|---|
OutputColumn(String name,
boolean derived,
boolean aggregate,
List<ColumnRef> sources)
Backwards-compatible constructor delegating to the 5-arg form with
windowSpec=null. |
OutputColumn(String name,
boolean derived,
boolean aggregate,
List<ColumnRef> sources,
WindowSpec windowSpec) |
OutputColumn(String name,
boolean derived,
boolean aggregate,
List<ColumnRef> sources,
WindowSpec windowSpec,
String expressionText,
SourceSpan expressionSpan)
Full constructor (US-021a).
|
| Modifier and Type | Method and Description |
|---|---|
SourceSpan |
getExpressionSpan()
Source span of the projection expression (US-021a), half-open per
SourceSpan. |
String |
getExpressionText()
Original source text of the projection expression this output was
built from (US-021a), reconstructed from the parser's token stream so
multi-line expressions keep their newlines.
|
String |
getName() |
List<ColumnRef> |
getSources() |
WindowSpec |
getWindowSpec()
Per-output analytic dependencies (slice 13).
|
boolean |
isAggregate()
true when the projection is an aggregate function call
(COUNT, SUM, AVG, MIN, MAX, etc.). |
boolean |
isDerived()
true when the projection is an expression rather than a direct column reference. |
OutputColumn |
withExpression(String expressionText,
SourceSpan expressionSpan)
Copy of this output column with the projection-expression provenance
attached (US-021a).
|
public OutputColumn(String name, boolean derived, boolean aggregate, List<ColumnRef> sources)
windowSpec=null. Slice 13 added the 5-arg constructor; this
overload preserves source-compatibility for downstream callers that
were already using OutputColumn from a published version of
the library.public OutputColumn(String name, boolean derived, boolean aggregate, List<ColumnRef> sources, WindowSpec windowSpec)
public OutputColumn(String name, boolean derived, boolean aggregate, List<ColumnRef> sources, WindowSpec windowSpec, String expressionText, SourceSpan expressionSpan)
expressionText and
expressionSpan are optional projection-expression provenance
(see getExpressionText() / getExpressionSpan());
both default to null via the shorter overloads, preserving
full behavioural compatibility for every existing caller.public OutputColumn withExpression(String expressionText, SourceSpan expressionSpan)
this when both arguments are null (nothing to attach).public boolean isDerived()
true when the projection is an expression rather than a direct column reference.public boolean isAggregate()
true when the projection is an aggregate function call
(COUNT, SUM, AVG, MIN, MAX, etc.). Always implies isDerived().
Always false when getWindowSpec() is non-null
(window functions are row-preserving).public List<ColumnRef> getSources()
public WindowSpec getWindowSpec()
FUNC(arg) OVER (...));
null otherwise.public String getExpressionText()
null when no
single projection expression exists for this output — e.g. star
expansion (one * produces many outputs), synthetic outputs
(predicate-body scaffolding, UPDATE SET shells), or columns built by
paths that have not been wired yet. Null-safe: never throws.public SourceSpan getExpressionSpan()
SourceSpan. null under the same conditions as
getExpressionText(), and additionally when the expression's
boundary tokens cannot anchor a span. Null-safe: never throws.