diff --git a/src/main/java/com/alibaba/druid/sql/dialect/oracle/ast/stmt/OracleCreateIndexStatement.java b/src/main/java/com/alibaba/druid/sql/dialect/oracle/ast/stmt/OracleCreateIndexStatement.java index a2c74a11a7..2bd56496a1 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/oracle/ast/stmt/OracleCreateIndexStatement.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/oracle/ast/stmt/OracleCreateIndexStatement.java @@ -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 localStoreIn = new ArrayList(); private List localPartitions = new ArrayList(); - private List globalPartitions = new ArrayList(); + + private boolean global; + private List globalPartitions = new ArrayList(); protected void accept0(SQLASTVisitor visitor) { accept0((OracleASTVisitor) visitor); @@ -262,7 +263,27 @@ public class OracleCreateIndexStatement extends SQLCreateIndexStatement implemen return localPartitions; } - public List getGlobalPartitions() { + public boolean isLocal() { + return local; + } + + public void setLocal(boolean local) { + this.local = local; + } + + public List getLocalStoreIn() { + return localStoreIn; + } + + public List getGlobalPartitions() { return globalPartitions; } + + public boolean isGlobal() { + return global; + } + + public void setGlobal(boolean global) { + this.global = global; + } } diff --git a/src/main/java/com/alibaba/druid/sql/dialect/oracle/parser/OracleCreateTableParser.java b/src/main/java/com/alibaba/druid/sql/dialect/oracle/parser/OracleCreateTableParser.java index db115e82c7..f01daa10d9 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/oracle/parser/OracleCreateTableParser.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/oracle/parser/OracleCreateTableParser.java @@ -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"); diff --git a/src/main/java/com/alibaba/druid/sql/dialect/oracle/parser/OracleExprParser.java b/src/main/java/com/alibaba/druid/sql/dialect/oracle/parser/OracleExprParser.java index be94b7b3c5..93c31a0e63 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/oracle/parser/OracleExprParser.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/oracle/parser/OracleExprParser.java @@ -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; + } } diff --git a/src/main/java/com/alibaba/druid/sql/dialect/oracle/parser/OracleStatementParser.java b/src/main/java/com/alibaba/druid/sql/dialect/oracle/parser/OracleStatementParser.java index f9dac1bc06..3ba2a1175e 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/oracle/parser/OracleStatementParser.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/oracle/parser/OracleStatementParser.java @@ -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; diff --git a/src/main/java/com/alibaba/druid/sql/dialect/oracle/visitor/OracleOutputVisitor.java b/src/main/java/com/alibaba/druid/sql/dialect/oracle/visitor/OracleOutputVisitor.java index bf352e5ede..03acfa1684 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/oracle/visitor/OracleOutputVisitor.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/oracle/visitor/OracleOutputVisitor.java @@ -1802,6 +1802,29 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS decrementIndent(); println(); print(')'); + } else if (x.isLocal()) { + print0(ucase ? " LOCAL" : " local"); + } + + List localStoreIn = x.getLocalStoreIn(); + if (localStoreIn.size() > 0) { + print0(ucase ? " STORE IN (" : " store in ("); + printAndAccept(localStoreIn, ", "); + print(')'); + } + + List 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; diff --git a/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest16_local.java b/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest16_local.java new file mode 100644 index 0000000000..4016283689 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest16_local.java @@ -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 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"))); + } +} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest17_global.java b/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest17_global.java new file mode 100644 index 0000000000..42b25c02bb --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest17_global.java @@ -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 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"))); + } +} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest18_global.java b/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest18_global.java new file mode 100644 index 0000000000..51e17fc474 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest18_global.java @@ -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 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"))); + } +} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest19_global.java b/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest19_global.java new file mode 100644 index 0000000000..b24105df09 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest19_global.java @@ -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 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"))); + } +} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest19_local_store.java b/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest19_local_store.java new file mode 100644 index 0000000000..79383e5902 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/oracle/create/OracleCreateIndexTest19_local_store.java @@ -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 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"))); + } +}