Search in sources :

Example 1 with CalciteMySqlNodeVisitor

use of com.alibaba.druid.support.calcite.CalciteMySqlNodeVisitor in project druid by alibaba.

the class MySqlParameterizedOutputVisitorTest_47_hints method test_headHint_2.

public void test_headHint_2() throws Exception {
    String sql = "/*TDDL : construct()*/ select /*TDDL : add_ms(sort=t.pk, asc=true) add_agg(agg=\"SUM\", group=\"pk\", column=\"c\") add_pj(c=\"c\") add_ts(c, true) */ pk, count(*) c from tb1 where id in(1,2,3,4) group by pk order by pk";
    MySqlStatementParser parser = new MySqlStatementParser(sql, SQLParserFeature.TDDLHint);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statemen = statementList.get(0);
    CalciteMySqlNodeVisitor visitor = new CalciteMySqlNodeVisitor();
    statemen.accept(visitor);
    SqlNode sqlNode = visitor.getSqlNode();
    System.out.println(sqlNode);
    SqlNodeList hints = ((TDDLSqlSelect) sqlNode).getHints();
    Assert.assertEquals(hints.size(), 1);
    Assert.assertEquals(((SqlNodeList) hints.get(0)).size(), 4);
    SqlNodeList headHints = ((TDDLSqlSelect) sqlNode).getHeadHints();
    Assert.assertEquals(headHints.size(), 1);
    Assert.assertEquals(((SqlNodeList) headHints.get(0)).size(), 1);
}
Also used : CalciteMySqlNodeVisitor(com.alibaba.druid.support.calcite.CalciteMySqlNodeVisitor) TDDLSqlSelect(com.alibaba.druid.support.calcite.TDDLSqlSelect) SqlNodeList(org.apache.calcite.sql.SqlNodeList) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)1 CalciteMySqlNodeVisitor (com.alibaba.druid.support.calcite.CalciteMySqlNodeVisitor)1 TDDLSqlSelect (com.alibaba.druid.support.calcite.TDDLSqlSelect)1 SqlNode (org.apache.calcite.sql.SqlNode)1 SqlNodeList (org.apache.calcite.sql.SqlNodeList)1