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


##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java:
##########
@@ -1223,6 +1239,22 @@ private static List<Column> 
buildExpectedPhysicalSchema(MTMV mtmv,
     private static boolean isTypeLike(Type type, Type typeOther) {
         if (type.isStringType()) {
             return typeOther.isStringType();
+        } else if (type instanceof org.apache.doris.catalog.VariantType
+                && typeOther instanceof org.apache.doris.catalog.VariantType) {
+            // An MV that an older version created stored a computed or 
external VARIANT as V1 (count=0),
+            // while this version analyses it as V2 (with the default 
subcolumn limit): that storage-layout
+            // promotion is not a schema change of the base tables.
+            org.apache.doris.catalog.VariantType storedVariant = 
(org.apache.doris.catalog.VariantType) type;
+            org.apache.doris.catalog.VariantType analyzedVariant = 
(org.apache.doris.catalog.VariantType) typeOther;
+            org.apache.doris.catalog.VariantType normalized =
+                    
analyzedVariant.withSerializeType(storedVariant.getVariantSerializeType());
+            if (storedVariant.getVariantSerializeType() == 
TVariantSerializeType.V1
+                    && storedVariant.getVariantMaxSubcolumnsCount() == 0
+                    && !storedVariant.getEnableVariantDocMode()
+                    && analyzedVariant.getVariantSerializeType() == 
TVariantSerializeType.V2) {
+                normalized = normalized.withMaxSubcolumnsCount(0);
+            }
+            return storedVariant.equals(normalized);

Review Comment:
   [P2] Preserve legacy inferred VARIANT layouts during MV reanalysis
   
   For an upgraded async MV with `Project(k, coalesce(a,b) AS v) -> Scan(src)`, 
let nullable `a`/`b` both have count 2048 but 
`variant_max_sparse_column_statistics_size` 111/222. The base 
`VariantType.equals` treats these inputs as equal, so persisted `v` inherits 
111. This head distinguishes them: `Coalesce` gets `VariantType.INSTANCE`, and 
`getDataType` creates V2/count2048/stats10000. This normalization restores the 
version but leaves stats10000, so an unrelated `ALTER TABLE src ADD COLUMN 
unused INT` marks the valid MV `SCHEMA_CHANGE`, and its next refresh fails with 
"column type not same". Preserve the historical inferred storage properties 
during compatibility comparison and cover an upgraded MV over differing active 
layouts.



##########
regression-test/suites/variant_p0/v2/variant_decimal256_storage_error.groovy:
##########
@@ -26,8 +26,7 @@ suite("variant_decimal256_storage_error", "p0,nonConcurrent") 
{
             var VARIANT<
                 'decimal256_': DECIMAL(76, 2),
                 PROPERTIES(
-                    "variant_max_subcolumns_count" = "1",
-                    "variant_enable_typed_paths_to_sparse" = "false")
+                    "variant_max_subcolumns_count" = "1")

Review Comment:
   [P2] Pin the typed-path default before the materialized Decimal256 case
   
   The first CREATE no longer specifies typed-path extraction, and the suite 
only pins doc mode before it. Standard p0/nonConcurrent enables fuzzy sessions, 
whose `initFuzzyModeVariables` can set 
`debug_variant_enable_typed_paths_to_sparse=true`. Then `hot` occurs twice 
versus `decimal256_` once at budget 1, so Decimal256 goes into sparse storage. 
The first SELECT consequently raises "Conversion from Decimal256 storage cell 
to Variant V2 is not supported" instead of the asserted materialized-column 
error. The later reset happens after this assertion. Set the debug flag to 
false before the first CREATE so this case always exercises materialized 
storage.



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