Search in sources :

Example 1 with ExplainWriter

use of io.mycat.calcite.ExplainWriter in project Mycat2 by MyCATApache.

the class PlanImpl method explain.

public List<String> explain(MycatDataContext dataContext, DrdsSqlWithParams drdsSql, boolean code) {
    ArrayList<String> list = new ArrayList<>();
    ExplainWriter explainWriter = new ExplainWriter();
    switch(this.type) {
        case PHYSICAL:
            Optional<ExplainDetail> singleViewOptional = ColocatedPlanner.executeQuery(dataContext, this, drdsSql);
            if (singleViewOptional.isPresent()) {
                ExplainDetail explainDetail = singleViewOptional.get();
                list.add("ColocatedPushDown:");
                list.add(explainDetail.toString());
            }
            list.add("\n");
            list.add("Plan:");
            String s = dumpPlan();
            list.addAll(Arrays.asList(s.split("\n")));
            List<SpecificSql> map = specificSql(drdsSql, dataContext);
            for (SpecificSql specificSql : map) {
                list.addAll(Arrays.asList(specificSql.toString().split("\n")));
            }
            if (code) {
                list.add("Code:");
                list.addAll(Arrays.asList(getCodeExecuterContext().getCodeContext().getCode().split("\n")));
            }
            break;
        case UPDATE:
            {
                Collection<VertxExecuter.EachSQL> eachSQLS = VertxUpdateExecuter.explainUpdate(drdsSql, dataContext);
                for (VertxExecuter.EachSQL eachSQL : eachSQLS) {
                    list.add(eachSQL.toString());
                }
                break;
            }
        case INSERT:
            {
                Iterable<VertxExecuter.EachSQL> eachSQLS = (VertxExecuter.explainInsert((SQLInsertStatement) drdsSql.getParameterizedStatement(), drdsSql.getParams()));
                for (VertxExecuter.EachSQL eachSQL : eachSQLS) {
                    list.add(eachSQL.toString());
                }
                break;
            }
        default:
            throw new IllegalStateException("Unexpected value: " + this.type);
    }
    for (String s1 : explainWriter.getText().split("\n")) {
        list.add(s1);
    }
    return list.stream().filter(i -> !i.isEmpty()).collect(Collectors.toList());
}
Also used : VertxExecuter(io.mycat.vertx.VertxExecuter) java.util(java.util) MycatRowMetaData(io.mycat.beans.mycat.MycatRowMetaData) RelShuttleImpl(org.apache.calcite.rel.RelShuttleImpl) CalciteRowMetaData(io.mycat.calcite.resultset.CalciteRowMetaData) SqlNode(org.apache.calcite.sql.SqlNode) ExplainWriter(io.mycat.calcite.ExplainWriter) MycatTransientSQLTableScan(io.mycat.calcite.table.MycatTransientSQLTableScan) DrdsSqlWithParams(io.mycat.DrdsSqlWithParams) MycatRel(io.mycat.calcite.MycatRel) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ExplainDetail(io.mycat.ExplainDetail) MycatView(io.mycat.calcite.logical.MycatView) VertxUpdateExecuter(io.mycat.vertx.VertxUpdateExecuter) SQLInsertStatement(com.alibaba.druid.sql.ast.statement.SQLInsertStatement) MycatCalciteSupport(io.mycat.calcite.MycatCalciteSupport) RelNode(org.apache.calcite.rel.RelNode) Collectors(java.util.stream.Collectors) MycatSQLTableLookup(io.mycat.calcite.physical.MycatSQLTableLookup) MycatUpdateRel(io.mycat.calcite.physical.MycatUpdateRel) MycatInsertRel(io.mycat.calcite.physical.MycatInsertRel) AsyncMycatDataContextImpl(io.mycat.AsyncMycatDataContextImpl) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) CodeExecuterContext(io.mycat.calcite.CodeExecuterContext) MycatDataContext(io.mycat.MycatDataContext) SqlString(org.apache.calcite.sql.util.SqlString) Util(org.apache.calcite.util.Util) NotNull(org.jetbrains.annotations.NotNull) ColocatedPlanner(io.mycat.calcite.plan.ColocatedPlanner) VertxExecuter(io.mycat.vertx.VertxExecuter) SqlString(org.apache.calcite.sql.util.SqlString) ExplainWriter(io.mycat.calcite.ExplainWriter) ExplainDetail(io.mycat.ExplainDetail)

Aggregations

SQLInsertStatement (com.alibaba.druid.sql.ast.statement.SQLInsertStatement)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 AsyncMycatDataContextImpl (io.mycat.AsyncMycatDataContextImpl)1 DrdsSqlWithParams (io.mycat.DrdsSqlWithParams)1 ExplainDetail (io.mycat.ExplainDetail)1 MycatDataContext (io.mycat.MycatDataContext)1 MycatRowMetaData (io.mycat.beans.mycat.MycatRowMetaData)1 CodeExecuterContext (io.mycat.calcite.CodeExecuterContext)1 ExplainWriter (io.mycat.calcite.ExplainWriter)1 MycatCalciteSupport (io.mycat.calcite.MycatCalciteSupport)1 MycatRel (io.mycat.calcite.MycatRel)1 MycatView (io.mycat.calcite.logical.MycatView)1 MycatInsertRel (io.mycat.calcite.physical.MycatInsertRel)1 MycatSQLTableLookup (io.mycat.calcite.physical.MycatSQLTableLookup)1 MycatUpdateRel (io.mycat.calcite.physical.MycatUpdateRel)1 ColocatedPlanner (io.mycat.calcite.plan.ColocatedPlanner)1 CalciteRowMetaData (io.mycat.calcite.resultset.CalciteRowMetaData)1 MycatTransientSQLTableScan (io.mycat.calcite.table.MycatTransientSQLTableScan)1 VertxExecuter (io.mycat.vertx.VertxExecuter)1 VertxUpdateExecuter (io.mycat.vertx.VertxUpdateExecuter)1