use of com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser 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));
}
use of com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser in project druid by alibaba.
the class OdpsSelectTest6 method test_distribute_by.
public void test_distribute_by() throws Exception {
File file = new File("/Users/wenshao/Downloads/datasafe_base_dev.udf_test.txt");
String sql = FileUtils.readFileToString(file, "UTF-8");
SQLStatementParser parser = new OdpsStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
Assert.assertEquals(1, statementList.size());
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
// Assert.assertEquals("SELECT *"
// + "\nFROM t"
// + "\nWHERE ds = '20160303'"
// + "\n\tAND hour IN ('18')", SQLUtils.formatOdps(sql));
}
use of com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser in project druid by alibaba.
the class Bug_for_qianbi method test_for_issue.
public void test_for_issue() throws Exception {
String sql = "insert into table lol select detail(sellerid,id) as count1,sum(sellerid) as sum1 from ctu_trade_paid_done.time('natural','1d','1h') " + "where match(auctionTitle,\"男鞋\\n中石化&加油卡\\n中石化&充值卡\\n中石化&冲值卡\\n中石化&代冲\\n中石化&代充\\n中国石化&加油卡\\n中国石化&充值卡\\n中国石化&冲值卡\\n中国石化&代冲\\n中国石化&代充\",\"\\n\")";
String expected = "INSERT INTO TABLE lol" + "\nSELECT detail(sellerid, id) AS count1" + "\n\t, SUM(sellerid) AS sum1" + "\nFROM ctu_trade_paid_done:time('natural', '1d', '1h')" + "\nWHERE match(auctionTitle, '男鞋\\n中石化&加油卡\\n中石化&充值卡\\n中石化&冲值卡\\n中石化&代冲\\n中石化&代充\\n中国石化&加油卡\\n中国石化&充值卡\\n中国石化&冲值卡\\n中国石化&代冲\\n中国石化&代充', '\\n');\n";
StringBuilder out = new StringBuilder();
OdpsOutputVisitor visitor = new OdpsOutputVisitor(out);
OdpsStatementParser parser = new OdpsStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
for (SQLStatement statement : statementList) {
statement.accept(visitor);
visitor.print(";");
visitor.println();
}
// System.out.println(out.toString());
Assert.assertEquals(expected, out.toString());
}
use of com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser in project druid by alibaba.
the class OdpsListTest method test_6.
public void test_6() throws Exception {
String sql = "list trustedprojects";
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("LIST trustedprojects", output);
}
use of com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser in project druid by alibaba.
the class OdpsListTest method test_2.
public void test_2() throws Exception {
String sql = "list functions";
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("LIST functions", output);
}
Aggregations