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) |
| Modifier and Type | Method and Description |
|---|---|
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. |
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 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.