use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class MySqlSchemaStatVisitorTest_Alter method test_0.
public void test_0() throws Exception {
String sql = "alter table sql_perf add index `idx_instance_8` (`host`,`port`,`hashcode`,`item`,`time`,`value`);";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
Assert.assertEquals(1, statementList.size());
SchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
statemen.accept(visitor);
// System.out.println(sql);
// System.out.println("Tables : " + visitor.getTables());
// System.out.println("fields : " + visitor.getColumns());
assertEquals(1, visitor.getTables().size());
assertTrue(visitor.containsTable("sql_perf"));
assertEquals(6, visitor.getColumns().size());
assertTrue(visitor.getColumns().contains(new Column("sql_perf", "host")));
assertTrue(visitor.getColumns().contains(new Column("sql_perf", "port")));
assertTrue(visitor.getColumns().contains(new Column("sql_perf", "hashcode")));
assertTrue(visitor.getColumns().contains(new Column("sql_perf", "item")));
assertTrue(visitor.getColumns().contains(new Column("sql_perf", "time")));
assertTrue(visitor.getColumns().contains(new Column("sql_perf", "value")));
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class MySqlSchemaStatVisitorTest_Subquery method test_0.
public void test_0() throws Exception {
String sql = "SELECT id2, name2 FROM (select id, name from users u where id = 22 limit 10) a";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
Assert.assertEquals(1, statementList.size());
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
statemen.accept(visitor);
System.out.println(sql);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("alias : " + visitor.getAliasMap());
System.out.println("conditions : " + visitor.getConditions());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(true, visitor.containsTable("users"));
Assert.assertEquals(22, visitor.getConditions().get(0).getValues().get(0));
Assert.assertEquals(2, visitor.getColumns().size());
Assert.assertEquals(true, visitor.getColumns().contains(new Column("users", "id")));
Assert.assertEquals(true, visitor.getColumns().contains(new Column("users", "name")));
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class MySqlSchemaStatVisitorTest_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 limit 10) a inner join groups b on a.groupId = b.id";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
Assert.assertEquals(1, statementList.size());
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
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")));
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class MySqlUpdateTest_0 method test_0.
public void test_0() throws Exception {
String sql = "UPDATE `z_code` SET `key`='INTRANT_NOTALLOWED_CATEGORY_C'";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
// print(statementList);
Assert.assertEquals(1, statementList.size());
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
statemen.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.getTables().containsKey(new TableStat.Name("z_code")));
Assert.assertTrue(visitor.getColumns().contains(new Column("z_code", "key")));
}
use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.
the class OdpsUDTFTest 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")));
}
Aggregations