Search in sources :

Example 96 with RelNode

use of org.apache.calcite.rel.RelNode in project drill by apache.

the class SelectionVectorPrelVisitor method visitPrel.

@Override
public Prel visitPrel(Prel prel, Void value) throws RuntimeException {
    SelectionVectorMode[] encodings = prel.getSupportedEncodings();
    List<RelNode> children = Lists.newArrayList();
    for (Prel child : prel) {
        child = child.accept(this, null);
        children.add(convert(encodings, child));
    }
    return (Prel) prel.copy(prel.getTraitSet(), children);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) SelectionVectorMode(org.apache.drill.exec.record.BatchSchema.SelectionVectorMode) Prel(org.apache.drill.exec.planner.physical.Prel) SelectionVectorRemoverPrel(org.apache.drill.exec.planner.physical.SelectionVectorRemoverPrel)

Example 97 with RelNode

use of org.apache.calcite.rel.RelNode in project drill by apache.

the class StarColumnConverter method visitPrel.

@Override
public Prel visitPrel(Prel prel, Void value) throws RuntimeException {
    // Require prefix rename : there exists other expression, in addition to a star column.
    if (// not set yet.
    !prefixedForStar && StarColumnHelper.containsStarColumn(prel.getRowType()) && prel.getRowType().getFieldNames().size() > 1) {
        prefixedForStar = true;
    }
    List<RelNode> children = Lists.newArrayList();
    for (Prel child : prel) {
        child = child.accept(this, null);
        children.add(child);
    }
    return (Prel) prel.copy(prel.getTraitSet(), children);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) Prel(org.apache.drill.exec.planner.physical.Prel) ProjectAllowDupPrel(org.apache.drill.exec.planner.physical.ProjectAllowDupPrel) ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) ScreenPrel(org.apache.drill.exec.planner.physical.ScreenPrel) WriterPrel(org.apache.drill.exec.planner.physical.WriterPrel)

Example 98 with RelNode

use of org.apache.calcite.rel.RelNode in project drill by apache.

the class StarColumnConverter method visitProject.

@Override
public Prel visitProject(ProjectPrel prel, Void value) throws RuntimeException {
    ProjectPrel proj = (ProjectPrel) prel;
    // Require prefix rename : there exists other expression, in addition to a star column.
    if (// not set yet.
    !prefixedForStar && StarColumnHelper.containsStarColumnInProject(prel.getInput().getRowType(), proj.getProjects()) && prel.getRowType().getFieldNames().size() > 1) {
        prefixedForStar = true;
    }
    // For project, we need make sure that the project's field name is same as the input,
    // when the project expression is RexInPutRef, since we may insert a PAS which will
    // rename the projected fields.
    RelNode child = ((Prel) prel.getInput(0)).accept(this, null);
    List<String> fieldNames = Lists.newArrayList();
    for (Pair<String, RexNode> pair : Pair.zip(prel.getRowType().getFieldNames(), proj.getProjects())) {
        if (pair.right instanceof RexInputRef) {
            String name = child.getRowType().getFieldNames().get(((RexInputRef) pair.right).getIndex());
            fieldNames.add(name);
        } else {
            fieldNames.add(pair.left);
        }
    }
    // Make sure the field names are unique : no allow of duplicate field names in a rowType.
    fieldNames = makeUniqueNames(fieldNames);
    RelDataType rowType = RexUtil.createStructType(prel.getCluster().getTypeFactory(), proj.getProjects(), fieldNames);
    ProjectPrel newProj = (ProjectPrel) proj.copy(proj.getTraitSet(), child, proj.getProjects(), rowType);
    if (ProjectRemoveRule.isTrivial(newProj)) {
        return (Prel) child;
    } else {
        return newProj;
    }
}
Also used : ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) RelNode(org.apache.calcite.rel.RelNode) RexInputRef(org.apache.calcite.rex.RexInputRef) RelDataType(org.apache.calcite.rel.type.RelDataType) ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) Prel(org.apache.drill.exec.planner.physical.Prel) ProjectAllowDupPrel(org.apache.drill.exec.planner.physical.ProjectAllowDupPrel) ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) ScreenPrel(org.apache.drill.exec.planner.physical.ScreenPrel) WriterPrel(org.apache.drill.exec.planner.physical.WriterPrel) RexNode(org.apache.calcite.rex.RexNode)

Example 99 with RelNode

use of org.apache.calcite.rel.RelNode in project drill by apache.

the class NumberingRelWriter method explain_.

//~ Methods ----------------------------------------------------------------
protected void explain_(RelNode rel, List<Pair<String, Object>> values) {
    List<RelNode> inputs = rel.getInputs();
    if (rel instanceof HashJoinPrel && ((HashJoinPrel) rel).isSwapped()) {
        HashJoinPrel joinPrel = (HashJoinPrel) rel;
        inputs = FlatLists.of(joinPrel.getRight(), joinPrel.getLeft());
    }
    RelMetadataQuery mq = RelMetadataQuery.instance();
    if (!mq.isVisibleInExplain(rel, detailLevel)) {
        // render children in place of this, at same level
        explainInputs(inputs);
        return;
    }
    StringBuilder s = new StringBuilder();
    OpId id = ids.get(rel);
    if (id != null) {
        s.append(String.format("%02d-%02d", id.fragmentId, id.opId));
    } else {
        s.append("     ");
    }
    s.append("  ");
    if (id != null && id.opId == 0) {
        for (int i = 0; i < spacer.get(); i++) {
            s.append('-');
        }
    } else {
        spacer.spaces(s);
    }
    s.append("  ");
    s.append(rel.getRelTypeName().replace("Prel", ""));
    if (detailLevel != SqlExplainLevel.NO_ATTRIBUTES) {
        int j = 0;
        for (Pair<String, Object> value : values) {
            if (value.right instanceof RelNode) {
                continue;
            }
            if (j++ == 0) {
                s.append("(");
            } else {
                s.append(", ");
            }
            s.append(value.left).append("=[").append(value.right).append("]");
        }
        if (j > 0) {
            s.append(")");
        }
    }
    if (detailLevel == SqlExplainLevel.ALL_ATTRIBUTES) {
        s.append(" : rowType = ").append(rel.getRowType()).append(": rowcount = ").append(mq.getRowCount(rel)).append(", cumulative cost = ").append(mq.getCumulativeCost(rel)).append(", id = ").append(rel.getId());
    }
    pw.println(s);
    spacer.add(2);
    explainInputs(inputs);
    spacer.subtract(2);
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelNode(org.apache.calcite.rel.RelNode) HashJoinPrel(org.apache.drill.exec.planner.physical.HashJoinPrel) OpId(org.apache.drill.exec.planner.physical.explain.PrelSequencer.OpId)

Example 100 with RelNode

use of org.apache.calcite.rel.RelNode in project drill by apache.

the class NumberingRelWriter method done.

public RelWriter done(RelNode node) {
    int i = 0;
    if (values.size() > 0 && values.get(0).left.equals("subset")) {
        ++i;
    }
    for (RelNode input : node.getInputs()) {
        assert values.get(i).right == input;
        ++i;
    }
    for (RexNode expr : node.getChildExps()) {
        assert values.get(i).right == expr;
        ++i;
    }
    final List<Pair<String, Object>> valuesCopy = ImmutableList.copyOf(values);
    values.clear();
    explain_(node, valuesCopy);
    pw.flush();
    return this;
}
Also used : RelNode(org.apache.calcite.rel.RelNode) RexNode(org.apache.calcite.rex.RexNode) Pair(org.apache.calcite.util.Pair)

Aggregations

RelNode (org.apache.calcite.rel.RelNode)219 RexNode (org.apache.calcite.rex.RexNode)75 ArrayList (java.util.ArrayList)50 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)30 RelDataType (org.apache.calcite.rel.type.RelDataType)27 RelTraitSet (org.apache.calcite.plan.RelTraitSet)25 HashMap (java.util.HashMap)24 RexBuilder (org.apache.calcite.rex.RexBuilder)24 RexInputRef (org.apache.calcite.rex.RexInputRef)21 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)20 Prel (org.apache.drill.exec.planner.physical.Prel)20 AggregateCall (org.apache.calcite.rel.core.AggregateCall)16 Pair (org.apache.calcite.util.Pair)16 ImmutableList (com.google.common.collect.ImmutableList)15 Project (org.apache.calcite.rel.core.Project)14 RelOptCluster (org.apache.calcite.plan.RelOptCluster)13 HiveProject (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject)13 TreeMap (java.util.TreeMap)11 HashSet (java.util.HashSet)10 RelCollation (org.apache.calcite.rel.RelCollation)10