Search in sources :

Example 1 with MycatRel

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

the class QueryView method explain.

@Override
public ExplainWriter explain(ExplainWriter writer) {
    writer.name("Query").into();
    List<RelNode> inputs = getInputs();
    for (RelNode input : inputs) {
        MycatRel rel = (MycatRel) input;
        rel.explain(writer);
    }
    return writer.ret();
}
Also used : RelNode(org.apache.calcite.rel.RelNode) MycatRel(io.mycat.calcite.MycatRel)

Example 2 with MycatRel

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

the class PlanImpl method getMetaData.

@Override
public MycatRowMetaData getMetaData() {
    MycatRel mycatRel = (MycatRel) relNode;
    List<RelDataTypeField> fieldList = mycatRel.getRowType().getFieldList();
    return new CalciteRowMetaData(fieldList, aliasList);
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) MycatRel(io.mycat.calcite.MycatRel) CalciteRowMetaData(io.mycat.calcite.resultset.CalciteRowMetaData)

Example 3 with MycatRel

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

the class MemPlanCache method add.

public synchronized PlanResultSet add(boolean fix, DrdsSql drdsSql) {
    Long baselineId = null;
    Baseline baseline = this.getBaseline(drdsSql);
    DrdsSqlCompiler drdsSqlCompiler = MetaClusterCurrent.wrapper(DrdsSqlCompiler.class);
    OptimizationContext optimizationContext = new OptimizationContext();
    MycatRel mycatRel = drdsSqlCompiler.dispatch(optimizationContext, drdsSql);
    RelJsonWriter relJsonWriter = new RelJsonWriter();
    mycatRel.explain(relJsonWriter);
    long hash = planIds.nextPlanId();
    BaselinePlan newBaselinePlan = new BaselinePlan(drdsSql.getParameterizedSQL(), relJsonWriter.asString(), hash, baselineId = baseline.getBaselineId(), null);
    getCodeExecuterContext(baseline, newBaselinePlan, optimizationContext, mycatRel);
    return saveBaselinePlan(fix, false, baseline, newBaselinePlan);
}
Also used : MycatRel(io.mycat.calcite.MycatRel) OptimizationContext(io.mycat.calcite.rewriter.OptimizationContext) RelJsonWriter(org.apache.calcite.rel.externalize.RelJsonWriter)

Example 4 with MycatRel

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

the class MemPlanCache method getCodeExecuterContext.

@SneakyThrows
public CodeExecuterContext getCodeExecuterContext(Baseline baseline, BaselinePlan plan) {
    boolean forUpdate = DrdsSql.isForUpdate(plan.getSql());
    Object attach = plan.attach;
    if (attach != null) {
        return (CodeExecuterContext) attach;
    }
    String rel = plan.getRel();
    synchronized (plan) {
        try {
            ImmutableMap<RexNode, RexNode> constantMap = getConstantMap(baseline);
            RelJsonReader relJsonReader = new RelJsonReader(DrdsSqlCompiler.newCluster(), MetaClusterCurrent.wrapper(DrdsSqlCompiler.class).newCalciteCatalogReader(), null);
            MycatRel mycatRel = (MycatRel) relJsonReader.read(rel);
            CodeExecuterContext codeExecuterContext = DrdsExecutorCompiler.getCodeExecuterContext(constantMap, mycatRel, forUpdate);
            plan.setAttach(codeExecuterContext);
        } catch (Throwable throwable) {
            log.error("", throwable);
        }
    }
    return (CodeExecuterContext) plan.attach;
}
Also used : CodeExecuterContext(io.mycat.calcite.CodeExecuterContext) MycatRel(io.mycat.calcite.MycatRel) RelJsonReader(org.apache.calcite.rel.externalize.RelJsonReader) RexNode(org.apache.calcite.rex.RexNode) SneakyThrows(lombok.SneakyThrows)

Example 5 with MycatRel

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

the class MycatTableSpool method explain.

@Override
public ExplainWriter explain(ExplainWriter writer) {
    writer.name("MycatTableSpool").into();
    for (RelNode relNode : getInputs()) {
        MycatRel relNode1 = (MycatRel) relNode;
        relNode1.explain(writer);
    }
    return writer.ret();
}
Also used : RelNode(org.apache.calcite.rel.RelNode) MycatRel(io.mycat.calcite.MycatRel)

Aggregations

MycatRel (io.mycat.calcite.MycatRel)15 OptimizationContext (io.mycat.calcite.rewriter.OptimizationContext)9 Plan (io.mycat.calcite.spm.Plan)8 PlanImpl (io.mycat.calcite.spm.PlanImpl)7 DrdsSqlCompiler (io.mycat.DrdsSqlCompiler)4 DrdsSqlWithParams (io.mycat.DrdsSqlWithParams)4 RelNode (org.apache.calcite.rel.RelNode)3 CodeExecuterContext (io.mycat.calcite.CodeExecuterContext)1 CalciteRowMetaData (io.mycat.calcite.resultset.CalciteRowMetaData)1 UpdatePlanCache (io.mycat.calcite.spm.UpdatePlanCache)1 SneakyThrows (lombok.SneakyThrows)1 RelJsonReader (org.apache.calcite.rel.externalize.RelJsonReader)1 RelJsonWriter (org.apache.calcite.rel.externalize.RelJsonWriter)1 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)1 RexNode (org.apache.calcite.rex.RexNode)1 Nullable (org.jetbrains.annotations.Nullable)1