Search in sources :

Example 16 with OdpsStatementParser

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

the class OdpsCreateTableTest method test_0.

public void test_0() throws Exception {
    String sql = //
    "CREATE TABLE IF NOT EXISTS sale_detail(" + //
    " shop_name     STRING," + //
    " customer_id   STRING," + //
    " total_price   DOUBLE" + //
    ")" + //
    "comment 'xxxx'" + //
    "PARTITIONED BY (sale_date STRING,region STRING)" + //
    "LIFECYCLE 5" + ";";
    OdpsStatementParser parser = new OdpsStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toOdpsString(stmt);
    Assert.assertEquals(//
    "CREATE TABLE IF NOT EXISTS sale_detail (" + //
    "\n\tshop_name STRING," + //
    "\n\tcustomer_id STRING," + //
    "\n\ttotal_price DOUBLE" + //
    "\n)" + //
    "\nCOMMENT 'xxxx'" + "\nPARTITIONED BY (" + "\n\tsale_date STRING," + "\n\tregion STRING" + //
    "\n)" + "\nLIFECYCLE 5", output);
}
Also used : OdpsStatementParser(com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 17 with OdpsStatementParser

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

the class OdpsCreateTableTest2 method test_0.

public void test_0() throws Exception {
    String sql = "CREATE TABLE sale_detail as select * from dual;";
    OdpsStatementParser parser = new OdpsStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toOdpsString(stmt);
    Assert.assertEquals("CREATE TABLE sale_detail" + "\nAS" + //
    "\nSELECT *" + "\nFROM dual", output);
}
Also used : OdpsStatementParser(com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 18 with OdpsStatementParser

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

the class OdpsCreateTableTest_1 method test_0.

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

Example 19 with OdpsStatementParser

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

the class OdpsCreateViewTest method test_create.

public void test_create() throws Exception {
    String sql = "CREATE view sale_detail as select * from dual;";
    OdpsStatementParser parser = new OdpsStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toOdpsString(stmt);
    Assert.assertEquals(//
    "CREATE VIEW sale_detail" + //
    "\nAS" + //
    "\nSELECT *" + "\nFROM dual", output);
}
Also used : OdpsStatementParser(com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 20 with OdpsStatementParser

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

the class OdpsCreateViewTest method test_create_or_replace.

public void test_create_or_replace() throws Exception {
    String sql = "CREATE or replace view sale_detail as select * from dual;";
    OdpsStatementParser parser = new OdpsStatementParser(sql);
    SQLStatement stmt = parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toOdpsString(stmt);
    Assert.assertEquals(//
    "CREATE OR REPLACE VIEW sale_detail" + //
    "\nAS" + //
    "\nSELECT *" + "\nFROM dual", 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