From 847898bf268edd77d52893515fcff1fb6d699176 Mon Sep 17 00:00:00 2001 From: morrySnow <101034200+morrySnow@users.noreply.github.com> Date: Mon, 8 Jan 2024 15:13:59 +0800 Subject: [PATCH] [fix](Nereids) delete using should support sql without where (#29518) --- .../src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 | 2 +- .../org/apache/doris/nereids/parser/LogicalPlanBuilder.java | 4 ++-- regression-test/suites/delete_p0/test_delete_on_mor.groovy | 6 +++--- 3 files changed, 6 insertions(+), 6 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 7159350556..5ce755eb39 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 @@ -65,7 +65,7 @@ statement | explain? cte? DELETE FROM tableName=multipartIdentifier partitionSpec? tableAlias (USING relation (COMMA relation)*)? - whereClause #delete + whereClause? #delete | LOAD LABEL lableName=identifier LEFT_PAREN dataDescs+=dataDesc (COMMA dataDescs+=dataDesc)* RIGHT_PAREN (withRemoteStorageSystem)? 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 5bfc465b30..f13cc8b69c 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 @@ -809,12 +809,12 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor { tableAlias = ctx.tableAlias().getText(); } if (ctx.USING() == null && ctx.cte() == null && ctx.explain() == null) { - query = withFilter(query, Optional.of(ctx.whereClause())); + query = withFilter(query, Optional.ofNullable(ctx.whereClause())); return new DeleteFromCommand(tableName, tableAlias, partitionSpec.first, partitionSpec.second, query); } else { // convert to insert into select query = withRelations(query, ctx.relation()); - query = withFilter(query, Optional.of(ctx.whereClause())); + query = withFilter(query, Optional.ofNullable(ctx.whereClause())); Optional cte = Optional.empty(); if (ctx.cte() != null) { cte = Optional.ofNullable(withCte(query, ctx.cte())); diff --git a/regression-test/suites/delete_p0/test_delete_on_mor.groovy b/regression-test/suites/delete_p0/test_delete_on_mor.groovy index 3388356e6e..71b5b15712 100644 --- a/regression-test/suites/delete_p0/test_delete_on_mor.groovy +++ b/regression-test/suites/delete_p0/test_delete_on_mor.groovy @@ -89,14 +89,14 @@ suite("test_delete_on_mor") { sql "sync;" qt_sql "select * from ${tableA} order by user_id;" - sql """DELETE from ${tableA} USING ${tableA} a - JOIN ( + sql """DELETE from ${tableA} USING + ( SELECT a.user_id, a.city FROM ${tableA} a JOIN ${tableB} ON a.user_id = ${tableB}.user_id AND a.city = ${tableB}.city WHERE ${tableB}.city = '上海' AND ${tableB}.age = 20 ) AS matched_rows - ON ${tableA}.user_id = matched_rows.user_id AND ${tableA}.city = matched_rows.city; """ + WHERE ${tableA}.user_id = matched_rows.user_id AND ${tableA}.city = matched_rows.city; """ qt_sql "select * from ${tableA} order by user_id;" sql "DROP TABLE IF EXISTS ${tableA};"