mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor
This commit is contained in:
@@ -167,7 +167,7 @@ public class ArithmeticOperatorsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT 1 = 0 OR A > ?;", text);
|
||||
Assert.assertEquals("SELECT 1 = 0\n\tOR A > ?;", text);
|
||||
}
|
||||
|
||||
public void test_13() throws Exception {
|
||||
@@ -178,7 +178,7 @@ public class ArithmeticOperatorsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT 1 = 0 AND ID = ?;", text);
|
||||
Assert.assertEquals("SELECT 1 = 0\n\tAND ID = ?;", text);
|
||||
}
|
||||
|
||||
private String output(List<SQLStatement> stmtList) {
|
||||
|
||||
@@ -123,7 +123,7 @@ public class LogicalOperatorsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT 1 AND 1;", text);
|
||||
Assert.assertEquals("SELECT 1\n\tAND 1;", text);
|
||||
}
|
||||
|
||||
public void test_9() throws Exception {
|
||||
@@ -134,7 +134,7 @@ public class LogicalOperatorsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT 1 AND NULL;", text);
|
||||
Assert.assertEquals("SELECT 1\n\tAND NULL;", text);
|
||||
}
|
||||
|
||||
public void test_10() throws Exception {
|
||||
@@ -145,7 +145,7 @@ public class LogicalOperatorsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT 0 OR NULL;", text);
|
||||
Assert.assertEquals("SELECT 0\n\tOR NULL;", text);
|
||||
}
|
||||
|
||||
public void test_11() throws Exception {
|
||||
|
||||
@@ -20,13 +20,16 @@ public class OracleGroupingSetTest extends TestCase {
|
||||
+ "GROUP BY GROUPING SETS((channel_desc, calendar_month_desc, co.country_id), (channel_desc, co.country_id), "
|
||||
+ "( calendar_month_desc, co.country_id) );\n";
|
||||
|
||||
String expected = "SELECT channel_desc, calendar_month_desc, co.country_id, "
|
||||
+ "TO_CHAR(sum(amount_sold), '9,999,999,999') AS SALES$\n"
|
||||
+ "FROM sales, customers, times, channels, countries co\n"
|
||||
+ "WHERE sales.time_id = times.time_id AND sales.cust_id = customers.cust_id AND sales.channel_id = channels.channel_id "
|
||||
+ "AND customers.country_id = co.country_id AND channels.channel_desc IN ('Direct Sales', 'Internet') "
|
||||
+ "AND times.calendar_month_desc IN ('2000-09', '2000-10') "
|
||||
+ "AND co.country_id IN ('UK', 'US')\n"
|
||||
String expected = "SELECT channel_desc, calendar_month_desc, co.country_id, " //
|
||||
+ "TO_CHAR(sum(amount_sold), '9,999,999,999') AS SALES$\n" //
|
||||
+ "FROM sales, customers, times, channels, countries co\n" //
|
||||
+ "WHERE sales.time_id = times.time_id" //
|
||||
+ "\n\tAND sales.cust_id = customers.cust_id" //
|
||||
+ "\n\tAND sales.channel_id = channels.channel_id" //
|
||||
+ "\n\tAND customers.country_id = co.country_id" //
|
||||
+ "\n\tAND channels.channel_desc IN ('Direct Sales', 'Internet')" //
|
||||
+ "\n\tAND times.calendar_month_desc IN ('2000-09', '2000-10')"
|
||||
+ "\n\tAND co.country_id IN ('UK', 'US')\n"
|
||||
+ "GROUP BY GROUPING SETS ((channel_desc, calendar_month_desc, co.country_id), (channel_desc, co.country_id), "
|
||||
+ "(calendar_month_desc, co.country_id));\n";
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public class OraclePivotClauseTest extends TestCase {
|
||||
+ "ORDER BY year, order_mode;";
|
||||
|
||||
String expected = "SELECT *\n" + "FROM pivot_table\n"
|
||||
+ "\tUNPIVOT (yearly_total FOR order_mode IN (store AS 'direct', internet AS 'online'))\n"
|
||||
+ "UNPIVOT (yearly_total FOR order_mode IN (store AS 'direct', internet AS 'online'))\n"
|
||||
+ "ORDER BY year, order_mode;\n";
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
@@ -34,9 +34,9 @@ public class OraclePivotClauseTest extends TestCase {
|
||||
+ "PIVOT (SUM(order_total) FOR order_mode IN ('direct' AS Store, 'online' AS Internet));\n";
|
||||
|
||||
String expected = "SELECT *\n"
|
||||
+ "FROM (SELECT EXTRACT(YEAR FROM order_date) AS YEAR, order_mode, order_total\n"
|
||||
+ "\tFROM orders\n" + "\t)\n"
|
||||
+ "\tPIVOT (SUM(order_total) FOR order_mode IN ('direct' AS Store, 'online' AS Internet));\n";
|
||||
+ "FROM (\n\tSELECT EXTRACT(YEAR FROM order_date) AS YEAR, order_mode, order_total\n"
|
||||
+ "\tFROM orders\n" + ")\n"
|
||||
+ "PIVOT (SUM(order_total) FOR order_mode IN ('direct' AS Store, 'online' AS Internet));\n";
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
@@ -54,9 +54,9 @@ public class OraclePivotClauseTest extends TestCase {
|
||||
+ "PIVOT (SUM(order_total) FOR order_mode IN ('direct' AS Store, 'online' AS Internet));\n";
|
||||
|
||||
String expected = "SELECT *\n"
|
||||
+ "FROM (SELECT EXTRACT(YEAR FROM order_date) AS YEAR, order_mode, order_total\n"
|
||||
+ "\tFROM orders\n" + "\t)\n"
|
||||
+ "\tPIVOT (SUM(order_total) FOR order_mode IN ('direct' AS Store, 'online' AS Internet));\n";
|
||||
+ "FROM (\n\tSELECT EXTRACT(YEAR FROM order_date) AS YEAR, order_mode, order_total\n"
|
||||
+ "\tFROM orders\n" + ")\n"
|
||||
+ "PIVOT (SUM(order_total) FOR order_mode IN ('direct' AS Store, 'online' AS Internet));\n";
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
@@ -73,9 +73,9 @@ public class OraclePivotClauseTest extends TestCase {
|
||||
+ "FROM (SELECT EXTRACT(YEAR FROM order_date) as day, order_mode, order_total FROM orders)\n"
|
||||
+ "PIVOT (SUM(order_total) FOR order_mode IN ('direct' AS Store, 'online' AS Internet));\n";
|
||||
|
||||
String expected = "SELECT *\n" + "FROM (SELECT EXTRACT(YEAR FROM order_date) AS DAY, order_mode, order_total\n"
|
||||
+ "\tFROM orders\n" + "\t)\n"
|
||||
+ "\tPIVOT (SUM(order_total) FOR order_mode IN ('direct' AS Store, 'online' AS Internet));\n";
|
||||
String expected = "SELECT *\n" + "FROM (\n\tSELECT EXTRACT(YEAR FROM order_date) AS DAY, order_mode, order_total\n"
|
||||
+ "\tFROM orders\n" + ")\n"
|
||||
+ "PIVOT (SUM(order_total) FOR order_mode IN ('direct' AS Store, 'online' AS Internet));\n";
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
@@ -93,9 +93,9 @@ public class OraclePivotClauseTest extends TestCase {
|
||||
+ "PIVOT (SUM(order_total) FOR order_mode IN ('direct' AS Store, 'online' AS Internet));\n";
|
||||
|
||||
String expected = "SELECT *\n"
|
||||
+ "FROM (SELECT EXTRACT(YEAR FROM order_date) AS DAY, order_mode AS YEAR, order_total\n"
|
||||
+ "\tFROM orders\n" + "\t)\n"
|
||||
+ "\tPIVOT (SUM(order_total) FOR order_mode IN ('direct' AS Store, 'online' AS Internet));\n";
|
||||
+ "FROM (\n\tSELECT EXTRACT(YEAR FROM order_date) AS DAY, order_mode AS YEAR, order_total\n"
|
||||
+ "\tFROM orders\n" + ")\n"
|
||||
+ "PIVOT (SUM(order_total) FOR order_mode IN ('direct' AS Store, 'online' AS Internet));\n";
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
@@ -12,7 +12,7 @@ public class OracleSampleClauseTest extends TestCase {
|
||||
public void test_0() throws Exception {
|
||||
String sql = "SELECT COUNT(*) * 10 FROM orders SAMPLE (10);";
|
||||
|
||||
String expected = "SELECT COUNT(*) * 10\n" + "FROM orders\n" + "SAMPLE (10);\n";
|
||||
String expected = "SELECT COUNT(*) * 10\n" + "FROM orders SAMPLE (10);\n";
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
@@ -27,7 +27,7 @@ public class OracleSampleClauseTest extends TestCase {
|
||||
public void test_1() throws Exception {
|
||||
String sql = "SELECT COUNT(*) * 10 FROM orders SAMPLE (10) SEED (1);";
|
||||
|
||||
String expected = "SELECT COUNT(*) * 10\n" + "FROM orders\n" + "SAMPLE (10) SEED (1);\n";
|
||||
String expected = "SELECT COUNT(*) * 10\n" + "FROM orders SAMPLE (10) SEED (1);\n";
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class OracleOutputVisitorTest_selectJoin extends TestCase {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
OracleOutputVisitor outputVisitor = new OracleOutputVisitor(buf);
|
||||
stmt.accept(outputVisitor);
|
||||
Assert.assertEquals("SELECT e.salary\nFROM employee e JOIN department d\nWHERE e.depId = d.id;\n",
|
||||
Assert.assertEquals("SELECT e.salary\nFROM employee e\n\tJOIN department d\nWHERE e.depId = d.id;\n",
|
||||
buf.toString());
|
||||
|
||||
}
|
||||
|
||||
@@ -6,21 +6,20 @@ import java.io.Reader;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlParameterizedOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class OracleResourceTest extends TestCase {
|
||||
public class OracleResourceTest extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
// 13
|
||||
exec_test("bvt/parser/oracle-53.txt");
|
||||
exec_test("bvt/parser/oracle-17.txt");
|
||||
// for (int i = 0; i <= 53; ++i) {
|
||||
// exec_test("bvt/parser/oracle-" + i + ".txt");
|
||||
// }
|
||||
@@ -43,11 +42,14 @@ public class OracleResourceTest extends TestCase {
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
print(statementList);
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
statemen.accept(visitor);
|
||||
|
||||
System.out.println(sql);
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
|
||||
@@ -72,14 +74,4 @@ public class OracleResourceTest extends TestCase {
|
||||
Assert.assertEquals(expect, out.toString());
|
||||
}
|
||||
|
||||
private String output(List<SQLStatement> stmtList) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
MySqlOutputVisitor visitor = new MySqlOutputVisitor(out);
|
||||
|
||||
for (SQLStatement stmt : stmtList) {
|
||||
stmt.accept(visitor);
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user