Search in sources :

Example 31 with OdpsStatementParser

use of com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser in project druid by alibaba.

the class OdpsMultiInsertTest 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 32 with OdpsStatementParser

use of com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser in project druid by alibaba.

the class OdpsResourceTest 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();
    }
    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 33 with OdpsStatementParser

use of com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser in project druid by alibaba.

the class OdpsSetLabelTest method test_odps.

public void test_odps() throws Exception {
    String sql = "SET LABEL S3 TO USER aliyun$abc@alibaba-inc.com";
    OdpsStatementParser parser = new OdpsStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    Assert.assertEquals("SET LABEL S3 TO USER aliyun$abc@alibaba-inc.com", SQLUtils.toOdpsString(stmt));
    Assert.assertEquals("set label S3 to user aliyun$abc@alibaba-inc.com", SQLUtils.toOdpsString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
Also used : OdpsStatementParser(com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 34 with OdpsStatementParser

use of com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser in project druid by alibaba.

the class OdpsShowPartitionsTest method test_0.

public void test_0() throws Exception {
    String sql = "show partitions secods.xxx";
    OdpsStatementParser parser = new OdpsStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toOdpsString(stmt);
    Assert.assertEquals("SHOW PARTITIONS secods.xxx", output);
}
Also used : OdpsStatementParser(com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 35 with OdpsStatementParser

use of com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser in project druid by alibaba.

the class OdpsShowTablesTest0 method test_from.

public void test_from() throws Exception {
    String sql = "show tables from xx";
    OdpsStatementParser parser = new OdpsStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    Assert.assertEquals("SHOW TABLES FROM xx", SQLUtils.toOdpsString(stmt));
    Assert.assertEquals("show tables from xx", SQLUtils.toOdpsString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
Also used : OdpsStatementParser(com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)44 OdpsStatementParser (com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser)44 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 MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)1 OdpsOutputVisitor (com.alibaba.druid.sql.dialect.odps.visitor.OdpsOutputVisitor)1 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)1 File (java.io.File)1