use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project calcite by apache.
the class ProjectWindowTransposeRule method findReference.
private ImmutableBitSet findReference(final LogicalProject project, final LogicalWindow window) {
final int windowInputColumn = window.getInput().getRowType().getFieldCount();
final ImmutableBitSet.Builder beReferred = ImmutableBitSet.builder();
final RexShuttle referenceFinder = new RexShuttle() {
@Override
public RexNode visitInputRef(RexInputRef inputRef) {
final int index = inputRef.getIndex();
if (index < windowInputColumn) {
beReferred.set(index);
}
return inputRef;
}
};
// Reference in LogicalProject
for (RexNode rexNode : project.getChildExps()) {
rexNode.accept(referenceFinder);
}
// Reference in LogicalWindow
for (Window.Group group : window.groups) {
// Reference in Partition-By
for (int index : group.keys) {
if (index < windowInputColumn) {
beReferred.set(index);
}
}
// Reference in Order-By
for (RelFieldCollation relFieldCollation : group.orderKeys.getFieldCollations()) {
if (relFieldCollation.getFieldIndex() < windowInputColumn) {
beReferred.set(relFieldCollation.getFieldIndex());
}
}
// Reference in Window Functions
for (Window.RexWinAggCall rexWinAggCall : group.aggCalls) {
rexWinAggCall.accept(referenceFinder);
}
}
return beReferred.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project calcite by apache.
the class SortJoinTransposeRule method matches.
// ~ Methods ----------------------------------------------------------------
@Override
public boolean matches(RelOptRuleCall call) {
final Sort sort = call.rel(0);
final Join join = call.rel(1);
final RelMetadataQuery mq = call.getMetadataQuery();
final JoinInfo joinInfo = JoinInfo.of(join.getLeft(), join.getRight(), join.getCondition());
// condition, we bail out
if (join.getJoinType() == JoinRelType.LEFT) {
if (sort.getCollation() != RelCollations.EMPTY) {
for (RelFieldCollation relFieldCollation : sort.getCollation().getFieldCollations()) {
if (relFieldCollation.getFieldIndex() >= join.getLeft().getRowType().getFieldCount()) {
return false;
}
}
}
if (sort.offset != null && !RelMdUtil.areColumnsDefinitelyUnique(mq, join.getRight(), joinInfo.rightSet())) {
return false;
}
} else if (join.getJoinType() == JoinRelType.RIGHT) {
if (sort.getCollation() != RelCollations.EMPTY) {
for (RelFieldCollation relFieldCollation : sort.getCollation().getFieldCollations()) {
if (relFieldCollation.getFieldIndex() < join.getLeft().getRowType().getFieldCount()) {
return false;
}
}
}
if (sort.offset != null && !RelMdUtil.areColumnsDefinitelyUnique(mq, join.getLeft(), joinInfo.leftSet())) {
return false;
}
} else {
return false;
}
return true;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project calcite by apache.
the class DruidQuery method explainTerms.
@Override
public RelWriter explainTerms(RelWriter pw) {
for (RelNode rel : rels) {
if (rel instanceof TableScan) {
TableScan tableScan = (TableScan) rel;
pw.item("table", tableScan.getTable().getQualifiedName());
pw.item("intervals", intervals);
} else if (rel instanceof Filter) {
pw.item("filter", ((Filter) rel).getCondition());
} else if (rel instanceof Project) {
if (((Project) rel).getInput() instanceof Aggregate) {
pw.item("post_projects", ((Project) rel).getProjects());
} else {
pw.item("projects", ((Project) rel).getProjects());
}
} else if (rel instanceof Aggregate) {
final Aggregate aggregate = (Aggregate) rel;
pw.item("groups", aggregate.getGroupSet()).item("aggs", aggregate.getAggCallList());
} else if (rel instanceof Sort) {
final Sort sort = (Sort) rel;
for (Ord<RelFieldCollation> ord : Ord.zip(sort.collation.getFieldCollations())) {
pw.item("sort" + ord.i, ord.e.getFieldIndex());
}
for (Ord<RelFieldCollation> ord : Ord.zip(sort.collation.getFieldCollations())) {
pw.item("dir" + ord.i, ord.e.shortString());
}
pw.itemIf("fetch", sort.fetch, sort.fetch != null);
} else {
throw new AssertionError("rel type not supported in Druid query " + rel);
}
}
return pw;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project calcite by apache.
the class RexUtil method apply.
/**
* Applies a mapping to a collation list.
*
* @param mapping Mapping
* @param collationList Collation list
* @return collation list with mapping applied to each field
*/
public static List<RelCollation> apply(Mappings.TargetMapping mapping, List<RelCollation> collationList) {
final List<RelCollation> newCollationList = new ArrayList<>();
for (RelCollation collation : collationList) {
final List<RelFieldCollation> newFieldCollationList = new ArrayList<>();
for (RelFieldCollation fieldCollation : collation.getFieldCollations()) {
final RelFieldCollation newFieldCollation = apply(mapping, fieldCollation);
if (newFieldCollation == null) {
// if it's empty).
break;
}
newFieldCollationList.add(newFieldCollation);
}
// and duplicate collations. Ignore these.
if (!newFieldCollationList.isEmpty()) {
final RelCollation newCollation = RelCollations.of(newFieldCollationList);
if (!newCollationList.contains(newCollation)) {
newCollationList.add(newCollation);
}
}
}
return newCollationList;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project calcite by apache.
the class GeodeSort method implement.
@Override
public void implement(GeodeImplementContext geodeImplementContext) {
((GeodeRel) getInput()).implement(geodeImplementContext);
List<RelFieldCollation> sortCollations = collation.getFieldCollations();
if (!sortCollations.isEmpty()) {
List<String> orderByFields = new ArrayList<String>();
for (RelFieldCollation fieldCollation : sortCollations) {
final String name = fieldName(fieldCollation.getFieldIndex());
orderByFields.add(name + " " + direction(fieldCollation.getDirection()));
}
geodeImplementContext.addOrderByFields(orderByFields);
}
if (fetch != null) {
geodeImplementContext.setLimit(((RexLiteral) fetch).getValue().toString());
}
}
Aggregations