924060929 commented on code in PR #69304:
URL: https://github.com/apache/doris/pull/69304#discussion_r4779796510
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java:
##########
@@ -432,10 +434,15 @@ public class Rewriter extends AbstractBatchJobExecutor {
// plan nodes.
custom(RuleType.BIND_SCORE_TO_OLAP_SCAN,
BindScoreToOlapScan::new),
custom(RuleType.FOLD_CONSTANT_FOR_SQL_CACHE,
FoldConstantForSqlCache::new),
+ // Expose eligible CTE producers before validating sink
codec casts.
+ // For example, a v19 sink must reach SUM_STATE behind a
v21 CTE
+ // consumer. Keep the existing materialization and
volatility rules.
+ custom(RuleType.PULL_UP_CTE_ANCHOR, PullUpCteAnchor::new),
Review Comment:
Additional note on rule ordering:
- Moving `PushDownAggStateCast` (and CTE inlining) before
`ExpressionNormalizationAndOptimization` still misses `LogicalView` because
`InlineLogicalView` runs later in
`CTE_CHILDREN_REWRITE_JOBS_BEFORE_SUB_PATH_PUSH_DOWN` (so `INSERT INTO old_sink
SELECT ... FROM view_with_state` still fails at the early `CheckCast`).
- If FE cast pushdown is kept at all, there is no need to reorder
`PULL_UP_CTE_ANCHOR` / `CTE_INLINE`. `CheckDataTypes` at the end of `Rewriter`
already validates surviving `AggStateType` casts via
`CheckCast.validate(cast)`. Deferring same-signature version-only
`AggStateType` cast rejection from early `ExpressionNormalization` to
`CheckDataTypes` lets `PushDownAggStateCast` run **after** `Subquery
unnesting`, `CTE_INLINE`, `InlineLogicalView`, and `BuildAggForUnion` — keeping
global CTE order untouched, automatically covering `LogicalView`, and
eliminating the need for `PushDownAggStateCast` to touch `LogicalApply` /
`PullUpProjectUnderApply`, `LogicalSubQueryAlias`, or `UNION DISTINCT` lowering.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/AggStateType.java:
##########
@@ -128,6 +173,11 @@ public boolean equals(Object o) {
}
AggStateType rhs = (AggStateType) o;
+ // A sink must not treat version 21 state bytes as legacy state bytes.
+ // Keep the cast so that the STATE producer can use the target codec.
+ if (beExecVersion != rhs.beExecVersion) {
Review Comment:
To be explicit about the preferred architecture: **Option 2 (handling
`CAST(AggState@v21 AS AggState@v19)` on BE)** is strongly preferred — zero-copy
passthrough for byte-compatible functions and explicit handling/rejection of
`[0]` for nullable `bitmap_intersect`. That keeps FE changes minimal (only
persisting/propagating `beExecVersion`) and avoids adding
`PushDownAggStateCast` or touching `Rewriter` / `LogicalApply`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]