Skip to content

Commit

Permalink
impala parser support upsert followed by with clause
Browse files Browse the repository at this point in the history
  • Loading branch information
woyumen4597 committed Sep 9, 2024
1 parent ab57847 commit 1b76d73
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
import com.alibaba.druid.sql.dialect.hive.parser.HiveLexer;
import com.alibaba.druid.sql.parser.Keywords;
import com.alibaba.druid.sql.parser.SQLParserFeature;
import com.alibaba.druid.sql.parser.Token;

import java.util.Map;

public class ImpalaLexer extends HiveLexer {
@Override
protected Keywords loadKeywords() {
return super.loadKeywords();
Keywords keywords = super.loadKeywords();
Map<String, Token> map = keywords.getKeywords();
map.put("UPSERT", Token.UPSERT);
return new Keywords(map);
}

public ImpalaLexer(String input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5826,6 +5826,10 @@ public SQLStatement parseWith() {
SQLInsertStatement insert = (SQLInsertStatement) this.parseInsert();
insert.setWith(with);
stmt = insert;
} else if (lexer.token == Token.UPSERT) {
SQLInsertStatement insert = (SQLInsertStatement) this.parseUpsert();
insert.setWith(with);
stmt = insert;
} else if (lexer.token == Token.FROM) {
HiveMultiInsertStatement insert = (HiveMultiInsertStatement) this.parseInsert();
insert.setWith(with);
Expand Down
12 changes: 11 additions & 1 deletion core/src/test/resources/bvt/parser/impala/5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ UPSERT [SHUFFLE] INTO production_table
[NOSHUFFLE] SELECT *
FROM staging_table
WHERE c1 IS NOT NULL
AND c2 > 0;
AND c2 > 0;
------------------------------------------------------------------------------------------------------------------------
with tmp as (select c,d from prj1.kudu_table2) upsert into prj1.kudu_table select * from tmp
--------------------
WITH tmp AS (
SELECT c, d
FROM prj1.kudu_table2
)
UPSERT INTO prj1.kudu_table
SELECT *
FROM tmp

0 comments on commit 1b76d73

Please sign in to comment.