[fix](Nereids) delete using should support sql without where (#29518)

This commit is contained in:
morrySnow
2024-01-08 15:13:59 +08:00
committed by yiguolei
parent ddaa645a4f
commit 847898bf26
3 changed files with 6 additions and 6 deletions

View File

@ -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)?

View File

@ -809,12 +809,12 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
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<LogicalPlan> cte = Optional.empty();
if (ctx.cte() != null) {
cte = Optional.ofNullable(withCte(query, ctx.cte()));

View File

@ -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};"