diff --git a/core/src/main/java/com/alibaba/druid/sql/SQLUtils.java b/core/src/main/java/com/alibaba/druid/sql/SQLUtils.java index 785ce714ff..cb832ae635 100644 --- a/core/src/main/java/com/alibaba/druid/sql/SQLUtils.java +++ b/core/src/main/java/com/alibaba/druid/sql/SQLUtils.java @@ -68,6 +68,7 @@ import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerOutputVisitor; import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor; import com.alibaba.druid.sql.dialect.starrocks.visitor.StarRocksOutputVisitor; +import com.alibaba.druid.sql.dialect.supersql.visitor.SuperSqlOutputVisitor; import com.alibaba.druid.sql.dialect.teradata.visitor.TDOutputVisitor; import com.alibaba.druid.sql.parser.*; import com.alibaba.druid.sql.repository.SchemaRepository; @@ -568,8 +569,9 @@ public static SQLASTOutputVisitor createFormatOutputVisitor( return new SparkOutputVisitor(out); case presto: case trino: - case supersql: return new PrestoOutputVisitor(out); + case supersql: + return new SuperSqlOutputVisitor(out); case athena: return new AthenaOutputVisitor(out); case clickhouse: diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaCreateTableParser.java b/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaCreateTableParser.java index 471cc07cac..7ae1455da7 100644 --- a/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaCreateTableParser.java +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaCreateTableParser.java @@ -1,6 +1,5 @@ package com.alibaba.druid.sql.dialect.athena.parser; -import com.alibaba.druid.DbType; import com.alibaba.druid.sql.ast.SQLExpr; import com.alibaba.druid.sql.ast.SQLName; import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition; @@ -16,14 +15,8 @@ import com.alibaba.druid.util.FnvHash; public class AthenaCreateTableParser extends PrestoCreateTableParser { - public AthenaCreateTableParser(String sql) { - super(sql); - this.dbType = DbType.athena; - } - public AthenaCreateTableParser(SQLExprParser exprParser) { super(exprParser); - this.dbType = DbType.athena; } @Override diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaExprParser.java b/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaExprParser.java index 550854a3eb..f5c5cfddda 100644 --- a/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaExprParser.java +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaExprParser.java @@ -7,12 +7,11 @@ public class AthenaExprParser extends PrestoExprParser { public AthenaExprParser(String sql, SQLParserFeature... features) { - super(sql, features); - this.dbType = DbType.athena; + this(new AthenaLexer(sql, features)); + this.lexer.nextToken(); } public AthenaExprParser(Lexer lexer) { - super(lexer); - this.dbType = DbType.athena; + super(lexer, DbType.athena); } } diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaLexer.java b/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaLexer.java index 7f5c8db97b..54e268fb97 100644 --- a/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaLexer.java +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaLexer.java @@ -6,7 +6,6 @@ public class AthenaLexer extends PrestoLexer { public AthenaLexer(String input, SQLParserFeature... features) { - super(input, features); - this.dbType = DbType.athena; + super(input, DbType.athena, features); } } diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaSelectParser.java b/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaSelectParser.java index c9178fd993..c10aeef005 100644 --- a/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaSelectParser.java +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaSelectParser.java @@ -1,24 +1,12 @@ package com.alibaba.druid.sql.dialect.athena.parser; -import com.alibaba.druid.DbType; import com.alibaba.druid.sql.dialect.presto.parser.PrestoSelectParser; import com.alibaba.druid.sql.parser.SQLExprParser; import com.alibaba.druid.sql.parser.SQLSelectListCache; public class AthenaSelectParser extends PrestoSelectParser { - public AthenaSelectParser(SQLExprParser exprParser) { - super(exprParser); - this.dbType = DbType.athena; - } - public AthenaSelectParser(SQLExprParser exprParser, SQLSelectListCache selectListCache) { super(exprParser, selectListCache); - this.dbType = DbType.athena; - } - - public AthenaSelectParser(String sql) { - super(sql); - this.dbType = DbType.athena; } @Override diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaStatementParser.java b/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaStatementParser.java index 9535fc17ac..eddc14d9b1 100644 --- a/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaStatementParser.java +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/athena/parser/AthenaStatementParser.java @@ -1,25 +1,12 @@ package com.alibaba.druid.sql.dialect.athena.parser; -import com.alibaba.druid.DbType; import com.alibaba.druid.sql.dialect.presto.parser.PrestoStatementParser; -import com.alibaba.druid.sql.parser.Lexer; import com.alibaba.druid.sql.parser.SQLCreateTableParser; import com.alibaba.druid.sql.parser.SQLParserFeature; public class AthenaStatementParser extends PrestoStatementParser { - public AthenaStatementParser(String sql) { - super(sql); - this.dbType = DbType.athena; - } - public AthenaStatementParser(String sql, SQLParserFeature... features) { - super(sql, features); - this.dbType = DbType.athena; - } - - public AthenaStatementParser(Lexer lexer) { - super(lexer); - this.dbType = DbType.athena; + super(new AthenaExprParser(sql, features)); } @Override diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/athena/visitor/AthenaOutputVisitor.java b/core/src/main/java/com/alibaba/druid/sql/dialect/athena/visitor/AthenaOutputVisitor.java index 3c65f08944..b73900d43e 100644 --- a/core/src/main/java/com/alibaba/druid/sql/dialect/athena/visitor/AthenaOutputVisitor.java +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/athena/visitor/AthenaOutputVisitor.java @@ -7,13 +7,11 @@ public class AthenaOutputVisitor extends PrestoOutputVisitor implements AthenaASTVisitor { public AthenaOutputVisitor(StringBuilder appender) { - super(appender); - dbType = DbType.athena; + super(appender, DbType.athena); } public AthenaOutputVisitor(StringBuilder appender, boolean parameterized) { - super(appender, parameterized); - dbType = DbType.athena; + super(appender, DbType.athena, parameterized); } protected void printCreateTable(SQLCreateTableStatement x, boolean printSelect) { diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/presto/parser/PrestoExprParser.java b/core/src/main/java/com/alibaba/druid/sql/dialect/presto/parser/PrestoExprParser.java index 8896ff07c4..358ae489f0 100644 --- a/core/src/main/java/com/alibaba/druid/sql/dialect/presto/parser/PrestoExprParser.java +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/presto/parser/PrestoExprParser.java @@ -67,13 +67,16 @@ public PrestoExprParser(String sql, SQLParserFeature... features) { this.lexer.nextToken(); } - public PrestoExprParser(Lexer lexer) { - super(lexer); - dbType = DbType.presto; + public PrestoExprParser(Lexer lexer, DbType dbType) { + super(lexer, dbType); this.aggregateFunctions = AGGREGATE_FUNCTIONS; this.aggregateFunctionHashCodes = AGGREGATE_FUNCTIONS_CODES; } + public PrestoExprParser(Lexer lexer) { + this(lexer, DbType.presto); + } + @Override protected SQLColumnDefinition parseColumnSpecific(SQLColumnDefinition column) { if (lexer.token() == Token.WITH) { diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/presto/parser/PrestoLexer.java b/core/src/main/java/com/alibaba/druid/sql/dialect/presto/parser/PrestoLexer.java index d179d406a2..0ffb28c34a 100644 --- a/core/src/main/java/com/alibaba/druid/sql/dialect/presto/parser/PrestoLexer.java +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/presto/parser/PrestoLexer.java @@ -36,14 +36,16 @@ protected Keywords loadKeywords() { return new Keywords(map); } - public PrestoLexer(String input, SQLParserFeature... features) { - super(input); - this.dbType = DbType.presto; + public PrestoLexer(String input, DbType dbType, SQLParserFeature... features) { + super(input, dbType); for (SQLParserFeature feature : features) { config(feature, true); } } + public PrestoLexer(String input, SQLParserFeature... features) { + this(input, DbType.presto, features); + } @Override protected void initDialectFeature() { super.initDialectFeature(); diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/presto/parser/PrestoStatementParser.java b/core/src/main/java/com/alibaba/druid/sql/dialect/presto/parser/PrestoStatementParser.java index 5adb435cb7..81d8e32c2d 100644 --- a/core/src/main/java/com/alibaba/druid/sql/dialect/presto/parser/PrestoStatementParser.java +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/presto/parser/PrestoStatementParser.java @@ -47,6 +47,7 @@ import com.alibaba.druid.sql.parser.Lexer; import com.alibaba.druid.sql.parser.ParserException; import com.alibaba.druid.sql.parser.SQLCreateTableParser; +import com.alibaba.druid.sql.parser.SQLExprParser; import com.alibaba.druid.sql.parser.SQLParserFeature; import com.alibaba.druid.sql.parser.SQLSelectParser; import com.alibaba.druid.sql.parser.SQLStatementParser; @@ -66,10 +67,13 @@ public class PrestoStatementParser extends SQLStatementParser { public PrestoStatementParser(String sql) { super(new PrestoExprParser(sql)); } - public PrestoStatementParser(String sql, SQLParserFeature... features) { + public PrestoStatementParser(String sql, SQLParserFeature... features) { super(new PrestoExprParser(sql, features)); } + public PrestoStatementParser(SQLExprParser exprParser) { + super(exprParser); + } public PrestoStatementParser(Lexer lexer) { super(new PrestoExprParser(lexer)); } diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/presto/visitor/PrestoOutputVisitor.java b/core/src/main/java/com/alibaba/druid/sql/dialect/presto/visitor/PrestoOutputVisitor.java index f5cd4d3bcb..f6fcddc65b 100644 --- a/core/src/main/java/com/alibaba/druid/sql/dialect/presto/visitor/PrestoOutputVisitor.java +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/presto/visitor/PrestoOutputVisitor.java @@ -40,11 +40,19 @@ */ public class PrestoOutputVisitor extends SQLASTOutputVisitor implements PrestoASTVisitor { public PrestoOutputVisitor(StringBuilder appender) { - super(appender, DbType.presto); + this(appender, DbType.presto); + } + + public PrestoOutputVisitor(StringBuilder appender, DbType dbType) { + super(appender, dbType); } public PrestoOutputVisitor(StringBuilder appender, boolean parameterized) { - super(appender, DbType.presto, parameterized); + this(appender, DbType.presto, parameterized); + } + + public PrestoOutputVisitor(StringBuilder appender, DbType dbType, boolean parameterized) { + super(appender, dbType, parameterized); } @Override diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/ast/SuperSqlObject.java b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/ast/SuperSqlObject.java new file mode 100644 index 0000000000..e8f2f0289c --- /dev/null +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/ast/SuperSqlObject.java @@ -0,0 +1,16 @@ +package com.alibaba.druid.sql.dialect.supersql.ast; + +import com.alibaba.druid.sql.ast.SQLObject; +import com.alibaba.druid.sql.dialect.supersql.visitor.SuperSqlASTVisitor; +import com.alibaba.druid.sql.visitor.SQLASTVisitor; + +public interface SuperSqlObject extends SQLObject { + void accept0(SuperSqlASTVisitor visitor); + + @Override + default void accept(SQLASTVisitor visitor) { + if (visitor instanceof SuperSqlASTVisitor) { + accept0((SuperSqlASTVisitor) visitor); + } + } +} 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 new file mode 100644 index 0000000000..afb45da3d9 --- /dev/null +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlCreateTableParser.java @@ -0,0 +1,18 @@ +package com.alibaba.druid.sql.dialect.supersql.parser; + +import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement; +import com.alibaba.druid.sql.dialect.presto.parser.PrestoCreateTableParser; +import com.alibaba.druid.sql.parser.SQLExprParser; +import com.alibaba.druid.util.FnvHash; + +public class SuperSqlCreateTableParser extends PrestoCreateTableParser { + public SuperSqlCreateTableParser(SQLExprParser exprParser) { + super(exprParser); + } + + @Override + protected void createTableBefore(SQLCreateTableStatement stmt) { + acceptIdentifier(FnvHash.Constants.EXTERNAL); + stmt.setExternal(true); + } +} diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlExprParser.java b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlExprParser.java new file mode 100644 index 0000000000..f9eb88ef38 --- /dev/null +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlExprParser.java @@ -0,0 +1,17 @@ +package com.alibaba.druid.sql.dialect.supersql.parser; + +import com.alibaba.druid.DbType; +import com.alibaba.druid.sql.dialect.presto.parser.PrestoExprParser; +import com.alibaba.druid.sql.parser.Lexer; +import com.alibaba.druid.sql.parser.SQLParserFeature; + +public class SuperSqlExprParser extends PrestoExprParser { + public SuperSqlExprParser(String sql, SQLParserFeature... features) { + this(new SuperSqlLexer(sql, features)); + this.lexer.nextToken(); + } + + public SuperSqlExprParser(Lexer lexer) { + super(lexer, DbType.supersql); + } +} 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 new file mode 100644 index 0000000000..5f5c351c9a --- /dev/null +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlLexer.java @@ -0,0 +1,39 @@ +package com.alibaba.druid.sql.dialect.supersql.parser; + +import com.alibaba.druid.DbType; +import com.alibaba.druid.sql.dialect.presto.parser.PrestoLexer; +import com.alibaba.druid.sql.parser.Keywords; +import com.alibaba.druid.sql.parser.SQLParserFeature; +import com.alibaba.druid.sql.parser.Token; + +import java.util.HashMap; +import java.util.Map; + +public class SuperSqlLexer extends PrestoLexer { + @Override + protected Keywords loadKeywords() { + Map map = new HashMap(); + map.putAll(Keywords.DEFAULT_KEYWORDS.getKeywords()); + map.put("FETCH", Token.FETCH); + map.put("FIRST", Token.FIRST); + map.put("ONLY", Token.ONLY); + map.put("OPTIMIZE", Token.OPTIMIZE); + map.put("OF", Token.OF); + map.put("CONCAT", Token.CONCAT); + map.put("CONTINUE", Token.CONTINUE); + map.put("IDENTITY", Token.IDENTITY); + map.put("MERGE", Token.MERGE); + map.put("USING", Token.USING); + map.put("MATCHED", Token.MATCHED); + map.put("UPSERT", Token.UPSERT); + map.put("IF", Token.IF); + map.put("OVERWRITE", Token.OVERWRITE); + map.put("PARTITION", Token.PARTITION); + + return new Keywords(map); + } + public SuperSqlLexer(String input, SQLParserFeature... features) { + super(input, features); + this.dbType = DbType.supersql; + } +} diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlSelectParser.java b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlSelectParser.java new file mode 100644 index 0000000000..5fd5085f69 --- /dev/null +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlSelectParser.java @@ -0,0 +1,16 @@ +package com.alibaba.druid.sql.dialect.supersql.parser; + +import com.alibaba.druid.sql.dialect.presto.parser.PrestoSelectParser; +import com.alibaba.druid.sql.parser.SQLExprParser; +import com.alibaba.druid.sql.parser.SQLSelectListCache; + +public class SuperSqlSelectParser extends PrestoSelectParser { + public SuperSqlSelectParser(SQLExprParser exprParser, SQLSelectListCache selectListCache) { + super(exprParser, selectListCache); + } + + @Override + protected SQLExprParser createExprParser() { + return new SuperSqlExprParser(this.lexer); + } +} diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlStatementParser.java b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlStatementParser.java new file mode 100644 index 0000000000..7449347602 --- /dev/null +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/parser/SuperSqlStatementParser.java @@ -0,0 +1,22 @@ +package com.alibaba.druid.sql.dialect.supersql.parser; + +import com.alibaba.druid.sql.dialect.presto.parser.PrestoStatementParser; +import com.alibaba.druid.sql.parser.SQLCreateTableParser; +import com.alibaba.druid.sql.parser.SQLParserFeature; + +public class SuperSqlStatementParser extends PrestoStatementParser { + public SuperSqlStatementParser(String sql, SQLParserFeature... features) { + super(new SuperSqlExprParser(sql, features)); + } + + @Override + public SuperSqlSelectParser createSQLSelectParser() { + return new SuperSqlSelectParser(this.exprParser, selectListCache); + } + + @Override + public SQLCreateTableParser getSQLCreateTableParser() { + return new SuperSqlCreateTableParser(this.exprParser); + } + +} diff --git a/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/visitor/SuperSqlASTVisitor.java b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/visitor/SuperSqlASTVisitor.java new file mode 100644 index 0000000000..77f44301aa --- /dev/null +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/visitor/SuperSqlASTVisitor.java @@ -0,0 +1,6 @@ +package com.alibaba.druid.sql.dialect.supersql.visitor; + +import com.alibaba.druid.sql.dialect.presto.visitor.PrestoASTVisitor; + +public interface SuperSqlASTVisitor extends PrestoASTVisitor { +} 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 new file mode 100644 index 0000000000..330b546b4e --- /dev/null +++ b/core/src/main/java/com/alibaba/druid/sql/dialect/supersql/visitor/SuperSqlOutputVisitor.java @@ -0,0 +1,14 @@ +package com.alibaba.druid.sql.dialect.supersql.visitor; + +import com.alibaba.druid.DbType; +import com.alibaba.druid.sql.dialect.presto.visitor.PrestoOutputVisitor; + +public class SuperSqlOutputVisitor extends PrestoOutputVisitor implements SuperSqlASTVisitor { + public SuperSqlOutputVisitor(StringBuilder appender) { + super(appender, DbType.supersql); + } + + public SuperSqlOutputVisitor(StringBuilder appender, boolean parameterized) { + super(appender, DbType.supersql, parameterized); + } +} diff --git a/core/src/main/java/com/alibaba/druid/sql/parser/Lexer.java b/core/src/main/java/com/alibaba/druid/sql/parser/Lexer.java index c42ced62f1..026fa49b10 100644 --- a/core/src/main/java/com/alibaba/druid/sql/parser/Lexer.java +++ b/core/src/main/java/com/alibaba/druid/sql/parser/Lexer.java @@ -91,9 +91,9 @@ public Lexer(String input) { this(input, (CommentHandler) null); } -// public Lexer(String input, DbType dbType){ -// this(input, (CommentHandler) null, dbType); -// } + public Lexer(String input, DbType dbType) { + this(input, null, dbType); + } public Lexer(String input, CommentHandler commentHandler) { this(input, true); diff --git a/core/src/main/java/com/alibaba/druid/sql/parser/SQLParserUtils.java b/core/src/main/java/com/alibaba/druid/sql/parser/SQLParserUtils.java index 9e587e23d1..b762336d2f 100644 --- a/core/src/main/java/com/alibaba/druid/sql/parser/SQLParserUtils.java +++ b/core/src/main/java/com/alibaba/druid/sql/parser/SQLParserUtils.java @@ -95,6 +95,9 @@ import com.alibaba.druid.sql.dialect.starrocks.parser.StarRocksExprParser; import com.alibaba.druid.sql.dialect.starrocks.parser.StarRocksLexer; import com.alibaba.druid.sql.dialect.starrocks.parser.StarRocksStatementParser; +import com.alibaba.druid.sql.dialect.supersql.parser.SuperSqlExprParser; +import com.alibaba.druid.sql.dialect.supersql.parser.SuperSqlLexer; +import com.alibaba.druid.sql.dialect.supersql.parser.SuperSqlStatementParser; import com.alibaba.druid.sql.dialect.teradata.parser.TDExprParser; import com.alibaba.druid.sql.dialect.teradata.parser.TDLexer; import com.alibaba.druid.sql.dialect.teradata.parser.TDStatementParser; @@ -187,8 +190,9 @@ public static SQLStatementParser createSQLStatementParser(String sql, DbType dbT return new HiveStatementParser(sql, features); case presto: case trino: - case supersql: return new PrestoStatementParser(sql, features); + case supersql: + return new SuperSqlStatementParser(sql, features); case athena: return new AthenaStatementParser(sql, features); case bigquery: @@ -256,8 +260,9 @@ public static SQLExprParser createExprParser(String sql, DbType dbType, SQLParse return new PhoenixExprParser(sql, features); case presto: case trino: - case supersql: return new PrestoExprParser(sql, features); + case supersql: + return new SuperSqlExprParser(sql, features); case athena: return new AthenaExprParser(sql, features); case hive: @@ -324,8 +329,9 @@ public static Lexer createLexer(String sql, DbType dbType, SQLParserFeature... f return new PhoenixLexer(sql, features); case presto: case trino: - case supersql: return new PrestoLexer(sql, features); + case supersql: + return new SuperSqlLexer(sql, features); case athena: return new AthenaLexer(sql, features); case spark: diff --git a/core/src/test/java/com/alibaba/druid/bvt/sql/supersql/SuperSqlResourceTest.java b/core/src/test/java/com/alibaba/druid/bvt/sql/supersql/SuperSqlResourceTest.java new file mode 100644 index 0000000000..e508e982f8 --- /dev/null +++ b/core/src/test/java/com/alibaba/druid/bvt/sql/supersql/SuperSqlResourceTest.java @@ -0,0 +1,17 @@ +package com.alibaba.druid.bvt.sql.supersql; + +import com.alibaba.druid.DbType; +import com.alibaba.druid.bvt.sql.SQLResourceTest; +import org.junit.Test; + +public class SuperSqlResourceTest extends SQLResourceTest { + + public SuperSqlResourceTest() { + super(DbType.supersql); + } + + @Test + public void supersql_parse() throws Exception { + fileTest(0, 999, i -> "bvt/parser/supersql/" + i + ".txt"); + } +} diff --git a/core/src/test/resources/bvt/parser/supersql/0.txt b/core/src/test/resources/bvt/parser/supersql/0.txt new file mode 100644 index 0000000000..acc54e098c --- /dev/null +++ b/core/src/test/resources/bvt/parser/supersql/0.txt @@ -0,0 +1,82 @@ +WITH aa as ( + select a, c from b +) +select all a from aa group by c having count(1) > 0 order by c desc nulls first +limit 1 +-------------------- +WITH aa AS ( + SELECT a, c + FROM b + ) +SELECT ALL a +FROM aa +GROUP BY c +HAVING count(1) > 0 +ORDER BY c DESC NULLS FIRST + LIMIT 1 +------------------------------------------------------------------------------------------------------------------------ +select + 'organic' as tag, + count(distinct pd_device_id) filter(where app_time_6 is not null) app_uv, + sum(games) all_games +from base_data +where af_status='Organic' +-------------------- +SELECT 'organic' AS tag, count(DISTINCT pd_device_id) FILTER (WHERE app_time_6 IS NOT NULL) AS app_uv, sum(games) AS all_games +FROM base_data +WHERE af_status = 'Organic' +------------------------------------------------------------------------------------------------------------------------ +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 + ,nvl(t2.user_playtime_3d, 0.0) as user_playtime_3d + ,nvl(t2.user_playtime_7d, 0.0) as user_playtime_7d + ,nvl(t2.user_play_game_7d_cnt, 0) as user_play_game_7d_cnt +FROM click t1 +full join play_res t2 on t1.pd_uid = t2.pd_uid +-------------------- +INSERT OVERWRITE 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 + , nvl(t2.user_playtime_3d, 0.0) AS user_playtime_3d + , nvl(t2.user_playtime_7d, 0.0) AS user_playtime_7d + , nvl(t2.user_play_game_7d_cnt, 0) AS user_play_game_7d_cnt +FROM click t1 + FULL JOIN play_res t2 ON t1.pd_uid = t2.pd_uid +------------------------------------------------------------------------------------------------------------------------ +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 +-------------------- +INSERT OVERWRITE 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 +------------------------------------------------------------------------------------------------------------------------ +insert into 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 +-------------------- +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