use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class OdpsSelectTest33 method test_select.
public void test_select() throws Exception {
// 1095288847322
//
String sql = "SELECT * from mytable1 a LEFT ANTI JOIN mytable2 b on a.id=b.id;";
assertEquals("SELECT *\n" + "FROM mytable1 a\n" + "LEFT ANTI JOIN mytable2 b\n" + "ON a.id = b.id;", SQLUtils.formatOdps(sql));
assertEquals("select *\n" + "from mytable1 a\n" + "left anti join mytable2 b\n" + "on a.id = b.id;", SQLUtils.formatOdps(sql, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ODPS);
SQLStatement stmt = statementList.get(0);
assertEquals(1, statementList.size());
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ODPS);
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());
assertEquals(2, visitor.getTables().size());
assertEquals(4, visitor.getColumns().size());
assertEquals(2, visitor.getConditions().size());
// System.out.println(SQLUtils.formatOdps(sql));
// assertTrue(visitor.getColumns().contains(new Column("abc", "name")));
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class OdpsSelectTest35 method test_select.
public void test_select() throws Exception {
// 1095288847322
String sql = "SELECT a.city, a.car_id, a.rrc_id, a.brand, a.car_series\n" + " , a.title\n" + "FROM dw_x001_cp_used_car_detail a\n" + "WHERE status = 'PUBLISHED'\n" + " AND model_id = 4419\n" + //
" AND abs(datediff(licensed_date, '2013-07-01 00:00:00', 'mm')) <= 5;";
assertEquals("SELECT a.city, a.car_id, a.rrc_id, a.brand, a.car_series\n" + "\t, a.title\n" + "FROM dw_x001_cp_used_car_detail a\n" + "WHERE status = 'PUBLISHED'\n" + "\tAND model_id = 4419\n" + "\tAND abs(datediff(licensed_date, '2013-07-01 00:00:00', 'mm')) <= 5;", SQLUtils.formatOdps(sql));
assertEquals("select a.city, a.car_id, a.rrc_id, a.brand, a.car_series\n" + "\t, a.title\n" + "from dw_x001_cp_used_car_detail a\n" + "where status = 'PUBLISHED'\n" + "\tand model_id = 4419\n" + "\tand abs(datediff(licensed_date, '2013-07-01 00:00:00', 'mm')) <= 5;", SQLUtils.formatOdps(sql, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ODPS);
SQLStatement stmt = statementList.get(0);
assertEquals(1, statementList.size());
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ODPS);
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());
assertEquals(1, visitor.getTables().size());
assertEquals(9, visitor.getColumns().size());
assertEquals(2, visitor.getConditions().size());
// System.out.println(SQLUtils.formatOdps(sql));
// assertTrue(visitor.getColumns().contains(new Column("abc", "name")));
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class OdpsSelectTest21 method test_select.
public void test_select() throws Exception {
// 1095288847322
//
String sql = "select wm_concat(',', a) from values('abc', 1), (null, 2) t (a, i);";
Assert.assertEquals("SELECT wm_concat(',', a)\n" + "FROM (VALUES ('abc', 1), (NULL, 2)) AS t (a, i);", SQLUtils.formatOdps(sql));
Assert.assertEquals("select wm_concat(',', a)\n" + "from (values ('abc', 1), (null, 2)) as t (a, i);", SQLUtils.formatOdps(sql, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ODPS);
SQLStatement stmt = statementList.get(0);
Assert.assertEquals(1, statementList.size());
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ODPS);
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(0, visitor.getTables().size());
Assert.assertEquals(0, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
// Assert.assertTrue(visitor.getColumns().contains(new Column("abc", "name")));
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class OdpsSelectTest27 method test_select.
public void test_select() throws Exception {
// 1095288847322
String sql = "select case when aaa < 0.1 then 2 else 1 end as abc\n" + //
"from bigdata_xy.dual;";
assertEquals("SELECT CASE \n" + "\t\tWHEN aaa < 0.1 THEN 2\n" + "\t\tELSE 1\n" + "\tEND AS abc\n" + "FROM bigdata_xy.dual;", SQLUtils.formatOdps(sql));
assertEquals("select case \n" + "\t\twhen aaa < 0.1 then 2\n" + "\t\telse 1\n" + "\tend as abc\n" + "from bigdata_xy.dual;", SQLUtils.formatOdps(sql, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ODPS);
SQLStatement stmt = statementList.get(0);
assertEquals(1, statementList.size());
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ODPS);
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());
assertEquals(1, visitor.getTables().size());
assertEquals(1, visitor.getColumns().size());
assertEquals(1, visitor.getConditions().size());
// System.out.println(SQLUtils.formatOdps(sql));
// assertTrue(visitor.getColumns().contains(new Column("abc", "name")));
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class OracleDropTypeTest_0 method test_0.
public void test_0() throws Exception {
//
String sql = "DROP type dmcfck;";
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("DROP TYPE dmcfck;", SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
assertEquals(0, visitor.getTables().size());
// assertTrue(visitor.getTables().containsKey(new TableStat.Name("t1")));
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")));
}
Aggregations