use of com.alibaba.druid.sql.repository.SchemaRepository in project druid by alibaba.
the class CanalSQLSchemaTest method test_persistent.
@Test
public void test_persistent() throws Throwable {
SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
String sql = " create table example_vc_tbl( c1 int not null auto_increment primary key," + "c2 varchar(70), vc1 int as (length(c2)) virtual," + "DIM_SUM varchar(128) AS (MD5(UPPER(CONCAT(c2, c1)))) PERSISTENT)";
repository.console(sql);
repository.setDefaultSchema("test");
SchemaObject table = repository.findTable("example_vc_tbl");
Assert.assertTrue(table.findColumn("DIM_SUM") != null);
}
use of com.alibaba.druid.sql.repository.SchemaRepository in project druid by alibaba.
the class SchemaStatTest15 method test_schemaStat_2.
public void test_schemaStat_2() throws Exception {
SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
repository.acceptDDL("create table table1 (fid bigint, f1 varchar(100), f2 varchar(100));");
repository.acceptDDL("create view view1 as select fid table1 where fid = 1;");
SchemaObject viewObject = repository.findView("view1");
System.out.println(viewObject);
assertEquals("view1", viewObject.getName());
assertEquals(SchemaObjectType.View, viewObject.getType());
}
use of com.alibaba.druid.sql.repository.SchemaRepository in project druid by alibaba.
the class SchemaStatTest20_issue3993 method test_schemaStat.
public void test_schemaStat() throws Exception {
SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
String sql = "select * from tableA where COALESCE(service_code,'/') <> '0821';";
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL);
SQLStatement stmt = parser.parseStatementList().get(0);
SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(repository);
stmt.accept(statVisitor);
System.out.println("Tables : " + statVisitor.getTables());
System.out.println("columns : " + statVisitor.getColumns());
// System.out.println(statVisitor.getGroupByColumns()); // group by
// group by
System.out.println("relationships : " + statVisitor.getRelationships());
System.out.println("conditions : " + statVisitor.getConditions());
assertEquals(2, statVisitor.getColumns().size());
assertEquals(1, statVisitor.getConditions().size());
assertEquals(1, statVisitor.getFunctions().size());
}
use of com.alibaba.druid.sql.repository.SchemaRepository in project druid by alibaba.
the class SchemaStatTest22_yiran method test_schemaStat.
public void test_schemaStat() throws Exception {
SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
repository.console("CREATE TABLE DEPT (depno INT4, dname ENC_TEXT)");
String sql = "SELECT * FROM ( SELECT dname FROM DEPT) X WHERE X.dname='cs';";
// sql = "SELECT * FROM ( SELECT * FROM DEPT) X WHERE X.dname='cs'";
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL);
SQLStatement stmt = parser.parseStatementList().get(0);
SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(repository);
stmt.accept(statVisitor);
SQLSelectQueryBlock q = ((SQLSelectStatement) stmt).getSelect().getFirstQueryBlock();
SQLPropertyExpr whereLeft = (SQLPropertyExpr) ((SQLBinaryOpExpr) q.getWhere()).getLeft();
SQLColumnDefinition resolvedColumn = whereLeft.getResolvedColumn();
assertNotNull(resolvedColumn);
System.out.println("Tables : " + statVisitor.getTables());
System.out.println("columns : " + statVisitor.getColumns());
// System.out.println(statVisitor.getGroupByColumns()); // group by
// group by
System.out.println("relationships : " + statVisitor.getRelationships());
System.out.println("conditions : " + statVisitor.getConditions());
assertEquals(1, statVisitor.getColumns().size());
assertEquals(1, statVisitor.getConditions().size());
assertEquals(0, statVisitor.getFunctions().size());
}
use of com.alibaba.druid.sql.repository.SchemaRepository in project druid by alibaba.
the class SchemaStatTest18 method test_schemaStat.
public void test_schemaStat() throws Exception {
SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
String sql = "SELECT * FROM t WHERE 3 > f1 -1;";
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL);
SQLStatement stmt = parser.parseStatementList().get(0);
SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(repository);
stmt.accept(statVisitor);
System.out.println("Tables : " + statVisitor.getTables());
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(2, statVisitor.getColumns().size());
assertEquals(1, statVisitor.getConditions().size());
assertEquals(0, statVisitor.getFunctions().size());
assertTrue(statVisitor.containsTable("t"));
assertTrue(statVisitor.containsColumn("t", "f1"));
assertEquals("t.f1 < 4", statVisitor.getConditions().get(0).toString());
}
Aggregations