Search in sources :

Example 6 with OdpsStatementParser

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

the class OdpsShowTablesTest0 method test_0.

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

Example 7 with OdpsStatementParser

use of com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser 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 8 with OdpsStatementParser

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

the class OdpsDescTest method test_3.

public void test_3() throws Exception {
    String sql = "desc idl_cheka_ent_sql_fht partition (ds='20151010',hh='10')";
    OdpsStatementParser parser = new OdpsStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toOdpsString(stmt);
    System.out.println(output);
    Assert.assertEquals("DESC idl_cheka_ent_sql_fht PARTITION (ds = '20151010', hh = '10')", output);
}
Also used : OdpsStatementParser(com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 9 with OdpsStatementParser

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

the class OdpsDescTest method test_4.

public void test_4() throws Exception {
    String sql = "desc idl_cheka_ent_sql_fdt partition (ds='20151010')";
    OdpsStatementParser parser = new OdpsStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toOdpsString(stmt);
    System.out.println(output);
    Assert.assertEquals("DESC idl_cheka_ent_sql_fdt PARTITION (ds = '20151010')", output);
}
Also used : OdpsStatementParser(com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 10 with OdpsStatementParser

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

the class OdpsDescTest method test_2.

public void test_2() throws Exception {
    String sql = "desc instance 20150715103441522gond1qa2";
    OdpsStatementParser parser = new OdpsStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toOdpsString(stmt);
    System.out.println(output);
    Assert.assertEquals("DESC INSTANCE 20150715103441522gond1qa2", output);
}
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