mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser for OracleCreateIndex. issue #1923
This commit is contained in:
+27
-6
@@ -15,10 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.oracle.ast.stmt;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLPartition;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.OracleSegmentAttributes;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
|
||||
@@ -97,8 +94,12 @@ public class OracleCreateIndexStatement extends SQLCreateIndexStatement implemen
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
private boolean local;
|
||||
private List<SQLName> localStoreIn = new ArrayList<SQLName>();
|
||||
private List<SQLPartition> localPartitions = new ArrayList<SQLPartition>();
|
||||
private List<SQLPartition> globalPartitions = new ArrayList<SQLPartition>();
|
||||
|
||||
private boolean global;
|
||||
private List<SQLPartitionBy> globalPartitions = new ArrayList<SQLPartitionBy>();
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
accept0((OracleASTVisitor) visitor);
|
||||
@@ -262,7 +263,27 @@ public class OracleCreateIndexStatement extends SQLCreateIndexStatement implemen
|
||||
return localPartitions;
|
||||
}
|
||||
|
||||
public List<SQLPartition> getGlobalPartitions() {
|
||||
public boolean isLocal() {
|
||||
return local;
|
||||
}
|
||||
|
||||
public void setLocal(boolean local) {
|
||||
this.local = local;
|
||||
}
|
||||
|
||||
public List<SQLName> getLocalStoreIn() {
|
||||
return localStoreIn;
|
||||
}
|
||||
|
||||
public List<SQLPartitionBy> getGlobalPartitions() {
|
||||
return globalPartitions;
|
||||
}
|
||||
|
||||
public boolean isGlobal() {
|
||||
return global;
|
||||
}
|
||||
|
||||
public void setGlobal(boolean global) {
|
||||
this.global = global;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-158
@@ -183,13 +183,13 @@ public class OracleCreateTableParser extends SQLCreateTableParser {
|
||||
accept(Token.BY);
|
||||
|
||||
if (identifierEquals("RANGE")) {
|
||||
SQLPartitionByRange partitionByRange = partitionByRange();
|
||||
partitionClauseRest(partitionByRange);
|
||||
SQLPartitionByRange partitionByRange = this.getExprParser().partitionByRange();
|
||||
this.getExprParser().partitionClauseRest(partitionByRange);
|
||||
stmt.setPartitioning(partitionByRange);
|
||||
continue;
|
||||
} else if (identifierEquals("HASH")) {
|
||||
SQLPartitionByHash partitionByHash = partitionByHash();
|
||||
partitionClauseRest(partitionByHash);
|
||||
SQLPartitionByHash partitionByHash = this.getExprParser().partitionByHash();
|
||||
this.getExprParser().partitionClauseRest(partitionByHash);
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
@@ -210,7 +210,7 @@ public class OracleCreateTableParser extends SQLCreateTableParser {
|
||||
continue;
|
||||
} else if (identifierEquals("LIST")) {
|
||||
SQLPartitionByList partitionByList = partitionByList();
|
||||
partitionClauseRest(partitionByList);
|
||||
this.getExprParser().partitionClauseRest(partitionByList);
|
||||
stmt.setPartitioning(partitionByList);
|
||||
continue;
|
||||
} else {
|
||||
@@ -343,163 +343,11 @@ public class OracleCreateTableParser extends SQLCreateTableParser {
|
||||
partitionByList.setExpr(this.exprParser.expr());
|
||||
accept(Token.RPAREN);
|
||||
|
||||
parsePartitionByRest(partitionByList);
|
||||
this.getExprParser().parsePartitionByRest(partitionByList);
|
||||
|
||||
return partitionByList;
|
||||
}
|
||||
|
||||
protected SQLPartitionByHash partitionByHash() {
|
||||
acceptIdentifier("HASH");
|
||||
SQLPartitionByHash partitionByHash = new SQLPartitionByHash();
|
||||
|
||||
if (lexer.token() == Token.KEY) {
|
||||
lexer.nextToken();
|
||||
partitionByHash.setKey(true);
|
||||
}
|
||||
|
||||
accept(Token.LPAREN);
|
||||
partitionByHash.setExpr(this.exprParser.expr());
|
||||
accept(Token.RPAREN);
|
||||
return partitionByHash;
|
||||
}
|
||||
|
||||
protected SQLPartitionByRange partitionByRange() {
|
||||
acceptIdentifier("RANGE");
|
||||
accept(Token.LPAREN);
|
||||
SQLPartitionByRange clause = new SQLPartitionByRange();
|
||||
for (;;) {
|
||||
SQLName column = this.exprParser.name();
|
||||
clause.addColumn(column);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
|
||||
if (lexer.token() == Token.INTERVAL) {
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
clause.setInterval(this.exprParser.expr());
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
parsePartitionByRest(clause);
|
||||
|
||||
return clause;
|
||||
}
|
||||
|
||||
protected void parsePartitionByRest(SQLPartitionBy clause) {
|
||||
if (lexer.token() == Token.STORE) {
|
||||
lexer.nextToken();
|
||||
accept(Token.IN);
|
||||
accept(Token.LPAREN);
|
||||
for (;;) {
|
||||
SQLName tablespace = this.exprParser.name();
|
||||
clause.getStoreIn().add(tablespace);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
if (identifierEquals("SUBPARTITION")) {
|
||||
SQLSubPartitionBy subPartitionBy = subPartitionBy();
|
||||
clause.setSubPartitionBy(subPartitionBy);
|
||||
}
|
||||
|
||||
|
||||
accept(Token.LPAREN);
|
||||
|
||||
for (;;) {
|
||||
SQLPartition partition = this.getExprParser().parsePartition();
|
||||
|
||||
clause.addPartition(partition);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
protected void partitionClauseRest(SQLPartitionBy clause) {
|
||||
if (identifierEquals("PARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLIntegerExpr countExpr = this.exprParser.integerExpr();
|
||||
clause.setPartitionsCount(countExpr);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.STORE) {
|
||||
lexer.nextToken();
|
||||
accept(Token.IN);
|
||||
accept(Token.LPAREN);
|
||||
this.exprParser.names(clause.getStoreIn(), clause);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
}
|
||||
|
||||
protected SQLSubPartitionBy subPartitionBy() {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
|
||||
if (identifierEquals("HASH")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
|
||||
SQLSubPartitionByHash byHash = new SQLSubPartitionByHash();
|
||||
SQLExpr expr = this.exprParser.expr();
|
||||
byHash.setExpr(expr);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
return byHash;
|
||||
} else if (identifierEquals("LIST")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
|
||||
SQLSubPartitionByList byList = new SQLSubPartitionByList();
|
||||
SQLName column = this.exprParser.name();
|
||||
byList.setColumn(column);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
if (identifierEquals("SUBPARTITION")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("TEMPLATE");
|
||||
accept(Token.LPAREN);
|
||||
|
||||
for (;;) {
|
||||
SQLSubPartition subPartition = this.getExprParser().parseSubPartition();
|
||||
subPartition.setParent(byList);
|
||||
byList.getSubPartitionTemplate().add(subPartition);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
return byList;
|
||||
}
|
||||
|
||||
throw new ParserException("TODO : " + lexer.info());
|
||||
}
|
||||
|
||||
protected void parseCreateTableSupplementalLogingProps(SQLCreateTableStatement stmt) {
|
||||
acceptIdentifier("SUPPLEMENTAL");
|
||||
acceptIdentifier("LOG");
|
||||
|
||||
@@ -1599,4 +1599,156 @@ public class OracleExprParser extends SQLExprParser {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected SQLPartitionByRange partitionByRange() {
|
||||
acceptIdentifier("RANGE");
|
||||
accept(Token.LPAREN);
|
||||
SQLPartitionByRange clause = new SQLPartitionByRange();
|
||||
for (;;) {
|
||||
SQLName column = this.name();
|
||||
clause.addColumn(column);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
|
||||
if (lexer.token() == Token.INTERVAL) {
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
clause.setInterval(this.expr());
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
parsePartitionByRest(clause);
|
||||
|
||||
return clause;
|
||||
}
|
||||
|
||||
protected void parsePartitionByRest(SQLPartitionBy clause) {
|
||||
if (lexer.token() == Token.STORE) {
|
||||
lexer.nextToken();
|
||||
accept(Token.IN);
|
||||
accept(Token.LPAREN);
|
||||
for (;;) {
|
||||
SQLName tablespace = this.name();
|
||||
clause.getStoreIn().add(tablespace);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
if (identifierEquals("SUBPARTITION")) {
|
||||
SQLSubPartitionBy subPartitionBy = subPartitionBy();
|
||||
clause.setSubPartitionBy(subPartitionBy);
|
||||
}
|
||||
|
||||
|
||||
accept(Token.LPAREN);
|
||||
|
||||
for (;;) {
|
||||
SQLPartition partition = this.parsePartition();
|
||||
|
||||
clause.addPartition(partition);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
protected SQLSubPartitionBy subPartitionBy() {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
|
||||
if (identifierEquals("HASH")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
|
||||
SQLSubPartitionByHash byHash = new SQLSubPartitionByHash();
|
||||
SQLExpr expr = this.expr();
|
||||
byHash.setExpr(expr);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
return byHash;
|
||||
} else if (identifierEquals("LIST")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
|
||||
SQLSubPartitionByList byList = new SQLSubPartitionByList();
|
||||
SQLName column = this.name();
|
||||
byList.setColumn(column);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
if (identifierEquals("SUBPARTITION")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("TEMPLATE");
|
||||
accept(Token.LPAREN);
|
||||
|
||||
for (;;) {
|
||||
SQLSubPartition subPartition = this.parseSubPartition();
|
||||
subPartition.setParent(byList);
|
||||
byList.getSubPartitionTemplate().add(subPartition);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
return byList;
|
||||
}
|
||||
|
||||
throw new ParserException("TODO : " + lexer.info());
|
||||
}
|
||||
|
||||
protected void partitionClauseRest(SQLPartitionBy clause) {
|
||||
if (identifierEquals("PARTITIONS")) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLIntegerExpr countExpr = this.integerExpr();
|
||||
clause.setPartitionsCount(countExpr);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.STORE) {
|
||||
lexer.nextToken();
|
||||
accept(Token.IN);
|
||||
accept(Token.LPAREN);
|
||||
this.names(clause.getStoreIn(), clause);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
}
|
||||
|
||||
protected SQLPartitionByHash partitionByHash() {
|
||||
acceptIdentifier("HASH");
|
||||
SQLPartitionByHash partitionByHash = new SQLPartitionByHash();
|
||||
|
||||
if (lexer.token() == Token.KEY) {
|
||||
lexer.nextToken();
|
||||
partitionByHash.setKey(true);
|
||||
}
|
||||
|
||||
accept(Token.LPAREN);
|
||||
partitionByHash.setExpr(this.expr());
|
||||
accept(Token.RPAREN);
|
||||
return partitionByHash;
|
||||
}
|
||||
}
|
||||
|
||||
+63
-8
@@ -2056,19 +2056,74 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
continue;
|
||||
} else if (identifierEquals("LOCAL")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
stmt.setLocal(true);
|
||||
|
||||
for (;;) {
|
||||
SQLPartition partition = this.getExprParser().parsePartition();
|
||||
partition.setParent(stmt);
|
||||
stmt.getLocalPartitions().add(partition);
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
if (lexer.token() == Token.STORE) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
} else if (lexer.token() == Token.RPAREN) {
|
||||
accept(Token.IN);
|
||||
accept(Token.LPAREN);
|
||||
this.exprParser.names(stmt.getLocalStoreIn(), stmt);
|
||||
accept(Token.RPAREN);
|
||||
} else if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
for (; ; ) {
|
||||
SQLPartition partition = this.getExprParser().parsePartition();
|
||||
partition.setParent(stmt);
|
||||
stmt.getLocalPartitions().add(partition);
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
} else if (lexer.token() == Token.RPAREN) {
|
||||
lexer.nextToken();
|
||||
break;
|
||||
}
|
||||
throw new ParserException("TODO : " + lexer.info());
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
throw new ParserException("TODO : " + lexer.info());
|
||||
}
|
||||
|
||||
break;
|
||||
} else if (identifierEquals("GLOBAL")) {
|
||||
lexer.nextToken();
|
||||
stmt.setGlobal(true);
|
||||
|
||||
if (lexer.token() == Token.PARTITION) {
|
||||
lexer.nextToken();
|
||||
|
||||
accept(Token.BY);
|
||||
|
||||
if (identifierEquals("RANGE")) {
|
||||
SQLPartitionByRange partitionByRange = this.getExprParser().partitionByRange();
|
||||
this.getExprParser().partitionClauseRest(partitionByRange);
|
||||
partitionByRange.setParent(stmt);
|
||||
stmt.getGlobalPartitions().add(partitionByRange);
|
||||
continue;
|
||||
} else if (identifierEquals("HASH")) {
|
||||
SQLPartitionByHash partitionByHash = this.getExprParser().partitionByHash();
|
||||
this.getExprParser().partitionClauseRest(partitionByHash);
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
for (; ; ) {
|
||||
SQLPartition partition = this.getExprParser().parsePartition();
|
||||
partitionByHash.addPartition(partition);
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
} else if (lexer.token() == Token.RPAREN) {
|
||||
lexer.nextToken();
|
||||
break;
|
||||
}
|
||||
throw new ParserException("TODO : " + lexer.info());
|
||||
}
|
||||
}
|
||||
partitionByHash.setParent(stmt);
|
||||
stmt.getGlobalPartitions().add(partitionByHash);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -1802,6 +1802,29 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
decrementIndent();
|
||||
println();
|
||||
print(')');
|
||||
} else if (x.isLocal()) {
|
||||
print0(ucase ? " LOCAL" : " local");
|
||||
}
|
||||
|
||||
List<SQLName> localStoreIn = x.getLocalStoreIn();
|
||||
if (localStoreIn.size() > 0) {
|
||||
print0(ucase ? " STORE IN (" : " store in (");
|
||||
printAndAccept(localStoreIn, ", ");
|
||||
print(')');
|
||||
}
|
||||
|
||||
List<SQLPartitionBy> globalPartitions = x.getGlobalPartitions();
|
||||
if (globalPartitions.size() > 0) {
|
||||
for (SQLPartitionBy globalPartition : globalPartitions) {
|
||||
println();
|
||||
print0(ucase ? "GLOBAL " : "global ");
|
||||
globalPartition.accept(this);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (x.isGlobal()) {
|
||||
print0(ucase ? " GLOBAL" : " global");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.bvt.sql.oracle.create;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreateIndexTest16_local extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE INDEX dbobjs_idx ON dbobjs (created) LOCAL";
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ORACLE);
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("relationships : " + visitor.getRelationships());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals("CREATE INDEX dbobjs_idx ON dbobjs(created) LOCAL"
|
||||
, SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
|
||||
assertTrue(visitor.getTables().containsKey(new TableStat.Name("dbobjs")));
|
||||
|
||||
assertEquals(1, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("xwarehouses", "sales_rep_id")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.bvt.sql.oracle.create;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreateIndexTest17_global extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE INDEX dbobjs_idx ON dbobjs (created) global";
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ORACLE);
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("relationships : " + visitor.getRelationships());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals("CREATE INDEX dbobjs_idx ON dbobjs(created) GLOBAL"
|
||||
, SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
|
||||
assertTrue(visitor.getTables().containsKey(new TableStat.Name("dbobjs")));
|
||||
|
||||
assertEquals(1, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("xwarehouses", "sales_rep_id")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.bvt.sql.oracle.create;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreateIndexTest18_global extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE INDEX cost_ix ON sales (amount_sold)\n" +
|
||||
" GLOBAL PARTITION BY RANGE (amount_sold)\n" +
|
||||
" (PARTITION p1 VALUES LESS THAN (1000),\n" +
|
||||
" PARTITION p2 VALUES LESS THAN (2500),\n" +
|
||||
" PARTITION p3 VALUES LESS THAN (MAXVALUE));";
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ORACLE);
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("relationships : " + visitor.getRelationships());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals("CREATE INDEX cost_ix ON sales(amount_sold)\n" +
|
||||
"GLOBAL PARTITION BY RANGE (amount_sold) (\n" +
|
||||
"\tPARTITION p1 VALUES LESS THAN (1000),\n" +
|
||||
"\tPARTITION p2 VALUES LESS THAN (2500),\n" +
|
||||
"\tPARTITION p3 VALUES LESS THAN (MAXVALUE)\n" +
|
||||
");"
|
||||
, SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
|
||||
assertTrue(visitor.getTables().containsKey(new TableStat.Name("sales")));
|
||||
|
||||
assertEquals(1, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("xwarehouses", "sales_rep_id")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.bvt.sql.oracle.create;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreateIndexTest19_global extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE INDEX cust_last_name_ix ON customers (cust_last_name)\n" +
|
||||
" GLOBAL PARTITION BY HASH (cust_last_name)\n" +
|
||||
" PARTITIONS 4;";
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ORACLE);
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("relationships : " + visitor.getRelationships());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals("CREATE INDEX cust_last_name_ix ON customers(cust_last_name)\n" +
|
||||
"GLOBAL PARTITION BY HASH (cust_last_name) PARTITIONS 4;"
|
||||
, SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
|
||||
assertTrue(visitor.getTables().containsKey(new TableStat.Name("customers")));
|
||||
|
||||
assertEquals(1, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("xwarehouses", "sales_rep_id")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.bvt.sql.oracle.create;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreateIndexTest19_local_store extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE INDEX prod_idx ON hash_products(product_id) LOCAL\n" +
|
||||
" STORE IN (tbs_01, tbs_02);";
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ORACLE);
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("relationships : " + visitor.getRelationships());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals("CREATE INDEX prod_idx ON hash_products(product_id) LOCAL STORE IN (tbs_01, tbs_02);"
|
||||
, SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
|
||||
assertTrue(visitor.getTables().containsKey(new TableStat.Name("hash_products")));
|
||||
|
||||
assertEquals(1, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("xwarehouses", "sales_rep_id")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user