mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved pg parser, fix #4146
This commit is contained in:
+20
@@ -1,6 +1,7 @@
|
||||
package com.alibaba.druid.sql.dialect.postgresql.parser;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionBy;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionByHash;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionByList;
|
||||
import com.alibaba.druid.sql.parser.*;
|
||||
|
||||
@@ -45,7 +46,26 @@ public class PGCreateTableParser extends SQLCreateTableParser {
|
||||
}
|
||||
|
||||
return list;
|
||||
} else if (lexer.identifierEquals("HASH") || lexer.identifierEquals("UNI_HASH")) {
|
||||
SQLPartitionByHash hash = new SQLPartitionByHash();
|
||||
|
||||
if (lexer.identifierEquals("UNI_HASH")) {
|
||||
hash.setUnique(true);
|
||||
}
|
||||
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.KEY) {
|
||||
lexer.nextToken();
|
||||
hash.setKey(true);
|
||||
}
|
||||
|
||||
accept(Token.LPAREN);
|
||||
this.exprParser.exprList(hash.getColumns(), hash);
|
||||
accept(Token.RPAREN);
|
||||
return hash;
|
||||
}
|
||||
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3512,6 +3512,13 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
public boolean visit(SQLCreateTableStatement x) {
|
||||
printCreateTable(x, true);
|
||||
|
||||
SQLPartitionBy partitionBy = x.getPartitioning();
|
||||
if (partitionBy != null) {
|
||||
println();
|
||||
print0(ucase ? "PARTITION BY " : "partition by ");
|
||||
partitionBy.accept(this);
|
||||
}
|
||||
|
||||
List<SQLAssignItem> options = x.getTableOptions();
|
||||
if (options.size() > 0) {
|
||||
println();
|
||||
|
||||
@@ -64,6 +64,10 @@ public class PostgresqlResourceTest extends PGTest {
|
||||
exec_test("bvt/parser/postgresql-6.txt");
|
||||
}
|
||||
|
||||
public void test_7() throws Exception {
|
||||
exec_test("bvt/parser/postgresql-7.txt");
|
||||
}
|
||||
|
||||
public void exec_test(String resource) throws Exception {
|
||||
System.out.println(resource);
|
||||
InputStream is = null;
|
||||
|
||||
@@ -13,4 +13,5 @@ CREATE TABLE IF NOT EXISTS test_dim_segment (
|
||||
segment_id bigint,
|
||||
segment_name text,
|
||||
ds text NOT NULL
|
||||
);
|
||||
)
|
||||
PARTITION BY LIST (ds);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
CREATE TABLE orders (
|
||||
order_id bigint not null,
|
||||
cust_id bigint not null,
|
||||
status text
|
||||
) PARTITION BY HASH (order_id);
|
||||
---------------------------
|
||||
CREATE TABLE orders (
|
||||
order_id bigint NOT NULL,
|
||||
cust_id bigint NOT NULL,
|
||||
status text
|
||||
)
|
||||
PARTITION BY HASH (order_id);
|
||||
Reference in New Issue
Block a user