mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
+10
-11
@@ -62,17 +62,16 @@ public class MySqlCreateTableTest42 extends MysqlTest {
|
||||
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("rc")));
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE TABLE rc (" + //
|
||||
"\n\ta INT NOT NULL," + //
|
||||
"\n\tb INT NOT NULL" + //
|
||||
"\n)"
|
||||
+ "\nPARTITION BY RANGE COLUMNS (a, b)"
|
||||
+ "\n(" + //
|
||||
"\n\tPARTITION p0 VALUES LESS THAN (10, 5)," + //
|
||||
"\n\tPARTITION p1 VALUES LESS THAN (20, 10)," + //
|
||||
"\n\tPARTITION p2 VALUES LESS THAN (MAXVALUE, 15)," + //
|
||||
"\n\tPARTITION p3 VALUES LESS THAN (MAXVALUE, MAXVALUE)" + //
|
||||
"\n);", output);
|
||||
Assert.assertEquals("CREATE TABLE rc (\n" +
|
||||
"\ta INT NOT NULL,\n" +
|
||||
"\tb INT NOT NULL\n" +
|
||||
")\n" +
|
||||
"PARTITION BY RANGE COLUMNS (a, b) (\n" +
|
||||
"\tPARTITION p0 VALUES LESS THAN (10, 5),\n" +
|
||||
"\tPARTITION p1 VALUES LESS THAN (20, 10),\n" +
|
||||
"\tPARTITION p2 VALUES LESS THAN (MAXVALUE, 15),\n" +
|
||||
"\tPARTITION p3 VALUES LESS THAN (MAXVALUE, MAXVALUE)\n" +
|
||||
");", output);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -47,8 +47,7 @@ public class MySqlCreateTableTest67 extends MysqlTest {
|
||||
"\ta INT NOT NULL,\n" +
|
||||
"\tPRIMARY KEY (a)\n" +
|
||||
") ENGINE = InnoDB TABLESPACE ts1\n" +
|
||||
"PARTITION BY RANGE (a) PARTITIONS 3\n" +
|
||||
"(\n" +
|
||||
"PARTITION BY RANGE (a) PARTITIONS 3 (\n" +
|
||||
"\tPARTITION P1 VALUES LESS THAN (2),\n" +
|
||||
"\tPARTITION P2 VALUES LESS THAN (4)\n" +
|
||||
"\t\tTABLESPACE ts2,\n" +
|
||||
@@ -62,8 +61,7 @@ public class MySqlCreateTableTest67 extends MysqlTest {
|
||||
"\ta INT not null,\n" +
|
||||
"\tprimary key (a)\n" +
|
||||
") engine = InnoDB tablespace ts1\n" +
|
||||
"partition by range (a) partitions 3\n" +
|
||||
"(\n" +
|
||||
"partition by range (a) partitions 3 (\n" +
|
||||
"\tpartition P1 values less than (2),\n" +
|
||||
"\tpartition P2 values less than (4)\n" +
|
||||
"\t\ttablespace ts2,\n" +
|
||||
|
||||
+2
-4
@@ -53,8 +53,7 @@ public class MySqlCreateTableTest68 extends MysqlTest {
|
||||
+ "\n\tyear_col INT,"
|
||||
+ "\n\tsome_data INT"
|
||||
+ "\n)"
|
||||
+ "\nPARTITION BY RANGE (year_col)"
|
||||
+ "\n("
|
||||
+ "\nPARTITION BY RANGE (year_col) ("
|
||||
+ "\n\tPARTITION p0 VALUES LESS THAN (1991),"
|
||||
+ "\n\tPARTITION p1 VALUES LESS THAN (1995),"
|
||||
+ "\n\tPARTITION p2 VALUES LESS THAN (1999),"
|
||||
@@ -70,8 +69,7 @@ public class MySqlCreateTableTest68 extends MysqlTest {
|
||||
+ "\n\tyear_col INT,"
|
||||
+ "\n\tsome_data INT"
|
||||
+ "\n)"
|
||||
+ "\npartition by range (year_col)"
|
||||
+ "\n("
|
||||
+ "\npartition by range (year_col) ("
|
||||
+ "\n\tpartition p0 values less than (1991),"
|
||||
+ "\n\tpartition p1 values less than (1995),"
|
||||
+ "\n\tpartition p2 values less than (1999),"
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql.param;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.google.common.collect.Lists;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/8/23.
|
||||
*/
|
||||
public class MySqlParameterizedOutputVisitorTest_43 extends TestCase {
|
||||
public void test_for_parameterize() throws Exception {
|
||||
final String dbType = JdbcConstants.MYSQL;
|
||||
String sql = "UPDATE `feel_07`.feed_item_receive SET `attributes` = ?, `gmt_modified` = ?, `lock_version` = ? WHERE `feed_id` = ?";
|
||||
String params = "[\"enableTime:1498682416713,src:top,importFrom:0\",\"2017-06-29 04:40:20\",1,313825887478L]";
|
||||
String table = "[\"`feel_07`.`feed_item_receive_0502`\"]";
|
||||
String restoredSql = restore(sql,table,params);
|
||||
|
||||
assertEquals("UPDATE `feel_07`.`feed_item_receive_0502`\n" +
|
||||
"SET `attributes` = 'enableTime:1498682416713,src:top,importFrom:0', `gmt_modified` = '2017-06-29 04:40:20', `lock_version` = 1\n" +
|
||||
"WHERE `feed_id` = 313825887478", restoredSql);
|
||||
|
||||
}
|
||||
|
||||
public static String restore(String sql, String table, String params/*JSONArray paramsArray, JSONArray destArray*/) {
|
||||
JSONArray destArray = JSON.parseArray(table.replaceAll("''", "'"));
|
||||
params = StringUtils.replace(params.replaceAll("''", "'"), "\\\"","\"");
|
||||
JSONArray paramsArray = JSON.parseArray(params);
|
||||
String dbType = JdbcConstants.MYSQL;
|
||||
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, dbType);
|
||||
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, dbType);
|
||||
List<Object> paramsList = Lists.newArrayList(paramsArray);
|
||||
visitor.setParameters(paramsList);
|
||||
|
||||
SchemaStatVisitor schemaStatVisitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(schemaStatVisitor);
|
||||
JSONArray srcArray = new JSONArray();
|
||||
for (Map.Entry<TableStat.Name, TableStat> entry : schemaStatVisitor.getTables().entrySet()) {
|
||||
srcArray.add(entry.getKey().getName());
|
||||
}
|
||||
|
||||
for (int i = 0; i < srcArray.size(); i++) {
|
||||
visitor.addTableMapping(srcArray.getString(i), destArray.getString(i));
|
||||
}
|
||||
|
||||
stmt.accept(visitor);
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.mysql.select;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_46_group_concat extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "SELECT student_name,\n" +
|
||||
" GROUP_CONCAT(test_score)\n" +
|
||||
" FROM student\n" +
|
||||
" GROUP BY student_name;";
|
||||
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL, true);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
|
||||
// System.out.println("Tables : " + visitor.getTables());
|
||||
// System.out.println("fields : " + visitor.getColumns());
|
||||
// System.out.println("coditions : " + visitor.getConditions());
|
||||
// System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
// Assert.assertEquals(1, visitor.getTables().size());
|
||||
// Assert.assertEquals(1, visitor.getColumns().size());
|
||||
// Assert.assertEquals(0, visitor.getConditions().size());
|
||||
// Assert.assertEquals(0, visitor.getOrderByColumns().size());
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT student_name, GROUP_CONCAT(test_score)\n" +
|
||||
"FROM student\n" +
|
||||
"GROUP BY student_name;", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
Assert.assertEquals("select student_name, group_concat(test_score)\n" +
|
||||
"from student\n" +
|
||||
"group by student_name;", //
|
||||
output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, new SQLUtils.FormatOption(true, true, true));
|
||||
Assert.assertEquals("SELECT student_name, GROUP_CONCAT(test_score)\n" +
|
||||
"FROM student\n" +
|
||||
"GROUP BY student_name;", //
|
||||
output);
|
||||
}
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.mysql.select;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlSelectTest_47_group_concat extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "SELECT student_name,\n" +
|
||||
" GROUP_CONCAT(DISTINCT test_score\n" +
|
||||
" ORDER BY test_score DESC SEPARATOR ' ')\n" +
|
||||
" FROM student\n" +
|
||||
" GROUP BY student_name;";
|
||||
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL, true);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
stmt.accept(visitor);
|
||||
|
||||
// System.out.println("Tables : " + visitor.getTables());
|
||||
// System.out.println("fields : " + visitor.getColumns());
|
||||
// System.out.println("coditions : " + visitor.getConditions());
|
||||
// System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
// Assert.assertEquals(1, visitor.getTables().size());
|
||||
// Assert.assertEquals(1, visitor.getColumns().size());
|
||||
// Assert.assertEquals(0, visitor.getConditions().size());
|
||||
// Assert.assertEquals(0, visitor.getOrderByColumns().size());
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT student_name, GROUP_CONCAT(DISTINCT test_score ORDER BY test_score DESC SEPARATOR ' ')\n" +
|
||||
"FROM student\n" +
|
||||
"GROUP BY student_name;", //
|
||||
output);
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
Assert.assertEquals("select student_name, group_concat(DISTINCT test_score order by test_score desc separator ' ')\n" +
|
||||
"from student\n" +
|
||||
"group by student_name;", //
|
||||
output);
|
||||
}
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, new SQLUtils.FormatOption(true, true, true));
|
||||
Assert.assertEquals("SELECT student_name, GROUP_CONCAT(DISTINCT test_score ORDER BY test_score DESC SEPARATOR ' ')\n" +
|
||||
"FROM student\n" +
|
||||
"GROUP BY student_name;", //
|
||||
output);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -54,8 +54,7 @@ public class OceanbaseCreateTableTest_rangePartition extends MysqlTest {
|
||||
+ "\n\tjob_code INT NOT NULL,"
|
||||
+ "\n\tstore_id INT NOT NULL"
|
||||
+ "\n)"
|
||||
+ "\nPARTITION BY RANGE (store_id)"
|
||||
+ "\n("
|
||||
+ "\nPARTITION BY RANGE (store_id) ("
|
||||
+ "\n\tPARTITION p0 VALUES LESS THAN (6),"
|
||||
+ "\n\tPARTITION p1 VALUES LESS THAN (11),"
|
||||
+ "\n\tPARTITION p2 VALUES LESS THAN (16),"
|
||||
@@ -74,8 +73,7 @@ public class OceanbaseCreateTableTest_rangePartition extends MysqlTest {
|
||||
+ "\n\tjob_code INT not null,"
|
||||
+ "\n\tstore_id INT not null"
|
||||
+ "\n)"
|
||||
+ "\npartition by range (store_id)"
|
||||
+ "\n("
|
||||
+ "\npartition by range (store_id) ("
|
||||
+ "\n\tpartition p0 values less than (6),"
|
||||
+ "\n\tpartition p1 values less than (11),"
|
||||
+ "\n\tpartition p2 values less than (16),"
|
||||
|
||||
+2
-4
@@ -57,8 +57,7 @@ public class OceanbaseCreateTableTest_rangePartition2 extends MysqlTest {
|
||||
+ "\n\tjob_code INT NOT NULL,"
|
||||
+ "\n\tstore_id INT NOT NULL"
|
||||
+ "\n)"
|
||||
+ "\nPARTITION BY RANGE (store_id)"
|
||||
+ "\n("
|
||||
+ "\nPARTITION BY RANGE (store_id) ("
|
||||
+ "\n\tPARTITION p0 VALUES LESS THAN (6),"
|
||||
+ "\n\tPARTITION p1 VALUES LESS THAN (11),"
|
||||
+ "\n\tPARTITION p2 VALUES LESS THAN (16),"
|
||||
@@ -77,8 +76,7 @@ public class OceanbaseCreateTableTest_rangePartition2 extends MysqlTest {
|
||||
+ "\n\tjob_code INT not null,"
|
||||
+ "\n\tstore_id INT not null"
|
||||
+ "\n)"
|
||||
+ "\npartition by range (store_id)"
|
||||
+ "\n("
|
||||
+ "\npartition by range (store_id) ("
|
||||
+ "\n\tpartition p0 values less than (6),"
|
||||
+ "\n\tpartition p1 values less than (11),"
|
||||
+ "\n\tpartition p2 values less than (16),"
|
||||
|
||||
+2
-4
@@ -56,8 +56,7 @@ public class OceanbaseCreateTableTest_rangePartition3 extends MysqlTest {
|
||||
+ "\n\tjob_code INT NOT NULL,"
|
||||
+ "\n\tstore_id INT NOT NULL"
|
||||
+ "\n)"
|
||||
+ "\nPARTITION BY RANGE (job_code)"
|
||||
+ "\n("
|
||||
+ "\nPARTITION BY RANGE (job_code) ("
|
||||
+ "\n\tPARTITION p0 VALUES LESS THAN (100),"
|
||||
+ "\n\tPARTITION p1 VALUES LESS THAN (1000),"
|
||||
+ "\n\tPARTITION p2 VALUES LESS THAN (10000)"
|
||||
@@ -75,8 +74,7 @@ public class OceanbaseCreateTableTest_rangePartition3 extends MysqlTest {
|
||||
+ "\n\tjob_code INT not null,"
|
||||
+ "\n\tstore_id INT not null"
|
||||
+ "\n)"
|
||||
+ "\npartition by range (job_code)"
|
||||
+ "\n("
|
||||
+ "\npartition by range (job_code) ("
|
||||
+ "\n\tpartition p0 values less than (100),"
|
||||
+ "\n\tpartition p1 values less than (1000),"
|
||||
+ "\n\tpartition p2 values less than (10000)"
|
||||
|
||||
+2
-4
@@ -56,8 +56,7 @@ public class OceanbaseCreateTableTest_rangePartition4 extends MysqlTest {
|
||||
+ "\n\tjob_code INT,"
|
||||
+ "\n\tstore_id INT"
|
||||
+ "\n)"
|
||||
+ "\nPARTITION BY RANGE (YEAR(separated))"
|
||||
+ "\n("
|
||||
+ "\nPARTITION BY RANGE (YEAR(separated)) ("
|
||||
+ "\n\tPARTITION p0 VALUES LESS THAN (1991),"
|
||||
+ "\n\tPARTITION p1 VALUES LESS THAN (1996),"
|
||||
+ "\n\tPARTITION p2 VALUES LESS THAN (2001),"
|
||||
@@ -76,8 +75,7 @@ public class OceanbaseCreateTableTest_rangePartition4 extends MysqlTest {
|
||||
+ "\n\tjob_code INT,"
|
||||
+ "\n\tstore_id INT"
|
||||
+ "\n)"
|
||||
+ "\npartition by range (YEAR(separated))"
|
||||
+ "\n("
|
||||
+ "\npartition by range (YEAR(separated)) ("
|
||||
+ "\n\tpartition p0 values less than (1991),"
|
||||
+ "\n\tpartition p1 values less than (1996),"
|
||||
+ "\n\tpartition p2 values less than (2001),"
|
||||
|
||||
+2
-4
@@ -44,8 +44,7 @@ public class OceanbaseCreateTableTest_rangePartition5 extends MysqlTest {
|
||||
+ "\n\tid INT,"
|
||||
+ "\n\tname VARCHAR(5)"
|
||||
+ "\n)"
|
||||
+ "\nPARTITION BY RANGE (id)"
|
||||
+ "\n("
|
||||
+ "\nPARTITION BY RANGE (id) ("
|
||||
+ "\n\tPARTITION p1 VALUES LESS THAN (1),"
|
||||
+ "\n\tPARTITION p2 VALUES LESS THAN MAXVALUE"
|
||||
+ "\n);",
|
||||
@@ -57,8 +56,7 @@ public class OceanbaseCreateTableTest_rangePartition5 extends MysqlTest {
|
||||
+ "\n\tid INT,"
|
||||
+ "\n\tname VARCHAR(5)"
|
||||
+ "\n)"
|
||||
+ "\npartition by range (id)"
|
||||
+ "\n("
|
||||
+ "\npartition by range (id) ("
|
||||
+ "\n\tpartition p1 values less than (1),"
|
||||
+ "\n\tpartition p2 values less than maxvalue"
|
||||
+ "\n);",
|
||||
|
||||
+2
-4
@@ -47,8 +47,7 @@ public class OceanbaseCreateTableTest_subPartition extends MysqlTest {
|
||||
+ "\n\tpurchased DATE"
|
||||
+ "\n)"
|
||||
+ "\nPARTITION BY RANGE (YEAR(purchased))"
|
||||
+ "\nSUBPARTITION BY HASH (TO_DAYS(purchased)) SUBPARTITIONS 2"
|
||||
+ "\n("
|
||||
+ "\nSUBPARTITION BY HASH (TO_DAYS(purchased)) SUBPARTITIONS 2 ("
|
||||
+ "\n\tPARTITION p0 VALUES LESS THAN (1990),"
|
||||
+ "\n\tPARTITION p1 VALUES LESS THAN (2000),"
|
||||
+ "\n\tPARTITION p2 VALUES LESS THAN MAXVALUE"
|
||||
@@ -62,8 +61,7 @@ public class OceanbaseCreateTableTest_subPartition extends MysqlTest {
|
||||
+ "\n\tpurchased DATE"
|
||||
+ "\n)"
|
||||
+ "\npartition by range (YEAR(purchased))"
|
||||
+ "\nsubpartition by hash (TO_DAYS(purchased)) subpartitions 2"
|
||||
+ "\n("
|
||||
+ "\nsubpartition by hash (TO_DAYS(purchased)) subpartitions 2 ("
|
||||
+ "\n\tpartition p0 values less than (1990),"
|
||||
+ "\n\tpartition p1 values less than (2000),"
|
||||
+ "\n\tpartition p2 values less than maxvalue"
|
||||
|
||||
+38
-46
@@ -44,56 +44,48 @@ public class OceanbaseCreateTableTest_subPartition2 extends MysqlTest {
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
{
|
||||
String result = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE TABLE ts (" + //
|
||||
"\n\tid INT," + //
|
||||
"\n\tpurchased DATE" + //
|
||||
"\n)" + //
|
||||
"\nPARTITION BY RANGE (YEAR(purchased))" + //
|
||||
"\nSUBPARTITION BY HASH (TO_DAYS(purchased))" + //
|
||||
"\n(" + //
|
||||
"\n\tPARTITION p0 VALUES LESS THAN (1990)" + //
|
||||
"\n\t(" + //
|
||||
"\n\t\tSUBPARTITION s0," + //
|
||||
"\n\t\tSUBPARTITION s1" + //
|
||||
"\n\t)," + //
|
||||
"\n\tPARTITION p1 VALUES LESS THAN (2000)" + //
|
||||
"\n\t(" + //
|
||||
"\n\t\tSUBPARTITION s2," + //
|
||||
"\n\t\tSUBPARTITION s3" + //
|
||||
"\n\t)," + //
|
||||
"\n\tPARTITION p2 VALUES LESS THAN MAXVALUE" + //
|
||||
"\n\t(" + //
|
||||
"\n\t\tSUBPARTITION s4," + //
|
||||
"\n\t\tSUBPARTITION s5" + //
|
||||
"\n\t)" + //
|
||||
"\n)",
|
||||
Assert.assertEquals("CREATE TABLE ts (\n" +
|
||||
"\tid INT,\n" +
|
||||
"\tpurchased DATE\n" +
|
||||
")\n" +
|
||||
"PARTITION BY RANGE (YEAR(purchased))\n" +
|
||||
"SUBPARTITION BY HASH (TO_DAYS(purchased)) (\n" +
|
||||
"\tPARTITION p0 VALUES LESS THAN (1990) (\n" +
|
||||
"\t\tSUBPARTITION s0,\n" +
|
||||
"\t\tSUBPARTITION s1\n" +
|
||||
"\t),\n" +
|
||||
"\tPARTITION p1 VALUES LESS THAN (2000) (\n" +
|
||||
"\t\tSUBPARTITION s2,\n" +
|
||||
"\t\tSUBPARTITION s3\n" +
|
||||
"\t),\n" +
|
||||
"\tPARTITION p2 VALUES LESS THAN MAXVALUE (\n" +
|
||||
"\t\tSUBPARTITION s4,\n" +
|
||||
"\t\tSUBPARTITION s5\n" +
|
||||
"\t)\n" +
|
||||
")",
|
||||
result);
|
||||
}
|
||||
{
|
||||
String result = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
Assert.assertEquals("create table ts (" + //
|
||||
"\n\tid INT," + //
|
||||
"\n\tpurchased DATE" + //
|
||||
"\n)" + //
|
||||
"\npartition by range (YEAR(purchased))" + //
|
||||
"\nsubpartition by hash (TO_DAYS(purchased))" + //
|
||||
"\n(" + //
|
||||
"\n\tpartition p0 values less than (1990)" + //
|
||||
"\n\t(" + //
|
||||
"\n\t\tsubpartition s0," + //
|
||||
"\n\t\tsubpartition s1" + //
|
||||
"\n\t)," + //
|
||||
"\n\tpartition p1 values less than (2000)" + //
|
||||
"\n\t(" + //
|
||||
"\n\t\tsubpartition s2," + //
|
||||
"\n\t\tsubpartition s3" + //
|
||||
"\n\t)," + //
|
||||
"\n\tpartition p2 values less than maxvalue" + //
|
||||
"\n\t(" + //
|
||||
"\n\t\tsubpartition s4," + //
|
||||
"\n\t\tsubpartition s5" + //
|
||||
"\n\t)" + //
|
||||
"\n)",
|
||||
Assert.assertEquals("create table ts (\n" +
|
||||
"\tid INT,\n" +
|
||||
"\tpurchased DATE\n" +
|
||||
")\n" +
|
||||
"partition by range (YEAR(purchased))\n" +
|
||||
"subpartition by hash (TO_DAYS(purchased)) (\n" +
|
||||
"\tpartition p0 values less than (1990) (\n" +
|
||||
"\t\tsubpartition s0,\n" +
|
||||
"\t\tsubpartition s1\n" +
|
||||
"\t),\n" +
|
||||
"\tpartition p1 values less than (2000) (\n" +
|
||||
"\t\tsubpartition s2,\n" +
|
||||
"\t\tsubpartition s3\n" +
|
||||
"\t),\n" +
|
||||
"\tpartition p2 values less than maxvalue (\n" +
|
||||
"\t\tsubpartition s4,\n" +
|
||||
"\t\tsubpartition s5\n" +
|
||||
"\t)\n" +
|
||||
")",
|
||||
result);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
+16
-19
@@ -39,25 +39,22 @@ public class OceanbaseCreateTableTest_subPartition3 extends MysqlTest {
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
String result = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE TABLE ts ("
|
||||
+ "\n\tid INT,"
|
||||
+ "\n\tpurchased DATE"
|
||||
+ "\n)"
|
||||
+ "\nPARTITION BY RANGE (YEAR(purchased))"
|
||||
+ "\nSUBPARTITION BY HASH (TO_DAYS(purchased))"
|
||||
+ "\n("
|
||||
+ "\n\tPARTITION p0 VALUES LESS THAN (1990)"
|
||||
+ "\n\t("
|
||||
+ "\n\t\tSUBPARTITION s0,"
|
||||
+ "\n\t\tSUBPARTITION s1"
|
||||
+ "\n\t),"
|
||||
+ "\n\tPARTITION p1 VALUES LESS THAN (2000),"
|
||||
+ "\n\tPARTITION p2 VALUES LESS THAN MAXVALUE"
|
||||
+ "\n\t("
|
||||
+ "\n\t\tSUBPARTITION s2,"
|
||||
+ "\n\t\tSUBPARTITION s3"
|
||||
+ "\n\t)"
|
||||
+ "\n)",
|
||||
Assert.assertEquals("CREATE TABLE ts (\n" +
|
||||
"\tid INT,\n" +
|
||||
"\tpurchased DATE\n" +
|
||||
")\n" +
|
||||
"PARTITION BY RANGE (YEAR(purchased))\n" +
|
||||
"SUBPARTITION BY HASH (TO_DAYS(purchased)) (\n" +
|
||||
"\tPARTITION p0 VALUES LESS THAN (1990) (\n" +
|
||||
"\t\tSUBPARTITION s0,\n" +
|
||||
"\t\tSUBPARTITION s1\n" +
|
||||
"\t),\n" +
|
||||
"\tPARTITION p1 VALUES LESS THAN (2000),\n" +
|
||||
"\tPARTITION p2 VALUES LESS THAN MAXVALUE (\n" +
|
||||
"\t\tSUBPARTITION s2,\n" +
|
||||
"\t\tSUBPARTITION s3\n" +
|
||||
"\t)\n" +
|
||||
")",
|
||||
result);
|
||||
print(stmtList);
|
||||
|
||||
|
||||
+19
-23
@@ -40,29 +40,25 @@ public class OceanbaseCreateTableTest_subPartition4 extends MysqlTest {
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
String result = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE TABLE ts ("
|
||||
+ "\n\tid INT,"
|
||||
+ "\n\tpurchased DATE"
|
||||
+ "\n)"
|
||||
+ "\nPARTITION BY RANGE (YEAR(purchased))"
|
||||
+ "\nSUBPARTITION BY HASH (TO_DAYS(purchased))"
|
||||
+ "\n("
|
||||
+ "\n\tPARTITION p0 VALUES LESS THAN (1990)"
|
||||
+ "\n\t("
|
||||
+ "\n\t\tSUBPARTITION s0,"
|
||||
+ "\n\t\tSUBPARTITION s1"
|
||||
+ "\n\t),"
|
||||
+ "\n\tPARTITION p1 VALUES LESS THAN (2000)"
|
||||
+ "\n\t("
|
||||
+ "\n\t\tSUBPARTITION s0,"
|
||||
+ "\n\t\tSUBPARTITION s1"
|
||||
+ "\n\t),"
|
||||
+ "\n\tPARTITION p2 VALUES LESS THAN MAXVALUE"
|
||||
+ "\n\t("
|
||||
+ "\n\t\tSUBPARTITION s0,"
|
||||
+ "\n\t\tSUBPARTITION s1"
|
||||
+ "\n\t)"
|
||||
+ "\n)",
|
||||
Assert.assertEquals("CREATE TABLE ts (\n" +
|
||||
"\tid INT,\n" +
|
||||
"\tpurchased DATE\n" +
|
||||
")\n" +
|
||||
"PARTITION BY RANGE (YEAR(purchased))\n" +
|
||||
"SUBPARTITION BY HASH (TO_DAYS(purchased)) (\n" +
|
||||
"\tPARTITION p0 VALUES LESS THAN (1990) (\n" +
|
||||
"\t\tSUBPARTITION s0,\n" +
|
||||
"\t\tSUBPARTITION s1\n" +
|
||||
"\t),\n" +
|
||||
"\tPARTITION p1 VALUES LESS THAN (2000) (\n" +
|
||||
"\t\tSUBPARTITION s0,\n" +
|
||||
"\t\tSUBPARTITION s1\n" +
|
||||
"\t),\n" +
|
||||
"\tPARTITION p2 VALUES LESS THAN MAXVALUE (\n" +
|
||||
"\t\tSUBPARTITION s0,\n" +
|
||||
"\t\tSUBPARTITION s1\n" +
|
||||
"\t)\n" +
|
||||
")",
|
||||
result);
|
||||
print(stmtList);
|
||||
|
||||
|
||||
+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 OracleCreateIndexTest10_function extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE INDEX upper_ix ON employees (UPPER(last_name)); ";
|
||||
|
||||
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 upper_ix ON employees(UPPER(last_name));"
|
||||
, SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
|
||||
assertTrue(visitor.getTables().containsKey(new TableStat.Name("employees")));
|
||||
|
||||
assertEquals(0, 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")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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 OracleCreateIndexTest11 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE INDEX sales_ix ON composite_sales(time_id, prod_id)\n" +
|
||||
" STORAGE (INITIAL 1M MAXEXTENTS UNLIMITED)\n" +
|
||||
" LOCAL\n" +
|
||||
" (PARTITION q1_1998,\n" +
|
||||
" PARTITION q2_1998,\n" +
|
||||
" PARTITION q3_1998,\n" +
|
||||
" PARTITION q4_1998,\n" +
|
||||
" PARTITION q1_1999,\n" +
|
||||
" PARTITION q2_1999,\n" +
|
||||
" PARTITION q3_1999,\n" +
|
||||
" PARTITION q4_1999,\n" +
|
||||
" PARTITION q1_2000,\n" +
|
||||
" PARTITION q2_2000\n" +
|
||||
" (SUBPARTITION pq2001, SUBPARTITION pq2002, \n" +
|
||||
" SUBPARTITION pq2003, SUBPARTITION pq2004,\n" +
|
||||
" SUBPARTITION pq2005, SUBPARTITION pq2006, \n" +
|
||||
" SUBPARTITION pq2007, SUBPARTITION pq2008),\n" +
|
||||
" PARTITION q3_2000\n" +
|
||||
" (SUBPARTITION c1 TABLESPACE tbs_02, \n" +
|
||||
" SUBPARTITION c2 TABLESPACE tbs_02, \n" +
|
||||
" SUBPARTITION c3 TABLESPACE tbs_02,\n" +
|
||||
" SUBPARTITION c4 TABLESPACE tbs_02,\n" +
|
||||
" SUBPARTITION c5 TABLESPACE tbs_02),\n" +
|
||||
" PARTITION q4_2000\n" +
|
||||
" (SUBPARTITION pq4001 TABLESPACE tbs_03, \n" +
|
||||
" SUBPARTITION pq4002 TABLESPACE tbs_03,\n" +
|
||||
" SUBPARTITION pq4003 TABLESPACE tbs_03,\n" +
|
||||
" SUBPARTITION pq4004 TABLESPACE tbs_03)\n" +
|
||||
");";
|
||||
|
||||
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 sales_ix ON composite_sales(time_id, prod_id)\n" +
|
||||
"STORAGE (\n" +
|
||||
"\tINITIAL 1M\n" +
|
||||
"\tMAXEXTENTS UNLIMITED\n" +
|
||||
")\n" +
|
||||
"LOCAL (\n" +
|
||||
"\tPARTITION q1_1998,\n" +
|
||||
"\tPARTITION q2_1998,\n" +
|
||||
"\tPARTITION q3_1998,\n" +
|
||||
"\tPARTITION q4_1998,\n" +
|
||||
"\tPARTITION q1_1999,\n" +
|
||||
"\tPARTITION q2_1999,\n" +
|
||||
"\tPARTITION q3_1999,\n" +
|
||||
"\tPARTITION q4_1999,\n" +
|
||||
"\tPARTITION q1_2000,\n" +
|
||||
"\tPARTITION q2_2000 (\n" +
|
||||
"\t\tSUBPARTITION pq2001,\n" +
|
||||
"\t\tSUBPARTITION pq2002,\n" +
|
||||
"\t\tSUBPARTITION pq2003,\n" +
|
||||
"\t\tSUBPARTITION pq2004,\n" +
|
||||
"\t\tSUBPARTITION pq2005,\n" +
|
||||
"\t\tSUBPARTITION pq2006,\n" +
|
||||
"\t\tSUBPARTITION pq2007,\n" +
|
||||
"\t\tSUBPARTITION pq2008\n" +
|
||||
"\t),\n" +
|
||||
"\tPARTITION q3_2000 (\n" +
|
||||
"\t\tSUBPARTITION c1 TABLESPACE tbs_02,\n" +
|
||||
"\t\tSUBPARTITION c2 TABLESPACE tbs_02,\n" +
|
||||
"\t\tSUBPARTITION c3 TABLESPACE tbs_02,\n" +
|
||||
"\t\tSUBPARTITION c4 TABLESPACE tbs_02,\n" +
|
||||
"\t\tSUBPARTITION c5 TABLESPACE tbs_02\n" +
|
||||
"\t),\n" +
|
||||
"\tPARTITION q4_2000 (\n" +
|
||||
"\t\tSUBPARTITION pq4001 TABLESPACE tbs_03,\n" +
|
||||
"\t\tSUBPARTITION pq4002 TABLESPACE tbs_03,\n" +
|
||||
"\t\tSUBPARTITION pq4003 TABLESPACE tbs_03,\n" +
|
||||
"\t\tSUBPARTITION pq4004 TABLESPACE tbs_03\n" +
|
||||
"\t)\n" +
|
||||
");"
|
||||
, SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
|
||||
assertTrue(visitor.getTables().containsKey(new TableStat.Name("composite_sales")));
|
||||
|
||||
assertEquals(2, 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")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreateIndexTest6 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE INDEX ord_customer_ix_demo\n" +
|
||||
" ON orders (order_mode)\n" +
|
||||
" NOSORT\n" +
|
||||
" NOLOGGING;";
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
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 ord_customer_ix_demo ON orders(order_mode) NOSORT\n" +
|
||||
"NOLOGGING;", SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
|
||||
assertTrue(visitor.getTables().containsKey(new TableStat.Name("orders")));
|
||||
|
||||
assertEquals(1, visitor.getColumns().size());
|
||||
|
||||
assertTrue(visitor.getColumns().contains(new TableStat.Column("orders", "order_mode")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 OracleCreateIndexTest7 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE INDEX ord_customer_ix_demo \n" +
|
||||
" ON orders (customer_id, sales_rep_id)\n" +
|
||||
" COMPRESS 1;\n";
|
||||
|
||||
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 ord_customer_ix_demo ON orders(customer_id, sales_rep_id)\n" +
|
||||
"COMPRESS 1;", SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
|
||||
assertTrue(visitor.getTables().containsKey(new TableStat.Name("orders")));
|
||||
|
||||
assertEquals(2, visitor.getColumns().size());
|
||||
|
||||
assertTrue(visitor.getColumns().contains(new TableStat.Column("orders", "sales_rep_id")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 OracleCreateIndexTest8_cluster extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE INDEX idx_personnel ON CLUSTER personnel; ";
|
||||
|
||||
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 idx_personnel ON CLUSTER personnel;", SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
|
||||
assertTrue(visitor.getTables().containsKey(new TableStat.Name("personnel")));
|
||||
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("orders", "sales_rep_id")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
|
||||
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
|
||||
}
|
||||
}
|
||||
@@ -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 OracleCreateIndexTest9 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"CREATE INDEX area_index ON xwarehouses e \n" +
|
||||
" (EXTRACTVALUE(VALUE(e),'/Warehouse/Area'));";
|
||||
|
||||
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 area_index ON xwarehouses e(EXTRACTVALUE(VALUE(e), '/Warehouse/Area'));", SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
|
||||
assertTrue(visitor.getTables().containsKey(new TableStat.Name("xwarehouses")));
|
||||
|
||||
assertEquals(0, 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")));
|
||||
}
|
||||
}
|
||||
@@ -80,8 +80,7 @@ public class OracleCreateTableTest36 extends OracleTest {
|
||||
+ "\n\tamount_sold NUMBER(10, 2)"
|
||||
+ "\n)"
|
||||
+ "\nPARTITION BY RANGE (time_id)"
|
||||
+ "\nSUBPARTITION BY HASH (channel_id)"
|
||||
+ "\n("
|
||||
+ "\nSUBPARTITION BY HASH (channel_id) ("
|
||||
+ "\n\tPARTITION SALES_Q1_1998 VALUES LESS THAN (TO_DATE('01-APR-1998', 'DD-MON-YYYY')),"
|
||||
+ "\n\tPARTITION SALES_Q2_1998 VALUES LESS THAN (TO_DATE('01-JUL-1998', 'DD-MON-YYYY')),"
|
||||
+ "\n\tPARTITION SALES_Q3_1998 VALUES LESS THAN (TO_DATE('01-OCT-1998', 'DD-MON-YYYY')),"
|
||||
@@ -93,8 +92,7 @@ public class OracleCreateTableTest36 extends OracleTest {
|
||||
+ "\n\tPARTITION SALES_Q1_2000 VALUES LESS THAN (TO_DATE('01-APR-2000', 'DD-MON-YYYY')),"
|
||||
+ "\n\tPARTITION SALES_Q2_2000 VALUES LESS THAN (TO_DATE('01-JUL-2000', 'DD-MON-YYYY'))"
|
||||
+ "\n\t\tSUBPARTITIONS 8,"
|
||||
+ "\n\tPARTITION SALES_Q3_2000 VALUES LESS THAN (TO_DATE('01-OCT-2000', 'DD-MON-YYYY'))"
|
||||
+ "\n\t("
|
||||
+ "\n\tPARTITION SALES_Q3_2000 VALUES LESS THAN (TO_DATE('01-OCT-2000', 'DD-MON-YYYY')) ("
|
||||
+ "\n\t\tSUBPARTITION ch_c,"
|
||||
+ "\n\t\tSUBPARTITION ch_i,"
|
||||
+ "\n\t\tSUBPARTITION ch_p,"
|
||||
|
||||
@@ -53,8 +53,7 @@ public class OracleCreateTableTest39 extends OracleTest {
|
||||
+ "\n\tcust_last_name varchar2(20),"
|
||||
+ "\n\tcredit_limit number(9, 2)"
|
||||
+ "\n)"
|
||||
+ "\nPARTITION BY RANGE (credit_limit) INTERVAL 1000"
|
||||
+ "\n("
|
||||
+ "\nPARTITION BY RANGE (credit_limit) INTERVAL 1000 ("
|
||||
+ "\n\tPARTITION p1 VALUES LESS THAN (5001)"
|
||||
+ "\n);",//
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
+18
-19
@@ -56,25 +56,24 @@ public class OracleCreateTableTest40 extends OracleTest {
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
Assert.assertEquals("CREATE TABLE customers_part ("
|
||||
+ "\n\tcustomer_id NUMBER(6),"
|
||||
+ "\n\tcust_first_name VARCHAR2(20),"
|
||||
+ "\n\tcust_last_name VARCHAR2(20),"
|
||||
+ "\n\tnls_territory VARCHAR2(30),"
|
||||
+ "\n\tcredit_limit NUMBER(9, 2)"
|
||||
+ "\n)"
|
||||
+ "\nPARTITION BY RANGE (credit_limit)"
|
||||
+ "\nSUBPARTITION BY HASH (nls_territory)"
|
||||
+ "\n\tSUBPARTITION TEMPLATE ("
|
||||
+ "\n\t\tSUBPARTITION east VALUES ('CHINA', 'JAPAN', 'INDIA', 'THAILAND'),"
|
||||
+ "\n\t\tSUBPARTITION west VALUES ('AMERICA', 'GERMANY', 'ITALY', 'SWITZERLAND'),"
|
||||
+ "\n\t\tSUBPARTITION other VALUES (DEFAULT)"
|
||||
+ "\n\t)"
|
||||
+ "\n("
|
||||
+ "\n\tPARTITION p1 VALUES LESS THAN (1000),"
|
||||
+ "\n\tPARTITION p2 VALUES LESS THAN (2500),"
|
||||
+ "\n\tPARTITION p3 VALUES LESS THAN (MAXVALUE)"
|
||||
+ "\n);",//
|
||||
Assert.assertEquals("CREATE TABLE customers_part (\n" +
|
||||
"\tcustomer_id NUMBER(6),\n" +
|
||||
"\tcust_first_name VARCHAR2(20),\n" +
|
||||
"\tcust_last_name VARCHAR2(20),\n" +
|
||||
"\tnls_territory VARCHAR2(30),\n" +
|
||||
"\tcredit_limit NUMBER(9, 2)\n" +
|
||||
")\n" +
|
||||
"PARTITION BY RANGE (credit_limit)\n" +
|
||||
"SUBPARTITION BY HASH (nls_territory)\n" +
|
||||
"\tSUBPARTITION TEMPLATE (\n" +
|
||||
"\t\tSUBPARTITION east VALUES ('CHINA', 'JAPAN', 'INDIA', 'THAILAND'),\n" +
|
||||
"\t\tSUBPARTITION west VALUES ('AMERICA', 'GERMANY', 'ITALY', 'SWITZERLAND'),\n" +
|
||||
"\t\tSUBPARTITION other VALUES (DEFAULT)\n" +
|
||||
"\t) (\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));
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
|
||||
@@ -186,8 +186,7 @@ public class OracleCreateTableTest49 extends OracleTest {
|
||||
"\tCHUNK 8192\n" +
|
||||
"\tNOCACHE\n" +
|
||||
")\n" +
|
||||
"PARTITION BY RANGE (\"GMT_CREATE\")\n" +
|
||||
"(\n" +
|
||||
"PARTITION BY RANGE (\"GMT_CREATE\") (\n" +
|
||||
"\tPARTITION \"P2008\" VALUES LESS THAN (TO_DATE(' 2009-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))\n" +
|
||||
"\t\tPCTFREE 10\n" +
|
||||
"\t\tPCTUSED 40\n" +
|
||||
|
||||
@@ -95,8 +95,7 @@ public class OracleCreateTableTest58 extends OracleTest {
|
||||
"STORAGE (\n" +
|
||||
"\tBUFFER_POOL DEFAULT\n" +
|
||||
")\n" +
|
||||
"PARTITION BY RANGE (\"ID\")\n" +
|
||||
"(\n" +
|
||||
"PARTITION BY RANGE (\"ID\") (\n" +
|
||||
"\tPARTITION \"P1\" VALUES LESS THAN (2000000000)\n" +
|
||||
"\t\tPCTFREE 10\n" +
|
||||
"\t\tPCTUSED 40\n" +
|
||||
|
||||
@@ -70,7 +70,7 @@ public class OracleCreateTableTest59 extends OracleTest {
|
||||
"\tPCTFREE 10\n" +
|
||||
"\tINITRANS 2\n" +
|
||||
"\tMAXTRANS 255\n" +
|
||||
"\tCOMPRESS\n" +
|
||||
"\tCOMPRESS 1\n" +
|
||||
"\tLOGGING\n" +
|
||||
"\tTABLESPACE \"ZEUS_IND\"\n" +
|
||||
"\tSTORAGE (\n" +
|
||||
|
||||
@@ -98,8 +98,7 @@ public class OracleCreateTableTest62 extends OracleTest {
|
||||
"\tFLASH_CACHE DEFAULT\n" +
|
||||
"\tCELL_FLASH_CACHE DEFAULT\n" +
|
||||
")\n" +
|
||||
"PARTITION BY RANGE (\"GMT_VOUCHER_RECEIVE\")\n" +
|
||||
"(\n" +
|
||||
"PARTITION BY RANGE (\"GMT_VOUCHER_RECEIVE\") (\n" +
|
||||
"\tPARTITION \"PONLY\" VALUES LESS THAN (MAXVALUE)\n" +
|
||||
"\t\tPCTFREE 10\n" +
|
||||
"\t\tPCTUSED 40\n" +
|
||||
|
||||
@@ -235,8 +235,7 @@ public class OracleCreateTableTest66 extends OracleTest {
|
||||
"\tFLASH_CACHE DEFAULT\n" +
|
||||
"\tCELL_FLASH_CACHE DEFAULT\n" +
|
||||
")\n" +
|
||||
"PARTITION BY RANGE (\"LRSJ\")\n" +
|
||||
"(\n" +
|
||||
"PARTITION BY RANGE (\"LRSJ\") (\n" +
|
||||
"\tPARTITION \"T_RANGE_V1\" VALUES LESS THAN (TO_DATE(' 2015-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))\n" +
|
||||
"\t\tPCTFREE 80\n" +
|
||||
"\t\tPCTUSED 40\n" +
|
||||
|
||||
Reference in New Issue
Block a user