This is an automated email from the ASF dual-hosted git repository.
dataroaring 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 d94ae20d4a1 [improvement](nereids) support insert into
doris_internal_table_id(xxx) (#25722)
d94ae20d4a1 is described below
commit d94ae20d4a1645994407733fc02c633621568b58
Author: zzzzzzzs <[email protected]>
AuthorDate: Wed Oct 25 11:12:00 2023 +0800
[improvement](nereids) support insert into doris_internal_table_id(xxx)
(#25722)
---
.../antlr4/org/apache/doris/nereids/DorisParser.g4 | 3 +-
.../doris/nereids/parser/LogicalPlanBuilder.java | 14 ++-
.../insert_into_table/insert_use_table_id.out | 48 +++++++++
.../org/apache/doris/regression/suite/Suite.groovy | 16 +++
.../insert_into_table/insert_use_table_id.groovy | 107 +++++++++++++++++++++
5 files changed, 186 insertions(+), 2 deletions(-)
diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
index 065117d3b0b..4c74e424e60 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
@@ -50,7 +50,8 @@ statement
(ROLLUP LEFT_PAREN rollupDefs RIGHT_PAREN)?
propertyClause?
(AS query)?
#createTable
- | explain? INSERT (INTO | OVERWRITE TABLE) tableName=multipartIdentifier
+ | explain? INSERT (INTO | OVERWRITE TABLE)
+ (tableName=multipartIdentifier | DORIS_INTERNAL_TABLE_ID LEFT_PAREN
tableId=INTEGER_VALUE RIGHT_PAREN)
(PARTITION partition=identifierList)? // partition define
(WITH LABEL labelName=identifier)? cols=identifierList? // label and
columns define
(LEFT_BRACKET hints=identifierSeq RIGHT_BRACKET)? // hint define
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index b817803f23c..49209dcd54e 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -20,8 +20,10 @@ package org.apache.doris.nereids.parser;
import org.apache.doris.analysis.ArithmeticExpr.Operator;
import org.apache.doris.analysis.BrokerDesc;
import org.apache.doris.analysis.StorageBackend;
+import org.apache.doris.analysis.TableName;
import org.apache.doris.analysis.UserIdentity;
import org.apache.doris.catalog.AggregateType;
+import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.KeysType;
import org.apache.doris.common.Config;
import org.apache.doris.common.FeConstants;
@@ -411,7 +413,17 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
@Override
public LogicalPlan visitInsertIntoQuery(InsertIntoQueryContext ctx) {
boolean isOverwrite = ctx.INTO() == null;
- List<String> tableName = visitMultipartIdentifier(ctx.tableName);
+ List<String> tableName = new ArrayList<>();
+ if (null != ctx.tableName) {
+ tableName = visitMultipartIdentifier(ctx.tableName);
+ } else if (null != ctx.tableId) {
+ TableName name = Env.getCurrentEnv().getInternalCatalog()
+
.getTableNameByTableId(Long.valueOf(ctx.tableId.getText()));
+ tableName.add(name.getDb());
+ tableName.add(name.getTbl());
+ } else {
+ throw new ParseException("tableName and tableId cannot both be
null");
+ }
String labelName = ctx.labelName == null ? null :
ctx.labelName.getText();
List<String> colNames = ctx.cols == null ? ImmutableList.of() :
visitIdentifierList(ctx.cols);
List<String> partitions = ctx.partition == null ? ImmutableList.of() :
visitIdentifierList(ctx.partition);
diff --git
a/regression-test/data/nereids_p0/insert_into_table/insert_use_table_id.out
b/regression-test/data/nereids_p0/insert_into_table/insert_use_table_id.out
new file mode 100644
index 00000000000..d0020443bf6
--- /dev/null
+++ b/regression-test/data/nereids_p0/insert_into_table/insert_use_table_id.out
@@ -0,0 +1,48 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !sql_cross_join --
+1 10 1 1 1.0 2000-01-01 1 10 10
10.0 2000-01-10 1
+1 10 1 1 1.0 2000-01-01 1 10 10
10.0 2000-01-10 4
+1 10 1 1 1.0 2000-01-01 1 10 10
10.0 2000-01-10 5
+1 10 1 1 1.0 2000-01-01 2 20 20
20.0 2000-01-20 1
+1 10 1 1 1.0 2000-01-01 2 20 20
20.0 2000-01-20 4
+1 10 1 1 1.0 2000-01-01 2 20 20
20.0 2000-01-20 5
+1 10 1 1 1.0 2000-01-01 3 30 30
30.0 2000-01-30 1
+1 10 1 1 1.0 2000-01-01 3 30 30
30.0 2000-01-30 4
+1 10 1 1 1.0 2000-01-01 3 30 30
30.0 2000-01-30 5
+1 10 1 1 1.0 2000-01-01 4 4 4
4.0 2000-01-04 1
+1 10 1 1 1.0 2000-01-01 4 4 4
4.0 2000-01-04 4
+1 10 1 1 1.0 2000-01-01 4 4 4
4.0 2000-01-04 5
+1 10 1 1 1.0 2000-01-01 5 5 5
5.0 2000-01-05 1
+1 10 1 1 1.0 2000-01-01 5 5 5
5.0 2000-01-05 4
+1 10 1 1 1.0 2000-01-01 5 5 5
5.0 2000-01-05 5
+2 20 2 2 2.0 2000-01-02 1 10 10
10.0 2000-01-10 1
+2 20 2 2 2.0 2000-01-02 1 10 10
10.0 2000-01-10 4
+2 20 2 2 2.0 2000-01-02 1 10 10
10.0 2000-01-10 5
+2 20 2 2 2.0 2000-01-02 2 20 20
20.0 2000-01-20 1
+2 20 2 2 2.0 2000-01-02 2 20 20
20.0 2000-01-20 4
+2 20 2 2 2.0 2000-01-02 2 20 20
20.0 2000-01-20 5
+2 20 2 2 2.0 2000-01-02 3 30 30
30.0 2000-01-30 1
+2 20 2 2 2.0 2000-01-02 3 30 30
30.0 2000-01-30 4
+2 20 2 2 2.0 2000-01-02 3 30 30
30.0 2000-01-30 5
+2 20 2 2 2.0 2000-01-02 4 4 4
4.0 2000-01-04 1
+2 20 2 2 2.0 2000-01-02 4 4 4
4.0 2000-01-04 4
+2 20 2 2 2.0 2000-01-02 4 4 4
4.0 2000-01-04 5
+2 20 2 2 2.0 2000-01-02 5 5 5
5.0 2000-01-05 1
+2 20 2 2 2.0 2000-01-02 5 5 5
5.0 2000-01-05 4
+2 20 2 2 2.0 2000-01-02 5 5 5
5.0 2000-01-05 5
+3 30 3 3 3.0 2000-01-03 1 10 10
10.0 2000-01-10 1
+3 30 3 3 3.0 2000-01-03 1 10 10
10.0 2000-01-10 4
+3 30 3 3 3.0 2000-01-03 1 10 10
10.0 2000-01-10 5
+3 30 3 3 3.0 2000-01-03 2 20 20
20.0 2000-01-20 1
+3 30 3 3 3.0 2000-01-03 2 20 20
20.0 2000-01-20 4
+3 30 3 3 3.0 2000-01-03 2 20 20
20.0 2000-01-20 5
+3 30 3 3 3.0 2000-01-03 3 30 30
30.0 2000-01-30 1
+3 30 3 3 3.0 2000-01-03 3 30 30
30.0 2000-01-30 4
+3 30 3 3 3.0 2000-01-03 3 30 30
30.0 2000-01-30 5
+3 30 3 3 3.0 2000-01-03 4 4 4
4.0 2000-01-04 1
+3 30 3 3 3.0 2000-01-03 4 4 4
4.0 2000-01-04 4
+3 30 3 3 3.0 2000-01-03 4 4 4
4.0 2000-01-04 5
+3 30 3 3 3.0 2000-01-03 5 5 5
5.0 2000-01-05 1
+3 30 3 3 3.0 2000-01-03 5 5 5
5.0 2000-01-05 4
+3 30 3 3 3.0 2000-01-03 5 5 5
5.0 2000-01-05 5
+
diff --git
a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
index 0b7bc659755..5065f0e3e39 100644
---
a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
+++
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
@@ -295,6 +295,22 @@ class Suite implements GroovyInterceptable {
return result;
}
+
+ long getTableId(String tableName) {
+ def dbInfo = sql "show proc '/dbs'"
+ for(List<Object> row : dbInfo) {
+ if (row[1].split(":")[1].equals(context.dbName)) {
+ def tbInfo = sql "show proc '/dbs/${row[0]}' "
+ for (List<Object> tb : tbInfo) {
+ if (tb[1].equals(tableName)) {
+ println(tb[0])
+ return tb[0].toLong()
+ }
+ }
+ }
+ }
+ }
+
List<List<Object>> order_sql(String sqlStr) {
return sql(sqlStr, true)
}
diff --git
a/regression-test/suites/nereids_p0/insert_into_table/insert_use_table_id.groovy
b/regression-test/suites/nereids_p0/insert_into_table/insert_use_table_id.groovy
new file mode 100644
index 00000000000..930fe35b60e
--- /dev/null
+++
b/regression-test/suites/nereids_p0/insert_into_table/insert_use_table_id.groovy
@@ -0,0 +1,107 @@
+// 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('nereids_insert_use_table_id') {
+ sql 'set enable_nereids_planner=true'
+ sql 'set enable_fallback_to_original_planner=false'
+ sql 'set enable_nereids_dml=true'
+ sql 'set enable_strict_consistency_dml=true'
+
+ // sql 'CREATE DATABASE IF NOT EXISTS dnereids_insert_use_table_id_test'
+ // sql 'use nereids_insert_use_table_id_test'
+
+ def t1 = 'table_id_value_t1'
+ def t2 = 'table_id_value_t2'
+ def t3 = 'table_id_value_t3'
+
+ sql "drop table if exists ${t1}"
+ sql "drop table if exists ${t2}"
+ sql "drop table if exists ${t3}"
+
+ sql """
+ create table ${t1} (
+ id int,
+ id1 int,
+ c1 bigint,
+ c2 string,
+ c3 double,
+ c4 date
+ ) unique key (id, id1)
+ distributed by hash(id, id1) buckets 13
+ properties(
+ 'replication_num'='1',
+ "function_column.sequence_col" = "c4"
+ );
+ """
+
+ sql """
+ create table ${t2} (
+ id int,
+ c1 bigint,
+ c2 string,
+ c3 double,
+ c4 date
+ ) unique key (id)
+ distributed by hash(id) buckets 13
+ properties(
+ 'replication_num'='1'
+ );
+ """
+
+ sql """
+ create table ${t3} (
+ id int
+ ) distributed by hash(id) buckets 13
+ properties(
+ 'replication_num'='1'
+ );
+ """
+
+
+ sql """
+ INSERT INTO DORIS_INTERNAL_TABLE_ID(${getTableId(t1)}) VALUES
+ (1, (1 + 9) * (10 - 9), 1, '1', 1.0, '2000-01-01'),
+ (2, 20, 2, '2', 2.0, days_add('2000-01-01', 1)),
+ (3, 30, 3, '3', 3.0, makedate(2000, 3));
+ """
+
+ sql """
+ INSERT INTO DORIS_INTERNAL_TABLE_ID(${getTableId(t2)}) VALUES
+ (1, 10, '10', 10.0, '2000-01-10'),
+ (2, 20, '20', 20.0, '2000-01-20'),
+ (3, 30, '30', 30.0, '2000-01-30'),
+ (4, 4, '4', 4.0, '2000-01-04'),
+ (5, 5, '5', 5.0, '2000-01-05');
+ """
+
+ sql """
+ INSERT INTO DORIS_INTERNAL_TABLE_ID(${getTableId(t3)}) VALUES
+ (1),
+ (4),
+ (5);
+ """
+
+ sql "sync"
+ qt_sql_cross_join "select * from ${t1}, ${t2}, ${t3} order by ${t1}.id,
${t1}.id1, ${t2}.id, ${t3}.id"
+
+
+}
+
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]