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

支持 PG DDL 语句若干,MySQL 支持 create/alter database ... collate 语句 #6276

Merged
merged 11 commits into from
Dec 9, 2024
8 changes: 7 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,18 @@
<artifactId>calcite-core</artifactId>
<version>1.26.0</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1-jre</version>
<scope>provided</scope>
<scope>test</scope>
</dependency>
zycgit marked this conversation as resolved.
Show resolved Hide resolved
<dependency>
<groupId>com.alibaba</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.alibaba.druid.sql.parser.SQLParserFeature;
import com.alibaba.druid.sql.parser.Token;
import com.alibaba.druid.util.FnvHash;
import com.google.common.collect.Lists;

import java.util.Arrays;
import java.util.List;
Expand All @@ -53,7 +52,7 @@ public class CKExprParser extends SQLExprParser {
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
AGGREGATE_FUNCTIONS[index] = str;
}
NESTED_DATA_TYPE = Lists.newArrayList("array", "tuple", "nullable", "lowcardinality", "variant");
NESTED_DATA_TYPE = Arrays.asList("array", "tuple", "nullable", "lowcardinality", "variant");
zycgit marked this conversation as resolved.
Show resolved Hide resolved
}

public CKExprParser(String sql) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class PGAlterDatabaseStatement extends SQLStatementImpl implements PGSQLS
private SQLExpr setParameterValue;
private boolean setFromCurrent;
private SQLIdentifierExpr resetParameterName;
private boolean haveWith;
private Boolean allowConnections;
private Boolean setTemplateMark;

public SQLIdentifierExpr getDatabaseName() {
return databaseName;
Expand Down Expand Up @@ -119,6 +122,31 @@ public SQLIdentifierExpr getResetParameterName() {
public void setResetParameterName(SQLIdentifierExpr resetParameterName) {
this.resetParameterName = resetParameterName;
}

public boolean isHaveWith() {
return haveWith;
}

public void setHaveWith(boolean haveWith) {
this.haveWith = haveWith;
}

public Boolean getAllowConnections() {
return allowConnections;
}

public void setAllowConnections(Boolean allowConnections) {
this.allowConnections = allowConnections;
}

public Boolean getSetTemplateMark() {
return setTemplateMark;
}

public void setSetTemplateMark(Boolean setTemplateMark) {
this.setTemplateMark = setTemplateMark;
}

public PGAlterDatabaseStatement(DbType dbType) {
super.dbType = dbType;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright 1999-2017 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.sql.dialect.postgresql.ast.stmt;

import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLStatementImpl;
import com.alibaba.druid.sql.ast.statement.SQLCreateStatement;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;

public class PGCreateDatabaseStatement extends SQLStatementImpl implements PGSQLStatement, SQLCreateStatement {
private SQLName name;

private boolean haveWith;

private SQLName ownerName;
private PGWithMode ownerWithMode;

private SQLName templateName;
private PGWithMode templateWithMode;

public static enum PGWithMode {
OWNER,
EQ
}

zycgit marked this conversation as resolved.
Show resolved Hide resolved
public PGCreateDatabaseStatement(DbType dbType) {
super(dbType);
}

@Override
public SQLName getName() {
return this.name;
}

public void setName(SQLName dbName) {
this.name = dbName;
}

public boolean isHaveWith() {
return haveWith;
}

public void setHaveWith(boolean haveWith) {
this.haveWith = haveWith;
}

public SQLName getOwnerName() {
return ownerName;
}

public void setOwnerName(SQLName ownerName) {
this.ownerName = ownerName;
}

public PGWithMode getOwnerWithMode() {
return ownerWithMode;
}

public void setOwnerWithMode(PGWithMode ownerWithMode) {
this.ownerWithMode = ownerWithMode;
}

public SQLName getTemplateName() {
return templateName;
}

public void setTemplateName(SQLName templateName) {
this.templateName = templateName;
}

public PGWithMode getTemplateWithMode() {
return templateWithMode;
}

public void setTemplateWithMode(PGWithMode templateWithMode) {
this.templateWithMode = templateWithMode;
}

protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof PGASTVisitor) {
accept0((PGASTVisitor) visitor);
}
}

@Override
public void accept0(PGASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.name);
if (this.ownerName != null) {
zycgit marked this conversation as resolved.
Show resolved Hide resolved
acceptChild(visitor, this.ownerName);
}
}

visitor.endVisit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;

import java.util.List;

public class PGCreateSchemaStatement extends SQLStatementImpl implements PGSQLStatement, SQLCreateStatement {
private SQLIdentifierExpr schemaName;
private SQLIdentifierExpr userName;
private boolean ifNotExists;
private boolean authorization;
private List<SQLCreateStatement> createStatement;
zycgit marked this conversation as resolved.
Show resolved Hide resolved

public SQLIdentifierExpr getSchemaName() {
return schemaName;
Expand Down Expand Up @@ -59,6 +62,14 @@ public void setAuthorization(boolean authorization) {
this.authorization = authorization;
}

public List<SQLCreateStatement> getCreateStatement() {
return createStatement;
}

public void setCreateStatement(List<SQLCreateStatement> createStatement) {
this.createStatement = createStatement;
}

protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof PGASTVisitor) {
accept0((PGASTVisitor) visitor);
Expand All @@ -71,6 +82,13 @@ public void accept0(PGASTVisitor visitor) {
acceptChild(visitor, this.schemaName);
acceptChild(visitor, this.userName);
}

if (this.createStatement != null && !this.createStatement.isEmpty()) {
for (SQLCreateStatement stat : this.createStatement) {
acceptChild(visitor, stat);
}
}
zycgit marked this conversation as resolved.
Show resolved Hide resolved

visitor.endVisit(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 1999-2017 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.sql.dialect.postgresql.ast.stmt;

import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.ast.statement.SQLDropCatalogStatement;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;

public class PGDropDatabaseStatement extends SQLDropCatalogStatement implements PGSQLStatement {
private boolean usingWith;
private boolean force;

public PGDropDatabaseStatement(DbType dbType) {
super(dbType);
}

public boolean isUsingWith() {
return usingWith;
}

public void setUsingWith(boolean usingWith) {
this.usingWith = usingWith;
}

public boolean isForce() { return force; }

public void setForce(boolean force) { this.force = force; }

protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof PGASTVisitor) {
accept0((PGASTVisitor) visitor);
}
}

@Override
public void accept0(PGASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, this.getName());
}
visitor.endVisit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,31 @@
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;

import java.util.List;

public class PGDropSchemaStatement extends SQLStatementImpl implements PGSQLStatement, SQLDropStatement {
private SQLIdentifierExpr schemaName;
private List<SQLIdentifierExpr> multipleName;
zycgit marked this conversation as resolved.
Show resolved Hide resolved
private boolean ifExists;
private boolean cascade;
private boolean restrict;

public SQLIdentifierExpr getSchemaName() {
return schemaName;
return this.schemaName;
}

public void setSchemaName(SQLIdentifierExpr schemaName) {
this.schemaName = schemaName;
}

public List<SQLIdentifierExpr> getMultipleName() {
return this.multipleName;
}

public void setMultipleName(List<SQLIdentifierExpr> multipleName) {
this.multipleName = multipleName;
}

public boolean isIfExists() {
return ifExists;
}
Expand Down
Loading
Loading