use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class OdpsDoubleQuoteTest method test_0.
public void test_0() throws Exception {
String sql = "SELECT my_udtf(1,2,3) as (a, b, c) from employee t1 WHERE t1.name = \"aaa\";";
OdpsStatementParser parser = new OdpsStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
Assert.assertEquals(1, statementList.size());
OdpsSchemaStatVisitor visitor = new OdpsSchemaStatVisitor();
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(1, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("employee")));
Assert.assertTrue(visitor.getColumns().contains(new Column("employee", "name")));
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class OdpsSelectTest7 method test_select.
public void test_select() throws Exception {
//
String sql = "select name as close from abc";
Assert.assertEquals("SELECT name AS close" + "\nFROM abc", SQLUtils.formatOdps(sql));
Assert.assertEquals("select name as close" + "\nfrom abc", 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.stat.TableStat.Column in project druid by alibaba.
the class OracleSchemaStatVisitorTest method test_0.
public void test_0() throws Exception {
String sql = //
"SELECT id, name name from department d" + " WHERE d.id = ? order by name desc";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
List<Object> parameters = new ArrayList<Object>();
parameters.add(23456);
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
visitor.setParameters(parameters);
statemen.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());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("department")));
Assert.assertEquals(2, visitor.getColumns().size());
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("department", "id")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("department", "name")));
Assert.assertEquals(1, visitor.getConditions().size());
Condition condition = visitor.getConditions().get(0);
Assert.assertSame(parameters.get(0), condition.getValues().get(0));
Column orderByColumn = visitor.getOrderByColumns().iterator().next();
Assert.assertEquals(SQLOrderingSpecification.DESC, orderByColumn.getAttributes().get("orderBy.type"));
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class OracleOutputVisitorTest_dblink method test_0.
public void test_0() throws Exception {
String sql = "SELECT salary from master@emp";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
Assert.assertEquals(1, statementList.size());
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
stmt.accept(visitor);
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(true, visitor.containsTable("master@emp"));
Assert.assertEquals(1, visitor.getColumns().size());
Assert.assertEquals(true, visitor.getColumns().contains(new Column("master@emp", "salary")));
StringBuilder buf = new StringBuilder();
OracleOutputVisitor outputVisitor = new OracleOutputVisitor(buf);
stmt.accept(outputVisitor);
Assert.assertEquals("SELECT salary\nFROM master@emp;\n", buf.toString());
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class OracleSchemaStatVisitorTest_Subquery2 method test_0.
public void test_0() throws Exception {
String sql = "SELECT a.id, a.name, b.name groupName FROM (select id, name, groupId from users WHERE ROWNUM < 10) a inner join groups b on a.groupId = b.id";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
Assert.assertEquals(1, statementList.size());
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
statemen.accept(visitor);
System.out.println(sql);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
Assert.assertEquals(2, visitor.getTables().size());
Assert.assertEquals(true, visitor.containsTable("users"));
Assert.assertEquals(true, visitor.containsTable("groups"));
Assert.assertEquals(5, visitor.getColumns().size());
Assert.assertEquals(true, visitor.getColumns().contains(new Column("users", "id")));
Assert.assertEquals(true, visitor.getColumns().contains(new Column("users", "groupId")));
Assert.assertEquals(true, visitor.getColumns().contains(new Column("users", "name")));
Assert.assertEquals(true, visitor.getColumns().contains(new Column("groups", "id")));
Assert.assertEquals(true, visitor.getColumns().contains(new Column("groups", "name")));
}
Aggregations