Search in sources :

Example 11 with RelCollation

use of org.apache.calcite.rel.RelCollation in project hive by apache.

the class HiveRelDecorrelator method decorrelateRel.

/**
 * Rewrite Sort.
 *
 * @param rel Sort to be rewritten
 */
public Frame decorrelateRel(Sort rel) {
    // Sort itself should not reference cor vars.
    assert !cm.mapRefRelToCorRef.containsKey(rel);
    // Sort only references field positions in collations field.
    // The collations field in the newRel now need to refer to the
    // new output positions in its input.
    // Its output does not change the input ordering, so there's no
    // need to call propagateExpr.
    final RelNode oldInput = rel.getInput();
    final Frame frame = getInvoke(oldInput, rel);
    if (frame == null) {
        // If input has not been rewritten, do not rewrite this rel.
        return null;
    }
    final RelNode newInput = frame.r;
    Mappings.TargetMapping mapping = Mappings.target(frame.oldToNewOutputs, oldInput.getRowType().getFieldCount(), newInput.getRowType().getFieldCount());
    RelCollation oldCollation = rel.getCollation();
    RelCollation newCollation = RexUtil.apply(mapping, oldCollation);
    final RelNode newSort = HiveSortLimit.create(newInput, newCollation, rel.offset, rel.fetch);
    // Sort does not change input ordering
    return register(rel, newSort, frame.oldToNewOutputs, frame.corDefOutputs);
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) HiveRelNode(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRelNode) RelNode(org.apache.calcite.rel.RelNode) Mappings(org.apache.calcite.util.mapping.Mappings)

Example 12 with RelCollation

use of org.apache.calcite.rel.RelCollation in project hive by apache.

the class HiveRelDecorrelator method decorrelateRel.

/**
 * Rewrite Sort.
 *
 * @param rel Sort to be rewritten
 */
public Frame decorrelateRel(HiveSortLimit rel) {
    // Sort itself should not reference cor vars.
    assert !cm.mapRefRelToCorRef.containsKey(rel);
    // Sort only references field positions in collations field.
    // The collations field in the newRel now need to refer to the
    // new output positions in its input.
    // Its output does not change the input ordering, so there's no
    // need to call propagateExpr.
    final RelNode oldInput = rel.getInput();
    final Frame frame = getInvoke(oldInput, rel);
    if (frame == null) {
        // If input has not been rewritten, do not rewrite this rel.
        return null;
    }
    final RelNode newInput = frame.r;
    Mappings.TargetMapping mapping = Mappings.target(frame.oldToNewOutputs, oldInput.getRowType().getFieldCount(), newInput.getRowType().getFieldCount());
    RelCollation oldCollation = rel.getCollation();
    RelCollation newCollation = RexUtil.apply(mapping, oldCollation);
    final RelNode newSort = HiveSortLimit.create(newInput, newCollation, rel.offset, rel.fetch);
    // Sort does not change input ordering
    return register(rel, newSort, frame.oldToNewOutputs, frame.corDefOutputs);
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) HiveRelNode(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRelNode) RelNode(org.apache.calcite.rel.RelNode) Mappings(org.apache.calcite.util.mapping.Mappings)

Aggregations

RelCollation (org.apache.calcite.rel.RelCollation)12 RelNode (org.apache.calcite.rel.RelNode)10 Mappings (org.apache.calcite.util.mapping.Mappings)5 RelTraitSet (org.apache.calcite.plan.RelTraitSet)4 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)3 HiveRelNode (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRelNode)3 HiveSortLimit (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSortLimit)3 InvalidRelException (org.apache.calcite.rel.InvalidRelException)2 RexInputRef (org.apache.calcite.rex.RexInputRef)2 RexNode (org.apache.calcite.rex.RexNode)2 HiveProject (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 Sort (org.apache.calcite.rel.core.Sort)1 Window (org.apache.calcite.rel.core.Window)1 LogicalSort (org.apache.calcite.rel.logical.LogicalSort)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1