Search in sources :

Example 1 with RelNodeVisitor

use of org.apache.apex.malhar.sql.planner.RelNodeVisitor in project apex-malhar by apache.

the class SQLExecEnvironment method executeSQL.

/**
 * This is the main method takes SQL statement as input and contructs a DAG using contructs registered with this
 * {@link SQLExecEnvironment}.
 *
 * @param sql SQL statement that should be converted to a DAG.
 */
public void executeSQL(DAG dag, String sql) {
    FrameworkConfig config = buildFrameWorkConfig();
    Planner planner = Frameworks.getPlanner(config);
    try {
        logger.info("Parsing SQL statement: {}", sql);
        SqlNode parsedTree = planner.parse(sql);
        SqlNode validatedTree = planner.validate(parsedTree);
        RelNode relationalTree = planner.rel(validatedTree).rel;
        logger.info("RelNode relationalTree generate from SQL statement is:\n {}", Util.toLinux(RelOptUtil.toString(relationalTree)));
        RelNodeVisitor visitor = new RelNodeVisitor(dag, typeFactory);
        visitor.traverse(relationalTree);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    } finally {
        planner.close();
    }
}
Also used : RelNodeVisitor(org.apache.apex.malhar.sql.planner.RelNodeVisitor) RelNode(org.apache.calcite.rel.RelNode) Planner(org.apache.calcite.tools.Planner) FrameworkConfig(org.apache.calcite.tools.FrameworkConfig) SQLException(java.sql.SQLException) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

SQLException (java.sql.SQLException)1 RelNodeVisitor (org.apache.apex.malhar.sql.planner.RelNodeVisitor)1 RelNode (org.apache.calcite.rel.RelNode)1 SqlNode (org.apache.calcite.sql.SqlNode)1 FrameworkConfig (org.apache.calcite.tools.FrameworkConfig)1 Planner (org.apache.calcite.tools.Planner)1