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

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


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new a290c21deff [fix](decimal256) some ddl could not run or get wrong 
result on decimal256 (#53360)
a290c21deff is described below

commit a290c21deff784635ac2bd84d0d3c2443f861aff
Author: morrySnow <[email protected]>
AuthorDate: Wed Jul 16 16:06:33 2025 +0800

    [fix](decimal256) some ddl could not run or get wrong result on decimal256 
(#53360)
    
    ### What problem does this PR solve?
    
    Problem Summary:
    
    some ddl could not run or get wrong result on decimal256
    
    - alter table add column
    - alter table modify column
    - create aggregate model table with decimal256 value column
    
    ### Release note
    
    None
    
    ### Check List (For Author)
    
    - Test <!-- At least one of them must be included. -->
        - [x] Regression test
        - [ ] Unit Test
        - [ ] Manual test (add detailed scripts or steps below)
        - [ ] No need to test or manual test. Explain why:
    - [ ] This is a refactor/code format and no logic has been changed.
            - [ ] Previous test can cover this change.
            - [ ] No code files have been changed.
            - [ ] Other reason <!-- Add your reason?  -->
    
    - Behavior changed:
        - [ ] No.
        - [x] Yes. <!-- Explain the behavior change -->
    
    - Does this need documentation?
        - [x] No.
    - [ ] Yes. <!-- Add document PR link here. eg:
    https://github.com/apache/doris-website/pull/1214 -->
    
    ### Check List (For Reviewer who merge this PR)
    
    - [ ] Confirm the release note
    - [ ] Confirm test cases
    - [ ] Confirm document
    - [ ] Add branch pick label <!-- Add branch pick label that this PR
    should merge into -->
---
 .../org/apache/doris/catalog/AggregateType.java    |   3 +
 .../java/org/apache/doris/catalog/FunctionSet.java |  44 +++++++
 .../java/org/apache/doris/qe/SessionVariable.java  |  10 +-
 .../datatype_p0/decimalv3/test_decimal256_ddl.out  | Bin 0 -> 441 bytes
 .../decimalv3/test_decimal256_ddl.groovy           | 144 +++++++++++++++++++++
 5 files changed, 199 insertions(+), 2 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/catalog/AggregateType.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/AggregateType.java
index 94a788f0b9a..12f3d16fbd3 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/AggregateType.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/AggregateType.java
@@ -70,6 +70,7 @@ public enum AggregateType {
         primitiveTypeList.add(PrimitiveType.DECIMAL32);
         primitiveTypeList.add(PrimitiveType.DECIMAL64);
         primitiveTypeList.add(PrimitiveType.DECIMAL128);
+        primitiveTypeList.add(PrimitiveType.DECIMAL256);
         compatibilityMap.put(SUM, EnumSet.copyOf(primitiveTypeList));
 
         primitiveTypeList.clear();
@@ -84,6 +85,7 @@ public enum AggregateType {
         primitiveTypeList.add(PrimitiveType.DECIMAL32);
         primitiveTypeList.add(PrimitiveType.DECIMAL64);
         primitiveTypeList.add(PrimitiveType.DECIMAL128);
+        primitiveTypeList.add(PrimitiveType.DECIMAL256);
         primitiveTypeList.add(PrimitiveType.DATE);
         primitiveTypeList.add(PrimitiveType.DATETIME);
         primitiveTypeList.add(PrimitiveType.DATEV2);
@@ -105,6 +107,7 @@ public enum AggregateType {
         primitiveTypeList.add(PrimitiveType.DECIMAL32);
         primitiveTypeList.add(PrimitiveType.DECIMAL64);
         primitiveTypeList.add(PrimitiveType.DECIMAL128);
+        primitiveTypeList.add(PrimitiveType.DECIMAL256);
         primitiveTypeList.add(PrimitiveType.DATE);
         primitiveTypeList.add(PrimitiveType.DATETIME);
         primitiveTypeList.add(PrimitiveType.DATEV2);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java
index de1d1178ed6..54125ce4ac3 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java
@@ -139,6 +139,7 @@ public class FunctionSet<T> {
                     .put(Type.DECIMAL32, Type.DECIMAL32)
                     .put(Type.DECIMAL64, Type.DECIMAL64)
                     .put(Type.DECIMAL128, Type.DECIMAL128)
+                    .put(Type.DECIMAL256, Type.DECIMAL256)
                     .build();
 
     private static final Map<Type, Type> STDDEV_RETTYPE_SYMBOL =
@@ -953,6 +954,19 @@ public class FunctionSet<T> {
                         null,
                         "",
                         false, true, true, true));
+            } else if (t.equals(Type.DECIMAL256)) {
+                // vectorized
+                
addBuiltin(AggregateFunction.createBuiltin("multi_distinct_count", 
Lists.newArrayList(t),
+                        Type.BIGINT,
+                        Type.DECIMAL256,
+                        "",
+                        "",
+                        "",
+                        "",
+                        null,
+                        null,
+                        "",
+                        false, true, true, true));
             }
 
             // sum in multi distinct
@@ -1073,6 +1087,29 @@ public class FunctionSet<T> {
                         null,
                         "",
                         false, true, true, true));
+            } else if (t.equals(Type.DECIMAL256)) {
+                
addBuiltin(AggregateFunction.createBuiltin("multi_distinct_sum", 
Lists.newArrayList(t),
+                        MULTI_DISTINCT_SUM_RETURN_TYPE.get(t),
+                        Type.DECIMAL256,
+                        "",
+                        "",
+                        "",
+                        "",
+                        null,
+                        null,
+                        "",
+                        false, true, false, true));
+                
addBuiltin(AggregateFunction.createBuiltin("multi_distinct_sum0", 
Lists.newArrayList(t),
+                        MULTI_DISTINCT_SUM_RETURN_TYPE.get(t),
+                        Type.DECIMAL256,
+                        "",
+                        "",
+                        "",
+                        "",
+                        null,
+                        null,
+                        "",
+                        false, true, true, true));
             }
             // Min
             addBuiltin(AggregateFunction.createBuiltin("min",
@@ -1349,6 +1386,13 @@ public class FunctionSet<T> {
                     null, null,
                     "",
                     null, false, true, nameWithReturn.getValue(), true));
+            addBuiltin(AggregateFunction.createBuiltin(nameWithReturn.getKey(),
+                    Lists.<Type>newArrayList(Type.DECIMAL256), 
Type.DECIMAL256, Type.DECIMAL256, "",
+                    "",
+                    "",
+                    null, null,
+                    "",
+                    null, false, true, nameWithReturn.getValue(), true));
             addBuiltin(AggregateFunction.createBuiltin(nameWithReturn.getKey(),
                     Lists.<Type>newArrayList(Type.LARGEINT), Type.LARGEINT, 
Type.LARGEINT, "",
                     "",
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
index a036b18cd7e..3a7ee7c8f2e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
@@ -4487,10 +4487,16 @@ public class SessionVariable implements Serializable, 
Writable {
     public static boolean getEnableDecimal256() {
         ConnectContext connectContext = ConnectContext.get();
         if (connectContext == null) {
-            return false;
+            return VariableMgr.getDefaultSessionVariable().enableDecimal256;
         }
         SessionVariable sessionVariable = connectContext.getSessionVariable();
-        return connectContext.getState().isNereids() && 
sessionVariable.isEnableDecimal256();
+        if (!sessionVariable.isEnableDecimal256()) {
+            return false;
+        }
+        if (connectContext.getState().isQuery()) {
+            return connectContext.getState().isNereids();
+        }
+        return true;
     }
 
     public boolean isEnableDecimal256() {
diff --git a/regression-test/data/datatype_p0/decimalv3/test_decimal256_ddl.out 
b/regression-test/data/datatype_p0/decimalv3/test_decimal256_ddl.out
new file mode 100644
index 00000000000..aa3d3f760f3
Binary files /dev/null and 
b/regression-test/data/datatype_p0/decimalv3/test_decimal256_ddl.out differ
diff --git 
a/regression-test/suites/datatype_p0/decimalv3/test_decimal256_ddl.groovy 
b/regression-test/suites/datatype_p0/decimalv3/test_decimal256_ddl.groovy
new file mode 100644
index 00000000000..e50925ad27c
--- /dev/null
+++ b/regression-test/suites/datatype_p0/decimalv3/test_decimal256_ddl.groovy
@@ -0,0 +1,144 @@
+// 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.
+
+suite("test_decimal256_ddl") {
+    def getJobState = { tableName ->
+        def jobStateResult = sql """ SHOW ALTER TABLE COLUMN WHERE 
IndexName='${tableName}' ORDER BY createtime DESC LIMIT 1 """
+        return jobStateResult[0][9]
+    }
+
+    def waitSchemaChangeFinish = { table ->
+        while (true) {
+            String result = getJobState(table)
+            if (result == "FINISHED") {
+                break
+            } else if (result == "CANCELLED") {
+                sucess.set(false)
+                logger.error("schema change was cancelled")
+                assertTrue(false)
+            } else {
+                sleep(2000)
+            }
+        }
+    }
+
+    def table1 = "test_decimal256_ddl"
+
+    sql "set enable_decimal256=true"
+
+    sql "drop table if exists ${table1}"
+
+    sql """
+    CREATE TABLE IF NOT EXISTS `${table1}` (
+      id int,
+      dcl1 decimal(40, 5)
+    ) ENGINE=OLAP
+    DUPLICATE KEY(`id`, `dcl1`)
+    DISTRIBUTED BY HASH(`id`, `dcl1`) BUCKETS 8
+    PROPERTIES (
+    "replication_allocation" = "tag.location.default: 1"
+    )
+    """
+
+    sql """
+        alter table ${table1} add column (dcl2 decimal(60,15));
+    """
+
+    waitSchemaChangeFinish(table1)
+
+
+    sql """
+        alter table ${table1} add column (dcl3 decimal(60,15) default '0');
+    """
+
+    waitSchemaChangeFinish(table1)
+
+
+    sql """
+        alter table ${table1} modify column dcl2 decimal(48, 5);
+    """
+
+    waitSchemaChangeFinish(table1)
+
+
+    sql """
+        alter table ${table1} modify column dcl3 decimal(48, 5) default '0';
+    """
+
+    waitSchemaChangeFinish(table1)
+
+
+    sql """
+        create materialized view ${table1}mv as select id, sum(dcl1), 
min(dcl2), max(dcl3) from ${table1} group by id;
+    """
+
+
+    sql """
+        insert into ${table1} values
+            (1,1.1,1.2,1.3),
+            (1,11.1,11.2,11.3),
+            (1,12.1,12.2,12.3),
+            (2,2.1,2.2,2.3),  
+            (2,21.1,21.2,21.3),  
+            (2,22.1,22.2,22.3)  
+    """
+
+    sql """sync"""
+
+    order_qt_select """
+        select * from ${table1} order by id
+    """
+
+    order_qt_agg """
+        select sum(dcl1), min(dcl2), max(dcl3) from ${table1} group by id
+    """
+
+    sql "drop table if exists ${table1} force"
+
+    sql """
+        create table ${table1} (id int, dcl1 decimal(60,3) sum, dcl2 
decimal(70,0) min, dcl3 decimal(70,4) max)
+        AGGREGATE KEY(`id`) 
+        DISTRIBUTED BY hash(id)
+        PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1"
+        )
+    """
+
+    sql """
+        insert into ${table1} values
+            (1,1.1,1.2,1.3),
+            (1,11.1,11.2,11.3),
+            (1,12.1,12.2,12.3),
+            (2,2.1,2.2,2.3),  
+            (2,21.1,21.2,21.3),  
+            (2,22.1,22.2,22.3)  
+    """
+
+    sql """sync"""
+
+    order_qt_select """
+        select * from ${table1} order by id
+    """
+
+    order_qt_agg """
+        select sum(dcl1), min(dcl2), max(dcl3) from ${table1} group by id
+    """
+
+    sql "drop table if exists ${table1} force"
+
+
+}


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

Reply via email to