Search in sources :

Example 11 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project storm by apache.

the class StormSqlImpl method execute.

@Override
public void execute(Iterable<String> statements, ChannelHandler result) throws Exception {
    Map<String, DataSource> dataSources = new HashMap<>();
    for (String sql : statements) {
        StormParser parser = new StormParser(sql);
        SqlNode node = parser.impl().parseSqlStmtEof();
        if (node instanceof SqlCreateTable) {
            handleCreateTable((SqlCreateTable) node, dataSources);
        } else if (node instanceof SqlCreateFunction) {
            handleCreateFunction((SqlCreateFunction) node);
        } else {
            FrameworkConfig config = buildFrameWorkConfig();
            Planner planner = Frameworks.getPlanner(config);
            SqlNode parse = planner.parse(sql);
            SqlNode validate = planner.validate(parse);
            RelNode tree = planner.convert(validate);
            PlanCompiler compiler = new PlanCompiler(typeFactory);
            AbstractValuesProcessor proc = compiler.compile(tree);
            proc.initialize(dataSources, result);
        }
    }
}
Also used : HashMap(java.util.HashMap) AbstractValuesProcessor(org.apache.storm.sql.runtime.AbstractValuesProcessor) SqlCreateTable(org.apache.storm.sql.parser.SqlCreateTable) ISqlTridentDataSource(org.apache.storm.sql.runtime.ISqlTridentDataSource) DataSource(org.apache.storm.sql.runtime.DataSource) PlanCompiler(org.apache.storm.sql.compiler.backends.standalone.PlanCompiler) RelNode(org.apache.calcite.rel.RelNode) SqlCreateFunction(org.apache.storm.sql.parser.SqlCreateFunction) Planner(org.apache.calcite.tools.Planner) QueryPlanner(org.apache.storm.sql.planner.trident.QueryPlanner) FrameworkConfig(org.apache.calcite.tools.FrameworkConfig) StormParser(org.apache.storm.sql.parser.StormParser) SqlNode(org.apache.calcite.sql.SqlNode)

Example 12 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project storm by apache.

the class PlanCompiler method doChainOperators.

private void doChainOperators(PrintWriter pw, RelNode node, Set<TableScan> tables, String parentCtx) {
    pw.print(String.format("    ChannelContext CTX_%d = Channels.chain(%2$s, %3$s);\n", node.getId(), parentCtx, RelNodeCompiler.getStageName(node)));
    String currentCtx = String.format("CTX_%d", node.getId());
    if (node instanceof TableScan) {
        tables.add((TableScan) node);
    }
    for (RelNode i : node.getInputs()) {
        doChainOperators(pw, i, tables, currentCtx);
    }
}
Also used : TableScan(org.apache.calcite.rel.core.TableScan) RelNode(org.apache.calcite.rel.RelNode)

Example 13 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project flink by apache.

the class FlinkRelDecorrelator method decorrelateRel.

/**
	 * Rewrite LogicalFilter.
	 *
	 * @param rel the filter rel to rewrite
	 */
public Frame decorrelateRel(LogicalFilter rel) {
    //
    // Rewrite logic:
    //
    // 1. If a LogicalFilter references a correlated field in its filter
    // condition, rewrite the LogicalFilter to be
    //   LogicalFilter
    //     LogicalJoin(cross product)
    //       OriginalFilterInput
    //       ValueGenerator(produces distinct sets of correlated variables)
    // and rewrite the correlated fieldAccess in the filter condition to
    // reference the LogicalJoin output.
    //
    // 2. If LogicalFilter does not reference correlated variables, simply
    // rewrite the filter condition using new input.
    //
    final RelNode oldInput = rel.getInput();
    Frame frame = getInvoke(oldInput, rel);
    if (frame == null) {
        // If input has not been rewritten, do not rewrite this rel.
        return null;
    }
    // and produce the correlated variables in the new output.
    if (cm.mapRefRelToCorVar.containsKey(rel)) {
        decorrelateInputWithValueGenerator(rel);
        // The old input should be mapped to the newly created LogicalJoin by
        // rewriteInputWithValueGenerator().
        frame = map.get(oldInput);
    }
    // Replace the filter expression to reference output of the join
    // Map filter to the new filter over join
    RelNode newFilter = RelOptUtil.createFilter(frame.r, decorrelateExpr(rel.getCondition()));
    // input rel.
    return register(rel, newFilter, frame.oldToNewOutputPos, frame.corVarOutputPos);
}
Also used : RelNode(org.apache.calcite.rel.RelNode)

Example 14 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project flink by apache.

the class FlinkRelDecorrelator method createCopyHook.

private Function2<RelNode, RelNode, Void> createCopyHook() {
    return new Function2<RelNode, RelNode, Void>() {

        public Void apply(RelNode oldNode, RelNode newNode) {
            if (cm.mapRefRelToCorVar.containsKey(oldNode)) {
                cm.mapRefRelToCorVar.putAll(newNode, cm.mapRefRelToCorVar.get(oldNode));
            }
            if (oldNode instanceof LogicalCorrelate && newNode instanceof LogicalCorrelate) {
                LogicalCorrelate oldCor = (LogicalCorrelate) oldNode;
                CorrelationId c = oldCor.getCorrelationId();
                if (cm.mapCorVarToCorRel.get(c) == oldNode) {
                    cm.mapCorVarToCorRel.put(c, newNode);
                }
                if (generatedCorRels.contains(oldNode)) {
                    generatedCorRels.add((LogicalCorrelate) newNode);
                }
            }
            return null;
        }
    };
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Function2(org.apache.calcite.linq4j.function.Function2) LogicalCorrelate(org.apache.calcite.rel.logical.LogicalCorrelate) CorrelationId(org.apache.calcite.rel.core.CorrelationId)

Example 15 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project flink by apache.

the class FlinkRelDecorrelator method getNewForOldInputRef.

private RexInputRef getNewForOldInputRef(RexInputRef oldInputRef) {
    assert currentRel != null;
    int oldOrdinal = oldInputRef.getIndex();
    int newOrdinal = 0;
    // determine which input rel oldOrdinal references, and adjust
    // oldOrdinal to be relative to that input rel
    RelNode oldInput = null;
    for (RelNode oldInput0 : currentRel.getInputs()) {
        RelDataType oldInputType = oldInput0.getRowType();
        int n = oldInputType.getFieldCount();
        if (oldOrdinal < n) {
            oldInput = oldInput0;
            break;
        }
        RelNode newInput = map.get(oldInput0).r;
        newOrdinal += newInput.getRowType().getFieldCount();
        oldOrdinal -= n;
    }
    assert oldInput != null;
    final Frame frame = map.get(oldInput);
    assert frame != null;
    // now oldOrdinal is relative to oldInput
    int oldLocalOrdinal = oldOrdinal;
    // figure out the newLocalOrdinal, relative to the newInput.
    int newLocalOrdinal = oldLocalOrdinal;
    if (!frame.oldToNewOutputPos.isEmpty()) {
        newLocalOrdinal = frame.oldToNewOutputPos.get(oldLocalOrdinal);
    }
    newOrdinal += newLocalOrdinal;
    return new RexInputRef(newOrdinal, frame.r.getRowType().getFieldList().get(newLocalOrdinal).getType());
}
Also used : RelNode(org.apache.calcite.rel.RelNode) RexInputRef(org.apache.calcite.rex.RexInputRef) RelDataType(org.apache.calcite.rel.type.RelDataType)

Aggregations

RelNode (org.apache.calcite.rel.RelNode)2174 RexNode (org.apache.calcite.rex.RexNode)587 ArrayList (java.util.ArrayList)512 Test (org.junit.jupiter.api.Test)423 RelBuilder (org.apache.calcite.tools.RelBuilder)406 RelDataType (org.apache.calcite.rel.type.RelDataType)304 RexBuilder (org.apache.calcite.rex.RexBuilder)273 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)264 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)258 RexInputRef (org.apache.calcite.rex.RexInputRef)202 RelTraitSet (org.apache.calcite.plan.RelTraitSet)191 List (java.util.List)185 Project (org.apache.calcite.rel.core.Project)183 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)169 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)166 Pair (org.apache.calcite.util.Pair)163 AggregateCall (org.apache.calcite.rel.core.AggregateCall)159 TimestampString (org.apache.calcite.util.TimestampString)154 HashMap (java.util.HashMap)151 RelOptCluster (org.apache.calcite.plan.RelOptCluster)151