hello-stephen commented on code in PR #70408:
URL: https://github.com/apache/doris/pull/70408#discussion_r4752984936


##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java:
##########
@@ -468,7 +473,12 @@ public static List<ColumnDefinition> generateColumns(Plan 
plan, ConnectContext c
             } else {
                 colNames.add(colName);
             }
-            DataType dataType = getDataType(userSlot, i, ctx, partitionCol, 
distributionColumnNames);
+            if (exprDefinitions == null && userSlot.getDataType().conversion() 
instanceof VariantType) {
+                exprDefinitions = VariantType.collectExprDefinitions(plan);

Review Comment:
   [P2] Infer async MV VARIANT layouts from the analyzed plan
   
   `analyzeQueryInternal()` passes its optimized physical plan here, but 
`collectExprDefinitions()` bridges only `LogicalCTEConsumer`. For a twice-used 
CTE that defines `CAST(s AS VARIANT<'t':INT, 
PROPERTIES("variant_max_subcolumns_count"="5")>) AS v`, the materialized shape 
is:
   
   ```text
   CTEAnchor
     CTEProducer(Project(CAST(...) AS v#producer))
     Project(c1.k, v#consumer)
       Join(c1.k = c2.k)
         PhysicalCTEConsumer(c1)
         PhysicalCTEConsumer(c2)
   ```
   
   The consumer has a fresh ExprId and the cast output has no original column. 
Without the physical consumer-to-producer mapping, the resolver stops at 
`v#consumer` and returns default storage properties, dropping template `t` and 
count5. Thus default materialized CREATE already loses the explicit 
declaration. More seriously, create this MV with `SET 
enable_cte_materialize=false`: inlining preserves the cast/template, but the 
setting is not saved in the MV's `affectQueryResultInPlan` variables. A fresh 
refresh context uses default materialization, loses `t`, and 
`checkColumnIfChange` throws "column type not same" despite no source-schema 
change; an unrelated ADD COLUMN can also invalidate the MV. Use the available 
analyzed-plan snapshot for expression inference, or handle physical CTE 
mappings, and cover repeated-CTE async MV creation plus refresh. The new 
repeated-CTE cast test currently covers CTAS only.



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