Skip to content

Commit 4682c4a

Browse files
branch-4.0: [fix](parser) fix DELETE/UPDATE cannot resolve column when table alias uses AS keyword #60335 (#60402)
Cherry-picked from #60335 Co-authored-by: minghong <[email protected]>
1 parent 01646a9 commit 4682c4a

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,7 @@ public LogicalPlan visitUpdate(UpdateContext ctx) {
19161916
query = withFilter(query, Optional.ofNullable(ctx.whereClause()));
19171917
String tableAlias = null;
19181918
if (ctx.tableAlias().strictIdentifier() != null) {
1919-
tableAlias = ctx.tableAlias().getText();
1919+
tableAlias = ctx.tableAlias().strictIdentifier().getText();
19201920
}
19211921
Optional<LogicalPlan> cte = Optional.empty();
19221922
if (ctx.cte() != null) {
@@ -1941,7 +1941,7 @@ public LogicalPlan visitDelete(DeleteContext ctx) {
19411941
);
19421942
String tableAlias = null;
19431943
if (ctx.tableAlias().strictIdentifier() != null) {
1944-
tableAlias = ctx.tableAlias().getText();
1944+
tableAlias = ctx.tableAlias().strictIdentifier().getText();
19451945
}
19461946

19471947
Command deleteCommand;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
suite("deleteFromUsing") {
19+
sql """ DROP TABLE IF EXISTS d_table; """
20+
21+
sql """
22+
create table d_table(
23+
k1 int null,
24+
k2 int not null,
25+
k3 bigint null,
26+
k4 varchar(100) null
27+
)
28+
unique key (k1,k2,k3)
29+
distributed BY hash(k1) buckets 3
30+
properties("replication_num" = "1");
31+
"""
32+
33+
sql "insert into d_table select 1,1,1,'a';"
34+
sql "insert into d_table select 2,2,2,'b';"
35+
36+
37+
sql "set dry_run_query=true;"
38+
39+
// fix DELETE/UPDATE cannot resolve column when table alias uses AS keyword
40+
41+
// When using 'DELETE FROM table AS t1', the tableAlias was incorrectly
42+
// set to 'AS t1' instead of 't1', causing column resolution to fail
43+
// in subqueries. Changed to use strictIdentifier().getText() to get
44+
// only the identifier part.
45+
sql """
46+
delete from d_table as t1
47+
using d_table as t2
48+
where t2.k2 = 2
49+
and t1.k1 = t2.k1;
50+
"""
51+
}

0 commit comments

Comments
 (0)