use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class PhoenixUpsertTest_std method test_0.
public void test_0() throws Exception {
String sql = "upsert into t_1 (a,b,c) values (?,?,?)";
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, null);
SQLStatement stmt = statementList.get(0);
Assert.assertEquals(1, statementList.size());
SchemaStatVisitor visitor = new PhoenixSchemaStatVisitor();
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(3, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t_1")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "a")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "b")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("t_1", "c")));
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
// Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
String output = SQLUtils.toSQLString(stmt, JdbcConstants.PHOENIX);
Assert.assertEquals("UPSERT INTO t_1 (a, b, c)\n" + //
"VALUES (?, ?, ?)", output);
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class SchemaStatTest7 method test_schemaStat.
public void test_schemaStat() throws Exception {
String sql = "select t.a,t.b from t where cast(t.statdate as decimal) >=20160626";
String dbType = JdbcConstants.MYSQL;
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
SQLStatement stmt = parser.parseStatementList().get(0);
SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(dbType);
stmt.accept(statVisitor);
// System.out.println(statVisitor.getColumns());
// System.out.println(statVisitor.getGroupByColumns()); // group by
Assert.assertEquals(3, statVisitor.getColumns().size());
Assert.assertEquals(1, statVisitor.getConditions().size());
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class SchemaStatTest9 method test_schemaStat.
public void test_schemaStat() throws Exception {
String sql = "select now() from t";
String dbType = JdbcConstants.ORACLE;
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
SQLStatement stmt = parser.parseStatementList().get(0);
SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(dbType);
stmt.accept(statVisitor);
// System.out.println(statVisitor.getColumns());
// System.out.println(statVisitor.getGroupByColumns()); // group by
// System.out.println("relationships : " + statVisitor.getRelationships()); // group by
Assert.assertEquals(0, statVisitor.getColumns().size());
Assert.assertEquals(0, statVisitor.getConditions().size());
assertEquals(1, statVisitor.getFunctions().size());
assertEquals("now", statVisitor.getFunctions().get(0).getMethodName());
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class SchemaStatTest method test_schemaStat.
public void test_schemaStat() throws Exception {
String sql = "select " + " create_time_dd as 来电日期" + " from alisec_app.adl_tb_wing_rubbish_laidian_new_reason_realname_fdt " + " order by 来电日期 desc limit 30;";
String dbType = JdbcConstants.ODPS;
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
SQLStatement stmt = parser.parseStatementList().get(0);
SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(dbType);
stmt.accept(statVisitor);
System.out.println(statVisitor.getColumns());
Assert.assertEquals(1, statVisitor.getColumns().size());
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class SchemaStatTest11 method test_schemaStat.
public void test_schemaStat() throws Exception {
String sql = "select a.id, b.name from (select * from table1) a inner join table2 b on a.id = b.id";
String dbType = JdbcConstants.ORACLE;
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
SQLStatement stmt = parser.parseStatementList().get(0);
SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(dbType);
stmt.accept(statVisitor);
Set<TableStat.Relationship> relationships = statVisitor.getRelationships();
for (TableStat.Relationship relationship : relationships) {
// table1.id = table2.id
System.out.println(relationship);
}
// System.out.println(statVisitor.getColumns());
// System.out.println(statVisitor.getGroupByColumns()); // group by
// group by
System.out.println("relationships : " + statVisitor.getRelationships());
System.out.println(statVisitor.getConditions());
assertEquals(1, relationships.size());
Assert.assertEquals(3, statVisitor.getColumns().size());
Assert.assertEquals(2, statVisitor.getConditions().size());
assertEquals(0, statVisitor.getFunctions().size());
}
Aggregations