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;
}
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;
}
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;
}
}
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);
}
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);
}
Aggregations