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

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

commit dcfccde3d105d6e617ab31dfdc1fd10c29e0a3b5
Author: morrySnow <[email protected]>
AuthorDate: Mon Jan 29 10:55:22 2024 +0800

    [fix](Nereids) create table should check column name format (#30421)
---
 .../trees/plans/commands/CreateTableCommand.java   |  3 +-
 .../plans/commands/info/ColumnDefinition.java      |  6 ++++
 .../create_table/test_create_table.groovy          | 36 ++++++++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java
index 4d1e3937162..2f4c1d55acc 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java
@@ -24,6 +24,7 @@ import org.apache.doris.catalog.Env;
 import org.apache.doris.catalog.ScalarType;
 import org.apache.doris.common.ErrorCode;
 import org.apache.doris.nereids.NereidsPlanner;
+import org.apache.doris.nereids.analyzer.UnboundResultSink;
 import org.apache.doris.nereids.analyzer.UnboundTableSink;
 import org.apache.doris.nereids.annotation.Developing;
 import org.apache.doris.nereids.exceptions.AnalysisException;
@@ -96,7 +97,7 @@ public class CreateTableCommand extends Command implements 
ForwardWithSync {
         LogicalPlan query = ctasQuery.get();
         List<String> ctasCols = createTableInfo.getCtasColumns();
         NereidsPlanner planner = new NereidsPlanner(ctx.getStatementContext());
-        Plan plan = planner.plan(query, PhysicalProperties.ANY, 
ExplainLevel.NONE);
+        Plan plan = planner.plan(new UnboundResultSink<>(query), 
PhysicalProperties.ANY, ExplainLevel.NONE);
         if (ctasCols == null) {
             // we should analyze the plan firstly to get the columns' name.
             ctasCols = 
plan.getOutput().stream().map(NamedExpression::getName).collect(Collectors.toList());
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java
index cd551cbbf4b..f6208feb48c 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java
@@ -24,6 +24,7 @@ import org.apache.doris.catalog.KeysType;
 import org.apache.doris.catalog.PrimitiveType;
 import org.apache.doris.catalog.ScalarType;
 import org.apache.doris.catalog.Type;
+import org.apache.doris.common.FeNameFormat;
 import org.apache.doris.nereids.exceptions.AnalysisException;
 import org.apache.doris.nereids.types.ArrayType;
 import org.apache.doris.nereids.types.BigIntType;
@@ -181,6 +182,11 @@ public class ColumnDefinition {
      * validate column definition and analyze
      */
     public void validate(boolean isOlap, Set<String> keysSet, boolean 
isEnableMergeOnWrite, KeysType keysType) {
+        try {
+            FeNameFormat.checkColumnName(name);
+        } catch (Exception e) {
+            throw new AnalysisException(e.getMessage(), e);
+        }
         validateDataType(type.toCatalogDataType());
         type = updateCharacterTypeLength(type);
         if (type.isArrayType()) {
diff --git 
a/regression-test/suites/nereids_p0/create_table/test_create_table.groovy 
b/regression-test/suites/nereids_p0/create_table/test_create_table.groovy
index cb3590b6f01..60a10270c18 100644
--- a/regression-test/suites/nereids_p0/create_table/test_create_table.groovy
+++ b/regression-test/suites/nereids_p0/create_table/test_create_table.groovy
@@ -42,4 +42,40 @@ suite("nereids_create_table") {
     for (String t in tables) {
         qt_sql "select * from ${t} order by id"
     }
+
+    test {
+        sql """
+            CREATE TABLE region  (
+                r_regionkey      int NOT NULL,
+                r_name       VARCHAR(25) NOT NULL,
+                `CAST(``o_custkey`` AS BIGINT)` VARCHAR(152)
+            )ENGINE=OLAP
+            DUPLICATE KEY(`r_regionkey`)
+            COMMENT "OLAP"
+            DISTRIBUTED BY HASH(`r_regionkey`) BUCKETS 1
+            PROPERTIES (
+                "replication_num" = "1" 
+            );
+        """
+
+        exception "Incorrect column name"
+    }
+
+    test {
+        sql """
+            CREATE TABLE region  (
+                r_regionkey      int NOT NULL,
+                r_name       VARCHAR(25) NOT NULL,
+                `mva_invalid` VARCHAR(152)
+            )ENGINE=OLAP
+            DUPLICATE KEY(`r_regionkey`)
+            COMMENT "OLAP"
+            DISTRIBUTED BY HASH(`r_regionkey`) BUCKETS 1
+            PROPERTIES (
+                "replication_num" = "1" 
+            );
+        """
+
+        exception "Incorrect column name"
+    }
 }


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

Reply via email to