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

xuyang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 73f7979b73 [fix](struct-type) forbid struct-type to be distributed 
key/aggregation key and add more tests (#16626)
73f7979b73 is described below

commit 73f7979b73b5cad140fbe6e9d28f05b62f77ac5d
Author: xy720 <22125576+xy...@users.noreply.github.com>
AuthorDate: Sun Feb 19 15:16:36 2023 +0800

    [fix](struct-type) forbid struct-type to be distributed key/aggregation key 
and add more tests (#16626)
    
    This commits forbid struct and map type to be distributed key/aggregation 
key.
    
    The sql such as:
    
    select distinct stuct_col from struct_table
    
    will report an error.
---
 .../main/java/org/apache/doris/catalog/Type.java   |  9 +++++----
 .../org/apache/doris/analysis/CreateTableStmt.java |  2 +-
 .../doris/analysis/HashDistributionDesc.java       |  6 ++++++
 .../analysis/CheckExpressionLegalityTest.java      |  2 +-
 .../aggregate_group_by_metric_type.groovy          | 22 ++++++++++++++++++++++
 5 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java 
b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
index 56fbb20a1e..61e22fb32a 100644
--- a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
+++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
@@ -382,12 +382,13 @@ public abstract class Type {
     // 3. don't support group by
     // 4. don't support index
     public boolean isOnlyMetricType() {
-        return isObjectStored() || isArrayType();
+        return isObjectStored() || isComplexType();
     }
 
     public static final String OnlyMetricTypeErrorMsg =
-            "Doris hll, bitmap and array column must use with specific 
function, and don't support filter or group by."
-                    + "please run 'help hll' or 'help bitmap' or 'help array' 
in your mysql client.";
+            "Doris hll, bitmap, array, map, struct column must use with 
specific function, and don't"
+                    + " support filter or group by. please run 'help hll' or 
'help bitmap' or 'help array'"
+                    + " or 'help map' or 'help struct' in your mysql client.";
 
     public boolean isHllType() {
         return isScalarType(PrimitiveType.HLL);
@@ -480,7 +481,7 @@ public abstract class Type {
     }
 
     public boolean isCollectionType() {
-        return isMapType() || isArrayType() || isMultiRowType() || 
isStructType();
+        return isMapType() || isArrayType() || isMultiRowType();
     }
 
     public boolean isMapType() {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java
index dc699cde00..9a727e5de0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java
@@ -372,7 +372,7 @@ public class CreateTableStmt extends DdlStmt {
                         if (columnDef.getType().getPrimitiveType() == 
PrimitiveType.JSONB) {
                             break;
                         }
-                        if (columnDef.getType().isCollectionType()) {
+                        if (columnDef.getType().isComplexType()) {
                             break;
                         }
                         if (columnDef.getType().getPrimitiveType() == 
PrimitiveType.VARCHAR) {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/HashDistributionDesc.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/HashDistributionDesc.java
index 8b312a6ba7..d54049f793 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/HashDistributionDesc.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/HashDistributionDesc.java
@@ -120,6 +120,12 @@ public class HashDistributionDesc extends DistributionDesc 
{
                     } else if (column.getType().isArrayType()) {
                         throw new DdlException("Array Type should not be used 
in distribution column["
                                 + column.getName() + "].");
+                    } else if (column.getType().isMapType()) {
+                        throw new DdlException("Map Type should not be used in 
distribution column["
+                                + column.getName() + "].");
+                    } else if (column.getType().isStructType()) {
+                        throw new DdlException("Struct Type should not be used 
in distribution column["
+                                + column.getName() + "].");
                     } else if (column.getType().isFloatingPointType()) {
                         throw new DdlException("Floating point type should not 
be used in distribution column["
                                 + column.getName() + "].");
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckExpressionLegalityTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckExpressionLegalityTest.java
index 5d0ab86ff6..553ee35e44 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckExpressionLegalityTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckExpressionLegalityTest.java
@@ -65,7 +65,7 @@ public class CheckExpressionLegalityTest implements 
PatternMatchSupported {
                 ));
 
         ExceptionChecker.expectThrowsWithMsg(AnalysisException.class,
-                "Doris hll, bitmap and array column must use with specific 
function", () ->
+                "Doris hll, bitmap, array, map, struct column must use with 
specific function", () ->
                         PlanChecker.from(connectContext)
                                 .analyze("select count(distinct id) from 
(select to_bitmap(1) id) tbl")
                                 .applyBottomUp(new 
ExpressionRewrite(CheckLegalityAfterRewrite.INSTANCE))
diff --git 
a/regression-test/suites/query_p0/aggregate/aggregate_group_by_metric_type.groovy
 
b/regression-test/suites/query_p0/aggregate/aggregate_group_by_metric_type.groovy
index 31b8ef9fae..ee6ccf63a3 100644
--- 
a/regression-test/suites/query_p0/aggregate/aggregate_group_by_metric_type.groovy
+++ 
b/regression-test/suites/query_p0/aggregate/aggregate_group_by_metric_type.groovy
@@ -108,4 +108,26 @@ suite("aggregate_group_by_metric_type") {
     sql 'set enable_nereids_planner=false'
 
     sql "DROP TABLE test_group_by_array"
+
+    sql "DROP TABLE IF EXISTS test_group_by_struct"
+    sql "ADMIN SET FRONTEND CONFIG ('enable_struct_type' = 'true')"
+    sql """
+        CREATE TABLE IF NOT EXISTS test_group_by_struct (id int, s_struct 
struct<f1:tinyint, f2:char(5)>) ENGINE=OLAP DUPLICATE KEY(`id`)
+        DISTRIBUTED BY HASH(`id`) BUCKETS 1 properties("replication_num" = 
"1");
+        """
+
+    sql "insert into test_group_by_struct values(1, {1, 'a'})"
+
+    test {
+        sql "select distinct s_struct from test_group_by_struct"
+        exception "${error_msg}"
+    }
+    test {
+        sql "select s_struct from test_group_by_struct order by s_struct"
+        exception "${error_msg}"
+    }
+    test {
+        sql "select s_struct,count(*) from test_group_by_struct group by 
s_struct"
+        exception "${error_msg}"
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to