Skip to content

Commit

Permalink
Gaussdb parser ddl support to group/node clause
Browse files Browse the repository at this point in the history
  • Loading branch information
woyumen4597 committed Feb 13, 2025
1 parent 1aea5ae commit a6b202e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
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

0 comments on commit a6b202e

Please # to comment.