This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.1 by this push:
     new 2ac171097ed branch-4.1: [fix](variant) Reject Decimal256 in V2 VARIANT 
templates (#71007)
2ac171097ed is described below

commit 2ac171097edc713a41b0e0c532631742ee8e4eea
Author: lihangyu <[email protected]>
AuthorDate: Sun Nov 29 18:17:23 2026 +0800

    branch-4.1: [fix](variant) Reject Decimal256 in V2 VARIANT templates 
(#71007)
    
    cherry-pick #71006
    
    Reject Decimal256 in VARIANT templates when Variant V2 is enabled.
    Variant V1 continues to accept scalar and array Decimal256 templates.
    
    ### Testing
    
    - `VariantTemplateDdlTest` passed all three cases on dev-x.
    - `test_all_prdefine_type_to_sparse` and `rqg7` passed on the branch-4.1
    V1 cluster.
---
 .../trees/plans/commands/info/CreateTableInfo.java |  6 ++
 .../apache/doris/nereids/types/VariantType.java    | 13 ++++
 .../doris/catalog/VariantTemplateDdlTest.java      | 85 ++++++++++++++++++++++
 3 files changed, 104 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java
index 8e18c589e73..0d5e60374b3 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java
@@ -481,6 +481,12 @@ public class CreateTableInfo {
                 throw new AnalysisException("Disable to create table with 
`DECIMAL` type columns,"
                         + "please use `DECIMALV3`.");
             }
+            DataType type = columnDef.getType();
+            if (type instanceof VariantType && ((VariantType) 
type).isExecutionV2()
+                    && ((VariantType) type).hasDecimal256Template()) {
+                throw new AnalysisException("Decimal256 is not supported in 
VARIANT templates for column '"
+                        + columnDef.getName() + "'");
+            }
         }
         // check duplicated columns
         Map<String, ColumnDefinition> columnMap = new 
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java
index ad52a15ef8e..e0bd12010e0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java
@@ -301,6 +301,19 @@ public class VariantType extends PrimitiveType {
         return predefinedFields;
     }
 
+    /** Whether any declared storage path uses Decimal256, including array 
elements. */
+    public boolean hasDecimal256Template() {
+        return predefinedFields.stream().anyMatch(field -> 
containsDecimal256(field.getDataType()));
+    }
+
+    private static boolean containsDecimal256(DataType type) {
+        while (type instanceof ArrayType) {
+            type = ((ArrayType) type).getItemType();
+        }
+        return type instanceof DecimalV3Type
+                && ((DecimalV3Type) type).getPrecision() > 
DecimalV3Type.MAX_DECIMAL128_PRECISION;
+    }
+
     public int getVariantMaxSubcolumnsCount() {
         return variantMaxSubcolumnsCount;
     }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/catalog/VariantTemplateDdlTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/catalog/VariantTemplateDdlTest.java
new file mode 100644
index 00000000000..d1d98495e32
--- /dev/null
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/catalog/VariantTemplateDdlTest.java
@@ -0,0 +1,85 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.catalog;
+
+import org.apache.doris.common.Config;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.utframe.TestWithFeService;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class VariantTemplateDdlTest extends TestWithFeService {
+    private boolean originalDecimal256;
+    private boolean originalNereids;
+    private boolean originalVariantV2;
+
+    @Override
+    protected void runBeforeAll() throws Exception {
+        createDatabase("variant_template_ddl");
+        connectContext.setDatabase("variant_template_ddl");
+    }
+
+    @BeforeEach
+    public void enableDecimal256() {
+        originalDecimal256 = 
connectContext.getSessionVariable().enableDecimal256;
+        originalNereids = connectContext.getState().isNereids();
+        originalVariantV2 = Config.enable_variant_v2;
+        connectContext.getSessionVariable().enableDecimal256 = true;
+        connectContext.getState().setNereids(true);
+    }
+
+    @AfterEach
+    public void restoreSettings() {
+        connectContext.getSessionVariable().enableDecimal256 = 
originalDecimal256;
+        connectContext.getState().setNereids(originalNereids);
+        Config.enable_variant_v2 = originalVariantV2;
+    }
+
+    @Test
+    public void testDecimal256TemplatesAreRejectedInV2() {
+        Config.enable_variant_v2 = true;
+        for (String type : new String[] {"DECIMAL(39, 2)", "ARRAY<DECIMAL(76, 
2)>"}) {
+            AnalysisException error = 
Assertions.assertThrows(AnalysisException.class,
+                    () -> createTable(ddl("rejected_template", 
"VARIANT<'amount':" + type + ">")));
+            Assertions.assertTrue(error.getMessage().contains("Decimal256 is 
not supported in VARIANT templates"),
+                    error.getMessage());
+        }
+    }
+
+    @Test
+    public void testDecimal128TemplateAndStandaloneDecimal256AreAllowed() 
throws Exception {
+        Config.enable_variant_v2 = true;
+        createTable(ddl("allowed_types",
+                "VARIANT<'amount':DECIMAL(38, 2), 'items':ARRAY<DECIMAL(38, 
2)>>, wide DECIMAL(76, 2)"));
+    }
+
+    @Test
+    public void testDecimal256TemplatesAreAllowedInV1() throws Exception {
+        Config.enable_variant_v2 = false;
+        createTable(ddl("decimal256_v1",
+                "VARIANT<'scalar':DECIMAL(39, 2), 'items':ARRAY<DECIMAL(76, 
2)>>"));
+    }
+
+    private static String ddl(String table, String columns) {
+        return "CREATE TABLE " + table + " (id INT, v " + columns + ") 
DUPLICATE KEY(id) "
+                + "DISTRIBUTED BY HASH(id) BUCKETS 1 
PROPERTIES('replication_num'='1')";
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to