diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlCreateTableParser.java b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlCreateTableParser.java index afb45da3d9..e6b58ed853 100644 --- a/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlCreateTableParser.java +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlCreateTableParser.java @@ -1,9 +1,11 @@ package com.alibaba.druid.sql.dialect.supersql.parser; +import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition; import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement; import com.alibaba.druid.sql.dialect.presto.parser.PrestoCreateTableParser; +import com.alibaba.druid.sql.parser.ParserException; import com.alibaba.druid.sql.parser.SQLExprParser; -import com.alibaba.druid.util.FnvHash; +import com.alibaba.druid.sql.parser.Token; public class SuperSqlCreateTableParser extends PrestoCreateTableParser { public SuperSqlCreateTableParser(SQLExprParser exprParser) { @@ -11,8 +13,33 @@ public SuperSqlCreateTableParser(SQLExprParser exprParser) { } @Override - protected void createTableBefore(SQLCreateTableStatement stmt) { - acceptIdentifier(FnvHash.Constants.EXTERNAL); - stmt.setExternal(true); + protected void parseCreateTableRest(SQLCreateTableStatement stmt) { + if (lexer.nextIf(Token.PARTITIONED)) { + accept(Token.BY); + accept(Token.LPAREN); + for (; ; ) { + if (lexer.token() != Token.IDENTIFIER) { + throw new ParserException("expect identifier. " + lexer.info()); + } + + SQLColumnDefinition column = this.exprParser.parseColumn(); + stmt.addPartitionColumn(column); + + if (lexer.isKeepComments() && lexer.hasComment()) { + column.addAfterComment(lexer.readAndResetComments()); + } + + if (lexer.token() != Token.COMMA) { + break; + } else { + lexer.nextToken(); + if (lexer.isKeepComments() && lexer.hasComment()) { + column.addAfterComment(lexer.readAndResetComments()); + } + } + } + accept(Token.RPAREN); + } + super.parseCreateTableRest(stmt); } } diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlLexer.java b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlLexer.java index 5f5c351c9a..9e9a291b0e 100644 --- a/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlLexer.java +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlLexer.java @@ -29,6 +29,7 @@ protected Keywords loadKeywords() { map.put("IF", Token.IF); map.put("OVERWRITE", Token.OVERWRITE); map.put("PARTITION", Token.PARTITION); + map.put("PARTITIONED", Token.PARTITIONED); return new Keywords(map); } diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/visitor/SuperSqlOutputVisitor.java b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/visitor/SuperSqlOutputVisitor.java index 330b546b4e..0b82213606 100644 --- a/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/visitor/SuperSqlOutputVisitor.java +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/visitor/SuperSqlOutputVisitor.java @@ -1,6 +1,7 @@ package com.alibaba.druid.sql.dialect.supersql.visitor; import com.alibaba.druid.DbType; +import com.alibaba.druid.sql.ast.statement.SQLInsertStatement; import com.alibaba.druid.sql.dialect.presto.visitor.PrestoOutputVisitor; public class SuperSqlOutputVisitor extends PrestoOutputVisitor implements SuperSqlASTVisitor { @@ -11,4 +12,9 @@ public SuperSqlOutputVisitor(StringBuilder appender) { public SuperSqlOutputVisitor(StringBuilder appender, boolean parameterized) { super(appender, DbType.supersql, parameterized); } + + @Override + public void printInsertOverWrite(SQLInsertStatement x) { + print0(ucase ? "INSERT OVERWRITE TABLE " : "insert overwrite table "); + } } diff --git a/core/src/test/resources/bvt/parser/supersql/0.txt b/core/src/test/resources/bvt/parser/supersql/0.txt index acc54e098c..3cdccafa73 100644 --- a/core/src/test/resources/bvt/parser/supersql/0.txt +++ b/core/src/test/resources/bvt/parser/supersql/0.txt @@ -37,7 +37,7 @@ select FROM click t1 full join play_res t2 on t1.pd_uid = t2.pd_uid -------------------- -INSERT OVERWRITE a PARTITION (ymd = '${DATE_1D}') +INSERT OVERWRITE TABLE a PARTITION (ymd = '${DATE_1D}') SELECT nvl(t1.pd_uid, t2.pd_uid) AS uuid , nvl(t1.user_click_game_7d_cnt, 0) AS user_click_game_7d_cnt , nvl(t2.user_playtime_1d, 0.0) AS user_playtime_1d @@ -59,7 +59,7 @@ select t1.ymd ,login_dnu_gpark from b -------------------- -INSERT OVERWRITE a PARTITION (ymd) +INSERT OVERWRITE TABLE a PARTITION (ymd) SELECT t1.ymd, launcher_download_dnu, launcher_install_dnu, editor_install_dnu, gpark_install_dnu , pge_install_dnu, login_dnu, login_dnu_addr, login_dnu_gpark FROM b @@ -79,4 +79,29 @@ from b INSERT INTO a PARTITION (ymd) SELECT t1.ymd, launcher_download_dnu, launcher_install_dnu, editor_install_dnu, gpark_install_dnu , pge_install_dnu, login_dnu, login_dnu_addr, login_dnu_gpark -FROM b \ No newline at end of file +FROM b +------------------------------------------------------------------------------------------------------------------------ +create table if not exists gpark_dwd.dwd_game_review_publish_success_ios +( + imei_type string COMMENT '平台级新老' + ,imei_type_game string COMMENT '游戏级新老' + ,pd_country_en string COMMENT '国家名称(英文)' + ,pd_device_id string COMMENT '设备id' + ,gameid string COMMENT '游戏id' + ,game_tag string COMMENT '游戏类型pgc/ugc' + ,reviewtype bigint COMMENT '评论级别' +) partitioned by (ymd string) +; +-------------------- +CREATE TABLE IF NOT EXISTS gpark_dwd.dwd_game_review_publish_success_ios ( + imei_type string COMMENT '平台级新老', + imei_type_game string COMMENT '游戏级新老', + pd_country_en string COMMENT '国家名称(英文)', + pd_device_id string COMMENT '设备id', + gameid string COMMENT '游戏id', + game_tag string COMMENT '游戏类型pgc/ugc', + reviewtype bigint COMMENT '评论级别' +) +PARTITIONED BY ( + ymd string +); \ No newline at end of file