use of com.alibaba.druid.support.opds.udf.SqlCodeStat in project druid by alibaba.
the class OdpsListResourcesTest method exec_test.
public void exec_test(String resource) throws Exception {
// System.out.println(resource);
InputStream is = null;
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
Reader reader = new InputStreamReader(is, "UTF-8");
String input = Utils.read(reader);
JdbcUtils.close(reader);
String[] items = input.split("---------------------------");
String sql = items[0].trim();
String expect = null;
if (items.length > 1) {
expect = items[1].trim();
if (expect != null) {
expect = expect.replaceAll("\\r\\n", "\n");
}
}
new SqlCodeStat().evaluate(sql, "odps");
OdpsStatementParser parser = new OdpsStatementParser(sql, SQLParserFeature.EnableSQLBinaryOpExprGroup, SQLParserFeature.EnableMultiUnion, SQLParserFeature.KeepComments);
List<SQLStatement> statementList = parser.parseStatementList();
if (statementList.size() == 0) {
throw new Exception("empty");
}
SQLStatement stmt = statementList.get(0);
// Assert.assertEquals(1, statementList.size());
SchemaStatVisitor visitor = new OdpsSchemaStatVisitor();
stmt.accept(visitor);
// System.out.println(sql);
// System.out.println("Tables : " + visitor.getTables());
// System.out.println("fields : " + visitor.getColumns());
//
// System.out.println();
// System.out.println("---------------------------");
System.out.println(SQLUtils.toOdpsString(stmt));
if (expect != null && !expect.isEmpty()) {
assertEquals(expect, stmt.toString());
}
SchemaStatVisitor schemaStatVisitor = SQLUtils.createSchemaStatVisitor(DbType.odps);
for (SQLStatement item : statementList) {
item.accept(schemaStatVisitor);
}
}
Aggregations