github-actions[bot] commented on code in PR #69012:
URL: https://github.com/apache/doris/pull/69012#discussion_r4262118517


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/AggStateType.java:
##########
@@ -93,6 +94,14 @@ public AggStateType(String functionName, List<DataType> 
subTypes,
         this.looseTypeCoercionAllowed = looseTypeCoercionAllowed;
     }
 
+    /** Resolve SQL type declarations without changing the decoder for 
persisted states. */
+    public static AggStateType fromSql(String functionName, List<DataType> 
subTypes,
+            List<Boolean> subTypeNullables, boolean returnNullable) {
+        String resolvedName = "bitmap_intersect".equalsIgnoreCase(functionName)

Review Comment:
   [P1] Reject decoder changes before linking legacy state columns
   
   For an existing v1 column `s` followed by another value column `v`, `ALTER 
TABLE t MODIFY COLUMN s AGG_STATE<bitmap_intersect(bitmap NULL)> GENERIC AFTER 
v` now resolves `s` to v2. Catalog `AggStateType.equals()` ignores the function 
name, so `SchemaChangeHandler.processModifyColumn()` keeps `typeChanged=false`, 
preserves the column ID and adds no shadow column. The reorder still triggers a 
job; BE maps the unchanged column name and performs `LinkedSchemaChange`, 
retaining the original bitmap-only segment bytes under the v2 schema. A 
subsequent v2 merge reads those bytes as an initialization flag and 
length-prefixed bitmap: the valid v1 singleton `{1}` (`01 01 00 00 00`) is 
treated as uninitialized and returns an empty intersection. Reject incompatible 
AGG_STATE function identities before ALTER (and account for them in catalog 
equality), unless the bytes are actually migrated. This is a separate 
ALTER/storage path from the fixed LIKE/SHOW CREATE round trip.



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinAggregateFunctions.java:
##########
@@ -136,7 +137,8 @@ private BuiltinAggregateFunctions() {
                 agg(AvgMap.class, "avg_map"),
                 agg(AvgWeighted.class, "avg_weighted"),
                 agg(BitmapAgg.class, "bitmap_agg"),
-                agg(BitmapIntersect.class, "bitmap_intersect"),
+                agg(BitmapIntersect.class, "bitmap_intersect_v1"),
+                agg(BitmapIntersectV2.class, "bitmap_intersect_v2", 
"bitmap_intersect"),

Review Comment:
   [P2] Preserve v1 producers when refreshing existing async MVs
   
   An async MV created before this change from `SELECT id, 
bitmap_intersect_state(b) AS s FROM t` has a persisted v1 AGG_STATE column, but 
`CreateMTMVInfo.rewriteQuerySql()` retains the unversioned builtin spelling in 
`MTMV.querySql`. On refresh, `UpdateMvByPartitionCommand.from()` reparses that 
SQL and this registration now produces:
   
   ```text
   Sink(mv.s: v1)
     Project(id, bitmap_intersect_v2_state(b) AS s: v2)
       Scan(t)
   ```
   
   `BindSink` then calls `TypeCoercionUtils.castIfNotSameType()`, and 
`CheckCast` rejects the different function identities, so an existing supported 
MV stops refreshing after upgrade. Emitting v1 in schema `toSql()` does not 
update the persisted executable query SQL, making this distinct from the fixed 
schema round-trip thread. Preserve the producer version when replaying existing 
definitions, or migrate their query and state schema compatibly, and cover a 
pre-upgrade state-producing MV refresh.



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinAggregateFunctions.java:
##########
@@ -136,7 +137,8 @@ private BuiltinAggregateFunctions() {
                 agg(AvgMap.class, "avg_map"),
                 agg(AvgWeighted.class, "avg_weighted"),
                 agg(BitmapAgg.class, "bitmap_agg"),
-                agg(BitmapIntersect.class, "bitmap_intersect"),
+                agg(BitmapIntersect.class, "bitmap_intersect_v1"),

Review Comment:
   [P1] Retain v1 producer names in synchronous MV defining expressions
   
   With AGG_STATE enabled, creating a synchronous MV on a duplicate-key table 
with `SELECT id, bitmap_intersect_v1(bitmap_from_string(s)) AS bi FROM t GROUP 
BY id` is accepted. This registration builds the canonically named 
`BitmapIntersect`; `CreateMaterializedViewCommand.buildMVColumnItem()` creates 
a v1 GENERIC column but synthesizes its `Column.defineExpr` through 
`StateCombinator.create()`, naming it `bitmap_intersect_state`. For subsequent 
INSERTs into `t`, `BindSink.getColumnToOutput()` renders and reparses that 
expression, so the public producer now binds to v2:
   
   ```text
   Sink(t and mv.bi: v1)
     Project(..., bitmap_intersect_v2_state(bitmap_from_string(s)) AS mv.bi: v2)
       InsertInput(id, s)
   ```
   
   The cast to the MV's retained v1 type fails at `BindSink`'s 
materialized-column coercion, blocking base-table writes. Preserve the explicit 
v1 spelling when synthesizing/replaying these producer expressions. This 
affects newly created explicit-v1 synchronous MVs and their INSERT path, 
independently of the async MV upgrade/query-SQL issue and the fixed typed 
legacy union consumers.



-- 
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]

Reply via email to