Search in sources :

Example 1 with SqlExplainStatement

use of com.hazelcast.jet.sql.impl.parse.SqlExplainStatement in project hazelcast by hazelcast.

the class HazelcastExplainOperator method unparse.

@Override
public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
    writer.keyword("EXPLAIN PLAN FOR");
    SqlExplainStatement explainStatement = (SqlExplainStatement) call;
    explainStatement.getExplicandum().unparse(writer, leftPrec, rightPrec);
}
Also used : SqlExplainStatement(com.hazelcast.jet.sql.impl.parse.SqlExplainStatement)

Example 2 with SqlExplainStatement

use of com.hazelcast.jet.sql.impl.parse.SqlExplainStatement in project hazelcast by hazelcast.

the class CalciteSqlOptimizer method createPlan.

@SuppressWarnings("checkstyle:returncount")
private SqlPlan createPlan(OptimizationTask task, QueryParseResult parseResult, OptimizerContext context) {
    // TODO [sasha] : refactor this.
    SqlNode node = parseResult.getNode();
    PlanKey planKey = new PlanKey(task.getSearchPaths(), task.getSql());
    if (node instanceof SqlCreateMapping) {
        return toCreateMappingPlan(planKey, (SqlCreateMapping) node);
    } else if (node instanceof SqlDropMapping) {
        return toDropMappingPlan(planKey, (SqlDropMapping) node);
    } else if (node instanceof SqlCreateIndex) {
        return toCreateIndexPlan(planKey, (SqlCreateIndex) node);
    } else if (node instanceof SqlDropIndex) {
        return toDropIndexPlan(planKey, (SqlDropIndex) node);
    } else if (node instanceof SqlCreateJob) {
        return toCreateJobPlan(planKey, parseResult, context, task.getSql());
    } else if (node instanceof SqlAlterJob) {
        return toAlterJobPlan(planKey, (SqlAlterJob) node);
    } else if (node instanceof SqlDropJob) {
        return toDropJobPlan(planKey, (SqlDropJob) node);
    } else if (node instanceof SqlCreateSnapshot) {
        return toCreateSnapshotPlan(planKey, (SqlCreateSnapshot) node);
    } else if (node instanceof SqlDropSnapshot) {
        return toDropSnapshotPlan(planKey, (SqlDropSnapshot) node);
    } else if (node instanceof SqlCreateView) {
        return toCreateViewPlan(planKey, context, (SqlCreateView) node);
    } else if (node instanceof SqlDropView) {
        return toDropViewPlan(planKey, (SqlDropView) node);
    } else if (node instanceof SqlShowStatement) {
        return toShowStatementPlan(planKey, (SqlShowStatement) node);
    } else if (node instanceof SqlExplainStatement) {
        return toExplainStatementPlan(planKey, context, parseResult);
    } else {
        QueryConvertResult convertResult = context.convert(parseResult.getNode());
        return toPlan(planKey, parseResult.getParameterMetadata(), convertResult.getRel(), convertResult.getFieldNames(), context, parseResult.isInfiniteRows(), false, task.getSql());
    }
}
Also used : SqlCreateView(com.hazelcast.jet.sql.impl.parse.SqlCreateView) SqlDropView(com.hazelcast.jet.sql.impl.parse.SqlDropView) SqlDropJob(com.hazelcast.jet.sql.impl.parse.SqlDropJob) SqlAlterJob(com.hazelcast.jet.sql.impl.parse.SqlAlterJob) SqlDropMapping(com.hazelcast.jet.sql.impl.parse.SqlDropMapping) SqlCreateSnapshot(com.hazelcast.jet.sql.impl.parse.SqlCreateSnapshot) SqlCreateMapping(com.hazelcast.jet.sql.impl.parse.SqlCreateMapping) SqlDropIndex(com.hazelcast.jet.sql.impl.parse.SqlDropIndex) SqlCreateJob(com.hazelcast.jet.sql.impl.parse.SqlCreateJob) PlanKey(com.hazelcast.sql.impl.optimizer.PlanKey) SqlDropSnapshot(com.hazelcast.jet.sql.impl.parse.SqlDropSnapshot) QueryConvertResult(com.hazelcast.jet.sql.impl.parse.QueryConvertResult) SqlShowStatement(com.hazelcast.jet.sql.impl.parse.SqlShowStatement) SqlExplainStatement(com.hazelcast.jet.sql.impl.parse.SqlExplainStatement) SqlCreateIndex(com.hazelcast.jet.sql.impl.parse.SqlCreateIndex) SqlNode(org.apache.calcite.sql.SqlNode)

Example 3 with SqlExplainStatement

use of com.hazelcast.jet.sql.impl.parse.SqlExplainStatement in project hazelcast by hazelcast.

the class CalciteSqlOptimizer method toExplainStatementPlan.

private SqlPlan toExplainStatementPlan(PlanKey planKey, OptimizerContext context, QueryParseResult parseResult) {
    SqlNode node = parseResult.getNode();
    assert node instanceof SqlExplainStatement;
    QueryConvertResult convertResult = context.convert(((SqlExplainStatement) node).getExplicandum());
    PhysicalRel physicalRel = optimize(parseResult.getParameterMetadata(), convertResult.getRel(), context, false);
    return new ExplainStatementPlan(planKey, physicalRel, planExecutor);
}
Also used : QueryConvertResult(com.hazelcast.jet.sql.impl.parse.QueryConvertResult) ExplainStatementPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.ExplainStatementPlan) SelectByKeyMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.SelectByKeyMapPhysicalRel) SinkMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.SinkMapPhysicalRel) DeleteByKeyMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.DeleteByKeyMapPhysicalRel) InsertMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.InsertMapPhysicalRel) UpdateByKeyMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.UpdateByKeyMapPhysicalRel) PhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.PhysicalRel) SqlExplainStatement(com.hazelcast.jet.sql.impl.parse.SqlExplainStatement) SqlNode(org.apache.calcite.sql.SqlNode)

Example 4 with SqlExplainStatement

use of com.hazelcast.jet.sql.impl.parse.SqlExplainStatement in project hazelcast by hazelcast.

the class HazelcastSqlValidator method validate.

@Override
public SqlNode validate(SqlNode topNode) {
    if (topNode instanceof SqlCreateJob) {
        isCreateJob = true;
    }
    if (topNode instanceof SqlDropView) {
        return topNode;
    }
    if (topNode.getKind().belongsTo(SqlKind.DDL)) {
        topNode.validate(this, getEmptyScope());
        return topNode;
    }
    if (topNode instanceof SqlShowStatement) {
        return topNode;
    }
    if (topNode instanceof SqlExplainStatement) {
        /*
             * Just FYI, why do we do set validated explicandum back.
             *
             * There was a corner case with queries where ORDER BY is present.
             * SqlOrderBy is present as AST node (or SqlNode),
             * but then it becomes embedded as part of SqlSelect AST node,
             * and node itself is removed in `performUnconditionalRewrites().
             * As a result, ORDER BY is absent as operator
             * on the next validation & optimization phases
             * and also doesn't present in SUPPORTED_KINDS.
             *
             * Explain query contains explicandum query, and
             * performUnconditionalRewrites() doesn't rewrite anything for EXPLAIN.
             * It's a reason why we do it (extraction, validation & re-setting) manually.
             */
        SqlExplainStatement explainStatement = (SqlExplainStatement) topNode;
        SqlNode explicandum = explainStatement.getExplicandum();
        explicandum = super.validate(explicandum);
        explainStatement.setExplicandum(explicandum);
        return explainStatement;
    }
    return super.validate(topNode);
}
Also used : SqlCreateJob(com.hazelcast.jet.sql.impl.parse.SqlCreateJob) SqlDropView(com.hazelcast.jet.sql.impl.parse.SqlDropView) SqlShowStatement(com.hazelcast.jet.sql.impl.parse.SqlShowStatement) SqlExplainStatement(com.hazelcast.jet.sql.impl.parse.SqlExplainStatement) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

SqlExplainStatement (com.hazelcast.jet.sql.impl.parse.SqlExplainStatement)4 SqlNode (org.apache.calcite.sql.SqlNode)3 QueryConvertResult (com.hazelcast.jet.sql.impl.parse.QueryConvertResult)2 SqlCreateJob (com.hazelcast.jet.sql.impl.parse.SqlCreateJob)2 SqlDropView (com.hazelcast.jet.sql.impl.parse.SqlDropView)2 SqlShowStatement (com.hazelcast.jet.sql.impl.parse.SqlShowStatement)2 ExplainStatementPlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.ExplainStatementPlan)1 DeleteByKeyMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.DeleteByKeyMapPhysicalRel)1 InsertMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.InsertMapPhysicalRel)1 PhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.PhysicalRel)1 SelectByKeyMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.SelectByKeyMapPhysicalRel)1 SinkMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.SinkMapPhysicalRel)1 UpdateByKeyMapPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.UpdateByKeyMapPhysicalRel)1 SqlAlterJob (com.hazelcast.jet.sql.impl.parse.SqlAlterJob)1 SqlCreateIndex (com.hazelcast.jet.sql.impl.parse.SqlCreateIndex)1 SqlCreateMapping (com.hazelcast.jet.sql.impl.parse.SqlCreateMapping)1 SqlCreateSnapshot (com.hazelcast.jet.sql.impl.parse.SqlCreateSnapshot)1 SqlCreateView (com.hazelcast.jet.sql.impl.parse.SqlCreateView)1 SqlDropIndex (com.hazelcast.jet.sql.impl.parse.SqlDropIndex)1 SqlDropJob (com.hazelcast.jet.sql.impl.parse.SqlDropJob)1