Search in sources :

Example 46 with RelCollation

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelCollation in project hazelcast by hazelcast.

the class IndexResolver method excludeCoveredCollations.

/**
 * Filters out index scans which collation is covered (prefix based) by another index scan in the rels.
 *
 * @param rels the list of index scans
 * @return a filtered out map of collation to rel
 */
@SuppressWarnings("checkstyle:NPathComplexity")
private static Map<RelCollation, RelNode> excludeCoveredCollations(List<RelNode> rels) {
    // Order the index scans based on their collation
    TreeMap<RelCollation, RelNode> relsTreeMap = new TreeMap<>(RelCollationComparator.INSTANCE);
    // Put the rels into the ordered TreeMap
    for (RelNode rel : rels) {
        relsTreeMap.put(rel.getTraitSet().getTrait(RelCollationTraitDef.INSTANCE), rel);
    }
    Map<RelCollation, RelNode> resultMap = new HashMap<>();
    Map.Entry<RelCollation, RelNode> prevEntry = null;
    // Go through the ordered collations and exclude covered ones
    for (Map.Entry<RelCollation, RelNode> entry : relsTreeMap.descendingMap().entrySet()) {
        RelCollation collation = entry.getKey();
        RelNode relNode = entry.getValue();
        if (prevEntry == null) {
            resultMap.put(collation, relNode);
            prevEntry = entry;
        } else {
            RelCollation prevCollation = prevEntry.getKey();
            if (!prevCollation.satisfies(collation)) {
                prevEntry = entry;
                resultMap.put(collation, relNode);
            }
        }
    }
    return resultMap;
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) RelNode(org.apache.calcite.rel.RelNode) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 47 with RelCollation

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelCollation in project hazelcast by hazelcast.

the class IndexScanMapPhysicalRel method isDescending.

public boolean isDescending() {
    boolean descending = false;
    RelCollation relCollation = getTraitSet().getTrait(RelCollationTraitDef.INSTANCE);
    // In case of different directions Scan + Sort relations combination should be used.
    if (!relCollation.getFieldCollations().isEmpty()) {
        descending = relCollation.getFieldCollations().get(0).getDirection().isDescending();
    }
    return descending;
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation)

Example 48 with RelCollation

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelCollation in project hazelcast by hazelcast.

the class IndexScanMapPhysicalRel method getComparator.

public ComparatorEx<JetSqlRow> getComparator() {
    if (index.getType() == IndexType.SORTED) {
        RelCollation relCollation = getTraitSet().getTrait(RelCollationTraitDef.INSTANCE);
        List<FieldCollation> collations = relCollation.getFieldCollations().stream().map(FieldCollation::new).collect(toList());
        return ExpressionUtil.comparisonFn(collations);
    } else {
        return null;
    }
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) FieldCollation(com.hazelcast.jet.sql.impl.opt.FieldCollation)

Example 49 with RelCollation

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

the class LimitOffsetScanToLimitConverter method convert.

@Override
public RelNode convert(ResolvedLimitOffsetScan zetaNode, List<RelNode> inputs) {
    RelNode input = inputs.get(0);
    RelCollation relCollation = RelCollations.of(ImmutableList.of());
    RexNode offset = zetaNode.getOffset() == null ? null : getExpressionConverter().convertRexNodeFromResolvedExpr(zetaNode.getOffset());
    RexNode fetch = getExpressionConverter().convertRexNodeFromResolvedExpr(zetaNode.getLimit(), zetaNode.getColumnList(), input.getRowType().getFieldList(), ImmutableMap.of());
    // offset or fetch being RexDynamicParam means it is NULL (the only param supported currently)
    if (offset instanceof RexDynamicParam || RexLiteral.isNullLiteral(offset) || fetch instanceof RexDynamicParam || RexLiteral.isNullLiteral(fetch)) {
        throw new UnsupportedOperationException("Limit requires non-null count and offset");
    }
    return LogicalSort.create(input, relCollation, offset, fetch);
}
Also used : RelCollation(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelCollation) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) RexNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode) RexDynamicParam(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexDynamicParam)

Example 50 with RelCollation

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

the class LimitOffsetScanToOrderByLimitConverter method convert.

@Override
public RelNode convert(ResolvedLimitOffsetScan zetaNode, List<RelNode> inputs) {
    ResolvedOrderByScan inputOrderByScan = (ResolvedOrderByScan) zetaNode.getInputScan();
    RelNode input = inputs.get(0);
    RelCollation relCollation = getRelCollation(inputOrderByScan);
    RexNode offset = zetaNode.getOffset() == null ? null : getExpressionConverter().convertRexNodeFromResolvedExpr(zetaNode.getOffset());
    RexNode fetch = getExpressionConverter().convertRexNodeFromResolvedExpr(zetaNode.getLimit(), zetaNode.getColumnList(), input.getRowType().getFieldList(), ImmutableMap.of());
    if (RexLiteral.isNullLiteral(offset) || RexLiteral.isNullLiteral(fetch)) {
        throw new UnsupportedOperationException("Limit requires non-null count and offset");
    }
    RelNode sorted = LogicalSort.create(input, relCollation, offset, fetch);
    return convertOrderByScanToLogicalScan(inputOrderByScan, sorted);
}
Also used : RelCollation(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelCollation) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) ResolvedOrderByScan(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedOrderByScan) RexNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)

Aggregations

RelCollation (org.apache.calcite.rel.RelCollation)83 RelNode (org.apache.calcite.rel.RelNode)40 RelTraitSet (org.apache.calcite.plan.RelTraitSet)37 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)33 RexNode (org.apache.calcite.rex.RexNode)24 ArrayList (java.util.ArrayList)19 RelDataType (org.apache.calcite.rel.type.RelDataType)17 RelOptCluster (org.apache.calcite.plan.RelOptCluster)15 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)13 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)12 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)12 List (java.util.List)11 Sort (org.apache.calcite.rel.core.Sort)11 ImmutableList (com.google.common.collect.ImmutableList)8 RelDistribution (org.apache.calcite.rel.RelDistribution)8 RexInputRef (org.apache.calcite.rex.RexInputRef)8 Map (java.util.Map)7 Mappings (org.apache.calcite.util.mapping.Mappings)7 Supplier (com.google.common.base.Supplier)6 HashMap (java.util.HashMap)6