improved sql parser support create table partition syntax

This commit is contained in:
高铁
2016-02-26 21:53:00 +08:00
parent 4150256309
commit c9c6117897
45 changed files with 2015 additions and 1353 deletions
@@ -0,0 +1,173 @@
/*
* Copyright 1999-2101 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.ast;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLPartition extends SQLObjectImpl {
protected SQLName name;
protected SQLExpr subPartitionsCount;
protected List<SQLSubPartition> subPartitions = new ArrayList<SQLSubPartition>();
protected SQLPartitionValue values;
// for mysql
protected SQLExpr dataDirectory;
protected SQLExpr indexDirectory;
protected SQLName tableSpace;
protected SQLExpr maxRows;
protected SQLExpr minRows;
protected SQLExpr engine;
protected SQLExpr comment;
public SQLName getName() {
return name;
}
public void setName(SQLName name) {
if (name != null) {
name.setParent(this);
}
this.name = name;
}
public SQLExpr getSubPartitionsCount() {
return subPartitionsCount;
}
public void setSubPartitionsCount(SQLExpr subPartitionsCount) {
if (subPartitionsCount != null) {
subPartitionsCount.setParent(this);
}
this.subPartitionsCount = subPartitionsCount;
}
public SQLPartitionValue getValues() {
return values;
}
public void setValues(SQLPartitionValue values) {
if (values != null) {
values.setParent(this);
}
this.values = values;
}
public List<SQLSubPartition> getSubPartitions() {
return subPartitions;
}
public SQLExpr getIndexDirectory() {
return indexDirectory;
}
public void setIndexDirectory(SQLExpr indexDirectory) {
if (indexDirectory != null) {
indexDirectory.setParent(this);
}
this.indexDirectory = indexDirectory;
}
public SQLExpr getDataDirectory() {
return dataDirectory;
}
public void setDataDirectory(SQLExpr dataDirectory) {
if (dataDirectory != null) {
dataDirectory.setParent(this);
}
this.dataDirectory = dataDirectory;
}
public SQLName getTableSpace() {
return tableSpace;
}
public void setTableSpace(SQLName tableSpace) {
if (tableSpace != null) {
tableSpace.setParent(this);
}
this.tableSpace = tableSpace;
}
public SQLExpr getMaxRows() {
return maxRows;
}
public void setMaxRows(SQLExpr maxRows) {
if (maxRows != null) {
maxRows.setParent(this);
}
this.maxRows = maxRows;
}
public SQLExpr getMinRows() {
return minRows;
}
public void setMinRows(SQLExpr minRows) {
if (minRows != null) {
minRows.setParent(this);
}
this.minRows = minRows;
}
public SQLExpr getEngine() {
return engine;
}
public void setEngine(SQLExpr engine) {
if (engine != null) {
engine.setParent(this);
}
this.engine = engine;
}
public SQLExpr getComment() {
return comment;
}
public void setComment(SQLExpr comment) {
if (comment != null) {
comment.setParent(this);
}
this.comment = comment;
}
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, name);
acceptChild(visitor, values);
acceptChild(visitor, dataDirectory);
acceptChild(visitor, indexDirectory);
acceptChild(visitor, tableSpace);
acceptChild(visitor, maxRows);
acceptChild(visitor, minRows);
acceptChild(visitor, engine);
acceptChild(visitor, comment);
}
visitor.endVisit(this);
}
}
@@ -0,0 +1,70 @@
/*
* Copyright 1999-2101 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.ast;
import java.util.ArrayList;
import java.util.List;
public abstract class SQLPartitionBy extends SQLObjectImpl {
protected SQLSubPartitionBy subPartitionBy;
protected SQLExpr partitionsCount;
protected boolean linear;
protected List<SQLPartition> partitions = new ArrayList<SQLPartition>();
protected List<SQLName> storeIn = new ArrayList<SQLName>();
public List<SQLPartition> getPartitions() {
return partitions;
}
public SQLSubPartitionBy getSubPartitionBy() {
return subPartitionBy;
}
public void setSubPartitionBy(SQLSubPartitionBy subPartitionBy) {
if (subPartitionBy != null) {
subPartitionBy.setParent(this);
}
this.subPartitionBy = subPartitionBy;
}
public SQLExpr getPartitionsCount() {
return partitionsCount;
}
public void setPartitionsCount(SQLExpr partitionsCount) {
if (partitionsCount != null) {
partitionsCount.setParent(this);
}
this.partitionsCount = partitionsCount;
}
public boolean isLinear() {
return linear;
}
public void setLinear(boolean linear) {
this.linear = linear;
}
public List<SQLName> getStoreIn() {
return storeIn;
}
}
@@ -0,0 +1,57 @@
/*
* Copyright 1999-2101 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.ast;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLPartitionByHash extends SQLPartitionBy {
protected SQLExpr expr;
// for aliyun ads
protected boolean key;
public SQLExpr getExpr() {
return expr;
}
public void setExpr(SQLExpr expr) {
if (expr != null) {
expr.setParent(this);
}
this.expr = expr;
}
public boolean isKey() {
return key;
}
public void setKey(boolean key) {
this.key = key;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, expr);
acceptChild(visitor, partitionsCount);
acceptChild(visitor, getPartitions());
acceptChild(visitor, subPartitionBy);
}
visitor.endVisit(this);
}
}
@@ -0,0 +1,56 @@
/*
* Copyright 1999-2101 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.ast;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLPartitionByList extends SQLPartitionBy {
protected SQLExpr expr;
protected List<SQLName> columns = new ArrayList<SQLName>();
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, expr);
acceptChild(visitor, columns);
acceptChild(visitor, partitionsCount);
acceptChild(visitor, getPartitions());
acceptChild(visitor, subPartitionBy);
}
visitor.endVisit(this);
}
public SQLExpr getExpr() {
return expr;
}
public void setExpr(SQLExpr expr) {
if (expr != null) {
expr.setParent(this);
}
this.expr = expr;
}
public List<SQLName> getColumns() {
return columns;
}
}
@@ -0,0 +1,75 @@
/*
* Copyright 1999-2101 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.ast;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLPartitionByRange extends SQLPartitionBy {
protected List<SQLName> columns = new ArrayList<SQLName>();
protected SQLExpr interval;
// mysql
protected SQLExpr expr;
public List<SQLName> getColumns() {
return columns;
}
public void setColumns(List<SQLName> columns) {
this.columns = columns;
}
public SQLExpr getInterval() {
return interval;
}
public void setInterval(SQLExpr interval) {
if (interval != null) {
interval.setParent(this);
}
this.interval = interval;
}
public SQLExpr getExpr() {
return expr;
}
public void setExpr(SQLExpr expr) {
if (expr != null) {
expr.setParent(this);
}
this.expr = expr;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, columns);
acceptChild(visitor, expr);
acceptChild(visitor, interval);
acceptChild(visitor, storeIn);
acceptChild(visitor, partitions);
}
visitor.endVisit(this);
}
}
@@ -0,0 +1,54 @@
/*
* Copyright 1999-2101 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.ast;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLPartitionValue extends SQLObjectImpl {
protected Operator operator;
protected final List<SQLExpr> items = new ArrayList<SQLExpr>();
public SQLPartitionValue(Operator operator){
super();
this.operator = operator;
}
public List<SQLExpr> getItems() {
return items;
}
public Operator getOperator() {
return operator;
}
public static enum Operator {
LessThan, //
In, //
List
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, getItems());
}
visitor.endVisit(this);
}
}
@@ -0,0 +1,57 @@
/*
* Copyright 1999-2101 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.ast;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLSubPartition extends SQLObjectImpl {
protected SQLName name;
protected SQLPartitionValue values;
public SQLName getName() {
return name;
}
public void setName(SQLName name) {
if (name != null) {
name.setParent(this);
}
this.name = name;
}
public SQLPartitionValue getValues() {
return values;
}
public void setValues(SQLPartitionValue values) {
if (values != null) {
values.setParent(this);
}
this.values = values;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, name);
acceptChild(visitor, values);
}
visitor.endVisit(this);
}
}
@@ -0,0 +1,60 @@
/*
* Copyright 1999-2101 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.ast;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
public abstract class SQLSubPartitionBy extends SQLObjectImpl {
protected SQLExpr subPartitionsCount;
protected boolean linear;
protected List<SQLAssignItem> options = new ArrayList<SQLAssignItem>();
protected List<SQLSubPartition> subPartitionTemplate = new ArrayList<SQLSubPartition>();
public SQLExpr getSubPartitionsCount() {
return subPartitionsCount;
}
public void setSubPartitionsCount(SQLExpr subPartitionsCount) {
if (subPartitionsCount != null) {
subPartitionsCount.setParent(this);
}
this.subPartitionsCount = subPartitionsCount;
}
public boolean isLinear() {
return linear;
}
public void setLinear(boolean linear) {
this.linear = linear;
}
public List<SQLAssignItem> getOptions() {
return options;
}
public List<SQLSubPartition> getSubPartitionTemplate() {
return subPartitionTemplate;
}
}
@@ -0,0 +1,55 @@
/*
* Copyright 1999-2101 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.ast;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLSubPartitionByHash extends SQLSubPartitionBy {
protected SQLExpr expr;
// for aliyun ads
private boolean key;
public SQLExpr getExpr() {
return expr;
}
public void setExpr(SQLExpr expr) {
if (expr != null) {
expr.setParent(this);
}
this.expr = expr;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, expr);
acceptChild(visitor, subPartitionsCount);
}
visitor.endVisit(this);
}
public boolean isKey() {
return key;
}
public void setKey(boolean key) {
this.key = key;
}
}
@@ -0,0 +1,44 @@
/*
* Copyright 1999-2101 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.ast;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLSubPartitionByList extends SQLSubPartitionBy {
protected SQLName column;
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, column);
acceptChild(visitor, subPartitionsCount);
}
visitor.endVisit(this);
}
public SQLName getColumn() {
return column;
}
public void setColumn(SQLName column) {
if (column != null) {
column.setParent(this);
}
this.column = column;
}
}
@@ -1,22 +1,34 @@
/*
* Copyright 1999-2101 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.ast;
public interface SQLPartitioningClause extends SQLObject {
}
/*
* Copyright 1999-2101 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.ast;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLSubPartitionByRange extends SQLSubPartitionBy {
private List<SQLName> columns = new ArrayList<SQLName>();
public List<SQLName> getColumns() {
return columns;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
}
}