use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class OracleCreateSynonymTest_2 method test_0.
public void test_0() throws Exception {
//
String sql = "CREATE OR REPLACE SYNONYM CSCLIENT.ECC_CUST_AREA_INFO FOR ECC_CUST.ECC_CUST_AREA_INFO";
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
SQLStatement stmt = statementList.get(0);
print(statementList);
assertEquals(1, statementList.size());
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ORACLE);
stmt.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());
System.out.println("orderBy : " + visitor.getOrderByColumns());
assertEquals("CREATE OR REPLACE SYNONYM CSCLIENT.ECC_CUST_AREA_INFO FOR ECC_CUST.ECC_CUST_AREA_INFO", SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
assertEquals(0, visitor.getTables().size());
// assertTrue(visitor.getTables().containsKey(new TableStat.Name("t1")));
assertEquals(0, visitor.getColumns().size());
// assertTrue(visitor.getColumns().contains(new TableStat.Column("xwarehouses", "sales_rep_id")));
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
// assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class PrestoSelect_0 method test_unnest_2.
@Test
public void test_unnest_2() throws Exception {
String sql = "SELECT numbers, n, a\n" + "FROM (\n" + " VALUES\n" + " (ARRAY[2, 5]),\n" + " (ARRAY[7, 8, 9])\n" + ") AS x (numbers)\n" + "CROSS JOIN UNNEST(numbers) WITH ORDINALITY AS t (n, a);";
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
SQLStatement stmt = parser.parseStatement();
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(dbType);
stmt.accept(visitor);
Map<TableStat.Name, TableStat> tableMap = visitor.getTables();
assertTrue(tableMap.isEmpty());
assertEquals("SELECT numbers, n, a\n" + "FROM (VALUES (ARRAY[2, 5]), (ARRAY[7, 8, 9])) AS x (numbers)\n" + "\tCROSS JOIN UNNEST(numbers) WITH ORDINALITY AS t (n, a)", stmt.toString());
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class PrestoSelect_0 method test_in.
@Test
public void test_in() throws Exception {
String sql = "SELECT name\n" + "FROM nation\n" + "WHERE regionkey IN (\n" + " SELECT regionkey\n" + " FROM region\n" + " WHERE name = 'AMERICA' OR name = 'AFRICA'\n" + ");";
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
SQLStatement stmt = parser.parseStatement();
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(dbType);
stmt.accept(visitor);
Map<TableStat.Name, TableStat> tableMap = visitor.getTables();
assertFalse(tableMap.isEmpty());
assertEquals("SELECT name\n" + "FROM nation\n" + "WHERE regionkey IN (\n" + "\tSELECT regionkey\n" + "\tFROM region\n" + "\tWHERE name = 'AMERICA'\n" + "\t\tOR name = 'AFRICA'\n" + ")", stmt.toString());
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class PrestoSelect_0 method test_scalar.
@Test
public void test_scalar() throws Exception {
String sql = "SELECT name\n" + "FROM nation\n" + "WHERE regionkey = (SELECT max(regionkey) FROM region);";
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
SQLStatement stmt = parser.parseStatement();
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(dbType);
stmt.accept(visitor);
Map<TableStat.Name, TableStat> tableMap = visitor.getTables();
assertFalse(tableMap.isEmpty());
assertEquals("SELECT name\n" + "FROM nation\n" + "WHERE regionkey = (\n" + "\tSELECT max(regionkey)\n" + "\tFROM region\n" + ")", stmt.toString());
}
use of com.alibaba.druid.sql.visitor.SchemaStatVisitor in project druid by alibaba.
the class PrestoSelect_0 method test_exists.
@Test
public void test_exists() throws Exception {
String sql = "SELECT name\n" + "FROM nation\n" + "WHERE EXISTS (\n" + " SELECT *\n" + " FROM region\n" + " WHERE region.regionkey = nation.regionkey\n" + ");";
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
SQLStatement stmt = parser.parseStatement();
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(dbType);
stmt.accept(visitor);
Map<TableStat.Name, TableStat> tableMap = visitor.getTables();
assertFalse(tableMap.isEmpty());
assertEquals("SELECT name\n" + "FROM nation\n" + "WHERE EXISTS (\n" + "\tSELECT *\n" + "\tFROM region\n" + "\tWHERE region.regionkey = nation.regionkey\n" + ")", stmt.toString());
}
Aggregations