use of com.alibaba.druid.DbType in project druid by alibaba.
the class SchemaStatTest10 method test_schemaStat.
public void test_schemaStat() throws Exception {
String sql = "select a.id, b.name from table1 a inner join table2 b on a.id = b.id";
DbType 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());
Assert.assertEquals(3, statVisitor.getColumns().size());
Assert.assertEquals(2, statVisitor.getConditions().size());
assertEquals(0, statVisitor.getFunctions().size());
}
use of com.alibaba.druid.DbType in project druid by alibaba.
the class SchemaStatTest13 method test_schemaStat.
public void test_schemaStat() throws Exception {
String sql = "select a.id, b.name from (select t1.* from table1 t1 left join table3 t3 on cast(t1.id as bigint) = t3.id) a inner join table2 b on a.id = b.id";
DbType dbType = JdbcConstants.ORACLE;
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
SQLStatement stmt = parser.parseStatementList().get(0);
System.out.println(stmt);
SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(dbType);
stmt.accept(statVisitor);
Set<TableStat.Relationship> relationships = statVisitor.getRelationships();
System.out.println("columns : " + statVisitor.getColumns());
// group by
System.out.println("groups : " + statVisitor.getGroupByColumns());
// group by
System.out.println("relationships : " + statVisitor.getRelationships());
System.out.println("conditions : " + statVisitor.getConditions());
assertEquals(2, relationships.size());
Assert.assertEquals(5, statVisitor.getColumns().size());
Assert.assertEquals(4, statVisitor.getConditions().size());
assertEquals(0, statVisitor.getFunctions().size());
}
use of com.alibaba.druid.DbType in project druid by alibaba.
the class SchemaStatTest6 method test_schemaStat.
public void test_schemaStat() throws Exception {
String sql = "select count(1), name from tg_rpc_user where id < 5 group by name order by id desc";
DbType 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());
// group by
System.out.println(statVisitor.getGroupByColumns());
Assert.assertEquals(2, statVisitor.getColumns().size());
}
use of com.alibaba.druid.DbType in project druid by alibaba.
the class SchemaStatTest8 method test_schemaStat.
public void test_schemaStat() throws Exception {
String sql = "SELECT * FROM AQLQCAT " + "JOIN AQLQCATB " + " ON AQLQCAT.ZZ = AQLQCATB.RR " + " AND trim(AQLQCAT.BB) = AQLQCATB.DD " + "WHERE AQLQCAT.MANDT = 'A0' " + " AND AQLQCATB.NUM = 'A1'";
DbType 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
// group by
System.out.println("relationships : " + statVisitor.getRelationships());
Assert.assertEquals(8, statVisitor.getColumns().size());
Assert.assertEquals(6, statVisitor.getConditions().size());
}
use of com.alibaba.druid.DbType in project druid by alibaba.
the class SchemaStatTest2 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;";
DbType 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());
Assert.assertEquals(1, statVisitor.getColumns().size());
}
Aggregations