Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gaussdb parser ddl support to group/node clause #6351

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.alibaba.druid.sql.dialect.gaussdb.ast.stmt;

import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
import com.alibaba.druid.sql.dialect.gaussdb.ast.GaussDbDistributeBy;
import com.alibaba.druid.sql.dialect.gaussdb.ast.GaussDbObject;
Expand All @@ -9,6 +10,8 @@

public class GaussDbCreateTableStatement extends SQLCreateTableStatement implements GaussDbObject {
protected GaussDbDistributeBy distributeBy;
protected SQLExpr toGroup;
protected SQLExpr toNode;

public GaussDbCreateTableStatement() {
super(DbType.gaussdb);
Expand All @@ -25,6 +28,28 @@ public GaussDbDistributeBy getDistributeBy() {
return distributeBy;
}

public void setToGroup(SQLExpr toGroup) {
if (toGroup != null) {
toGroup.setParent(this);
}
this.toGroup = toGroup;
}

public SQLExpr getToGroup() {
return toGroup;
}

public void setToNode(SQLExpr toNode) {
if (toNode != null) {
toNode.setParent(this);
}
this.toNode = toNode;
}

public SQLExpr getToNode() {
return toNode;
}

@Override
public void accept0(SQLASTVisitor v) {
if (v instanceof GaussDbASTVisitor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ protected void parseCreateTableRest(SQLCreateTableStatement stmt) {
if (distributeByClause != null) {
gdStmt.setDistributeBy(distributeByClause);
}

if (lexer.nextIf(Token.TO)) {
if (lexer.nextIf(Token.GROUP)) {
SQLExpr group = this.exprParser.expr();
gdStmt.setToGroup(group);
}
if (lexer.nextIfIdentifier(FnvHash.Constants.NODE)) {
SQLExpr node = this.exprParser.expr();
gdStmt.setToNode(node);
}
}

if (lexer.nextIf(Token.COMMENT)) {
lexer.nextIf(Token.EQ);
SQLExpr comment = this.exprParser.expr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public boolean visit(GaussDbCreateTableStatement x) {
printDistributeBy(x.getDistributeBy());
}

if (x.getToGroup() != null) {
printToGroup(x);
}

if (x.getToNode() != null) {
printToNode(x);
}

printComment(x.getComment());
return false;
}
Expand All @@ -65,6 +73,18 @@ public void printDistributeBy(GaussDbDistributeBy x) {
x.accept(this);
}

public void printToGroup(GaussDbCreateTableStatement x) {
println();
print0(ucase ? "TO GROUP " : "to group ");
x.getToGroup().accept(this);
}

public void printToNode(GaussDbCreateTableStatement x) {
println();
print0(ucase ? "TO NODE " : "to node ");
x.getToNode().accept(this);
}

@Override
public boolean visit(SQLPartitionByRange x) {
print0(ucase ? "RANGE" : "range");
Expand Down
8 changes: 6 additions & 2 deletions core/src/test/resources/bvt/parser/gaussdb/0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ CREATE UNLOGGED TABLE lineitem (
WITH (
'orientation' = column
)
DISTRIBUTE BY hash (L_ORDERKEY);
DISTRIBUTE BY hash (L_ORDERKEY)
TO GROUP group1;
--------------------
CREATE UNLOGGED TABLE lineitem (
L_ORDERKEY BIGINT NOT NULL,
Expand All @@ -18,15 +19,18 @@ CREATE UNLOGGED TABLE lineitem (
WITH (
'orientation' = column
)
DISTRIBUTE BY hash (L_ORDERKEY);
DISTRIBUTE BY hash (L_ORDERKEY)
TO GROUP group1;
------------------------------------------------------------------------------------------------------------------------
CREATE GLOBAL TABLE test_global (
L_ORDERKEY BIGINT NOT NULL
)
TO NODE node01;
--------------------
CREATE GLOBAL TABLE test_global (
L_ORDERKEY BIGINT NOT NULL
)
TO NODE node01;
------------------------------------------------------------------------------------------------------------------------
CREATE LOCAL TABLE test_local (
L_ORDERKEY BIGINT NOT NULL
Expand Down
Loading