use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class OdpsListResourcesTest method exec_test.
public void exec_test(String resource) throws Exception {
// System.out.println(resource);
InputStream is = null;
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
Reader reader = new InputStreamReader(is, "UTF-8");
String input = Utils.read(reader);
JdbcUtils.close(reader);
String[] items = input.split("---------------------------");
String sql = items[0].trim();
String expect = items[1].trim();
OdpsStatementParser parser = new OdpsStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
Assert.assertEquals(1, statementList.size());
SchemaStatVisitor visitor = new OdpsSchemaStatVisitor();
stmt.accept(visitor);
// System.out.println(sql);
// System.out.println("Tables : " + visitor.getTables());
// System.out.println("fields : " + visitor.getColumns());
//
// System.out.println();
// System.out.println("---------------------------");
// System.out.println(SQLUtils.toOdpsString(stmt));
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class OdpsAlterTableAddColumnsTest method test_select.
public void test_select() throws Exception {
//
String sql = "alter table adl_smeta_column_indi_rule_relation_sdt add columns (rule_level string);";
Assert.assertEquals("ALTER TABLE adl_smeta_column_indi_rule_relation_sdt\n" + "\tADD COLUMNS (rule_level STRING);", SQLUtils.formatOdps(sql));
Assert.assertEquals("alter table adl_smeta_column_indi_rule_relation_sdt\n" + "\tadd columns (rule_level string);", 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(1, visitor.getTables().size());
Assert.assertEquals(1, 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 OdpsAlterTableChangeColumnTest method test_select.
public void test_select() throws Exception {
//
String sql = "ALTER TABLE adl_smeta_indi_rule_relation_sdt CHANGE COLUMN indi_level COMMENT 'xxxx';";
Assert.assertEquals("ALTER TABLE adl_smeta_indi_rule_relation_sdt\n" + "\tCHANGE COLUMN indi_level COMMENT 'xxxx';", SQLUtils.formatOdps(sql));
Assert.assertEquals("alter table adl_smeta_indi_rule_relation_sdt\n" + "\tchange column indi_level comment 'xxxx';", 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(1, visitor.getTables().size());
Assert.assertEquals(1, 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 OdpsSelectTest15 method test_select.
public void test_select() throws Exception {
//
String sql = "SELECT '\\n' FROM dual;";
Assert.assertEquals("SELECT '\\n'" + "\nFROM dual;", SQLUtils.formatOdps(sql));
Assert.assertEquals("select '\\n'" + "\nfrom dual;", 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(1, 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 OdpsSelectTest16 method test_select.
public void test_select() throws Exception {
//
String sql = "SELECT \"\\n\" FROM dual;";
Assert.assertEquals("SELECT '\\n'" + "\nFROM dual;", SQLUtils.formatOdps(sql));
Assert.assertEquals("select '\\n'" + "\nfrom dual;", 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(1, visitor.getTables().size());
Assert.assertEquals(0, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
// Assert.assertTrue(visitor.getColumns().contains(new Column("abc", "name")));
}
Aggregations