You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2023/06/18 11:56:13 UTC

[doris] branch master updated: [enhancement](insert-stmt) Make `insert into tbl values();` compatible with mysql (#20694)

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

yiguolei 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 8366ce7a81 [enhancement](insert-stmt) Make `insert into tbl values();` compatible with mysql (#20694)
8366ce7a81 is described below

commit 8366ce7a813bcb8c93c1724e84c3ba3d682e5070
Author: Siyang Tang <82...@users.noreply.github.com>
AuthorDate: Sun Jun 18 19:56:07 2023 +0800

    [enhancement](insert-stmt) Make `insert into tbl values();` compatible with mysql (#20694)
---
 .../apache/doris/analysis/NativeInsertStmt.java    | 19 ++++++++++
 .../data/load_p0/insert/test_insert.out            |  4 +++
 .../suites/load_p0/insert/test_insert.groovy       | 40 ++++++++++++++++++++++
 3 files changed, 63 insertions(+)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java
index 3a64357c9a..d3956de245 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java
@@ -64,6 +64,7 @@ import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -498,6 +499,24 @@ public class NativeInsertStmt extends InsertStmt {
         queryStmt.setFromInsert(true);
         queryStmt.analyze(analyzer);
 
+        // deal with this case: insert into tbl values();
+        // should try to insert default values for all columns in tbl if set
+        if (isValuesOrConstantSelect) {
+            final ValueList valueList = ((SelectStmt) queryStmt).getValueList();
+            if (valueList != null && valueList.getFirstRow().isEmpty() && CollectionUtils.isEmpty(targetColumnNames)) {
+                final int rowSize = mentionedColumns.size();
+                final List<String> colLabels = queryStmt.getColLabels();
+                final List<Expr> resultExprs = queryStmt.getResultExprs();
+                Preconditions.checkState(resultExprs.isEmpty(), "result exprs should be empty.");
+                for (int i = 0; i < rowSize; i++) {
+                    resultExprs.add(new IntLiteral(1));
+                    final DefaultValueExpr defaultValueExpr = new DefaultValueExpr();
+                    valueList.getFirstRow().add(defaultValueExpr);
+                    colLabels.add(defaultValueExpr.toColumnLabel());
+                }
+            }
+        }
+
         // check if size of select item equal with columns mentioned in statement
         if (mentionedColumns.size() != queryStmt.getResultExprs().size()
                 || realTargetColumnNames.size() != queryStmt.getResultExprs().size()) {
diff --git a/regression-test/data/load_p0/insert/test_insert.out b/regression-test/data/load_p0/insert/test_insert.out
index 68d12c992f..dcb5b854a7 100644
--- a/regression-test/data/load_p0/insert/test_insert.out
+++ b/regression-test/data/load_p0/insert/test_insert.out
@@ -11,3 +11,7 @@ true	3021	10	15
 true	25699	6	21
 true	2147483647	3	24
 
+-- !select --
+true	10	10000	10000000	92233720368547758	19223372036854775807	3.14159	hello world, today is 15/06/2023	2023-06-15	2023-06-15T16:10:15
+true	10	10000	10000000	92233720368547758	19223372036854775807	3.14159	hello world, today is 15/06/2023	2023-06-15	2023-06-15T16:10:15
+
diff --git a/regression-test/suites/load_p0/insert/test_insert.groovy b/regression-test/suites/load_p0/insert/test_insert.groovy
index 27a9f66992..1ab035d653 100644
--- a/regression-test/suites/load_p0/insert/test_insert.groovy
+++ b/regression-test/suites/load_p0/insert/test_insert.groovy
@@ -48,4 +48,44 @@ suite("test_insert") {
     """
 
     qt_sql1 "select * from ${insert_tbl} order by 1, 2, 3, 4"
+
+    def insert_tbl_dft = "test_insert_dft_tbl"
+    sql """ DROP TABLE IF EXISTS ${insert_tbl_dft}"""
+    
+    // `k7` should be float type, and bug exists now, https://github.com/apache/doris/pull/20867
+    // `k9` should be char(16), and bug exists now as error msg raised:"can not cast from origin type TINYINT to target type=CHAR(16)" when doing insert
+    // "`k13` datetime default CURRENT_TIMESTAMP" might have cast error in strict mode when doing insert:
+    // [INTERNAL_ERROR]Invalid value in strict mode for function CAST, source column String, from type String to type DateTimeV2
+    sql """
+        CREATE TABLE ${insert_tbl_dft} (
+            `k1` boolean default "true",
+            `k2` tinyint default "10",
+            `k3` smallint default "10000",
+            `k4` int default "10000000",
+            `k5` bigint default "92233720368547758",
+            `k6` largeint default "19223372036854775807",
+            	  
+            `k8` double default "3.14159",
+
+            `k10` varchar(64) default "hello world, today is 15/06/2023",
+            `k11` date default "2023-06-15",
+            `k12` datetime default "2023-06-15 16:10:15" 
+        ) ENGINE=OLAP
+        DUPLICATE KEY(`k1`)
+        COMMENT 'OLAP'
+        DISTRIBUTED BY HASH(`k1`) BUCKETS 5
+        PROPERTIES (
+            "replication_num"="1"
+        );
+    """
+    
+    sql """ set enable_nereids_planner=true """
+    sql """ set enable_nereids_dml=true """
+    sql """ insert into ${insert_tbl_dft} values() """
+
+    sql """ set enable_nereids_planner=false """
+    sql """ set enable_nereids_dml=false """
+    sql """ insert into ${insert_tbl_dft} values() """
+    
+    qt_select """ select k1,k2,k3,k4,k5,k6,k8,k10,k11,k12 from ${insert_tbl_dft} """
 }


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