Search in sources :

Example 1 with OdpsSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor 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")));
}
Also used : OdpsStatementParser(com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser) Column(com.alibaba.druid.stat.TableStat.Column) OdpsSchemaStatVisitor(com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 2 with OdpsSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor 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")));
}
Also used : OdpsStatementParser(com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser) Column(com.alibaba.druid.stat.TableStat.Column) OdpsSchemaStatVisitor(com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 3 with OdpsSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor in project druid by alibaba.

the class OdpsInsertTest 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 = items[1].trim();
    OdpsStatementParser parser = new OdpsStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    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));
}
Also used : InputStreamReader(java.io.InputStreamReader) OdpsStatementParser(com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser) InputStream(java.io.InputStream) OdpsSchemaStatVisitor(com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor) OdpsSchemaStatVisitor(com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor)

Example 4 with OdpsSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor in project druid by alibaba.

the class OdpsSelect_distribute_by_Test 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 = items[1].trim();
    OdpsStatementParser parser = new OdpsStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    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));
}
Also used : InputStreamReader(java.io.InputStreamReader) OdpsStatementParser(com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser) InputStream(java.io.InputStream) OdpsSchemaStatVisitor(com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor) OdpsSchemaStatVisitor(com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor)

Example 5 with OdpsSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor in project druid by alibaba.

the class OdpsFileTest 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 = items[1].trim();
    OdpsStatementParser parser = new OdpsStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    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));
}
Also used : InputStreamReader(java.io.InputStreamReader) OdpsStatementParser(com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser) InputStream(java.io.InputStream) OdpsSchemaStatVisitor(com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor) OdpsSchemaStatVisitor(com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)8 OdpsStatementParser (com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser)8 OdpsSchemaStatVisitor (com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor)8 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)6 InputStream (java.io.InputStream)6 InputStreamReader (java.io.InputStreamReader)6 Reader (java.io.Reader)6 Column (com.alibaba.druid.stat.TableStat.Column)2