Skip to content

Commit

Permalink
Support super sql parser 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
lingo-xp authored and wenshao committed Jan 6, 2025
1 parent 1e5344b commit cf1dc39
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
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) {
super(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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 ");
}
}
31 changes: 28 additions & 3 deletions core/src/test/resources/bvt/parser/supersql/0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
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
);

0 comments on commit cf1dc39

Please sign in to comment.