use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project drill by axbaretto.
the class DrillSortRel method convert.
public static RelNode convert(Order order, ConversionContext context) throws InvalidRelException {
// if there are compound expressions in the order by, we need to convert into projects on either side.
RelNode input = context.toRel(order.getInput());
List<String> fields = input.getRowType().getFieldNames();
// build a map of field names to indices.
Map<String, Integer> fieldMap = Maps.newHashMap();
int i = 0;
for (String field : fields) {
fieldMap.put(field, i);
i++;
}
List<RelFieldCollation> collations = Lists.newArrayList();
for (Ordering o : order.getOrderings()) {
String fieldName = ExprHelper.getFieldName(o.getExpr());
int fieldId = fieldMap.get(fieldName);
RelFieldCollation c = new RelFieldCollation(fieldId, o.getDirection(), o.getNullDirection());
}
return new DrillSortRel(context.getCluster(), context.getLogicalTraits(), input, RelCollationImpl.of(collations));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project drill by axbaretto.
the class WindowPrel method getPhysicalOperator.
@Override
public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException {
Prel child = (Prel) this.getInput();
PhysicalOperator childPOP = child.getPhysicalOperator(creator);
final List<String> childFields = getInput().getRowType().getFieldNames();
// We don't support distinct partitions
checkState(groups.size() == 1, "Only one window is expected in WindowPrel");
Group window = groups.get(0);
List<NamedExpression> withins = Lists.newArrayList();
List<NamedExpression> aggs = Lists.newArrayList();
List<Order.Ordering> orderings = Lists.newArrayList();
for (int group : BitSets.toIter(window.keys)) {
FieldReference fr = new FieldReference(childFields.get(group), ExpressionPosition.UNKNOWN);
withins.add(new NamedExpression(fr, fr));
}
for (AggregateCall aggCall : window.getAggregateCalls(this)) {
FieldReference ref = new FieldReference(aggCall.getName());
LogicalExpression expr = toDrill(aggCall, childFields);
aggs.add(new NamedExpression(expr, ref));
}
for (RelFieldCollation fieldCollation : window.orderKeys.getFieldCollations()) {
orderings.add(new Order.Ordering(fieldCollation.getDirection(), new FieldReference(childFields.get(fieldCollation.getFieldIndex())), fieldCollation.nullDirection));
}
WindowPOP windowPOP = new WindowPOP(childPOP, withins, aggs, orderings, window.isRows, WindowPOP.newBound(window.lowerBound), WindowPOP.newBound(window.upperBound));
creator.addMetadata(this, windowPOP);
return windowPOP;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project drill by axbaretto.
the class SortPrule method getDistributionField.
private List<DistributionField> getDistributionField(DrillSortRel rel) {
List<DistributionField> distFields = Lists.newArrayList();
for (RelFieldCollation relField : rel.getCollation().getFieldCollations()) {
DistributionField field = new DistributionField(relField.getFieldIndex());
distFields.add(field);
}
return distFields;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project drill by apache.
the class WindowPrule method getCollation.
/**
* Create a RelCollation that has partition-by as the leading keys followed by order-by keys
* @param window The window specification
* @return a RelCollation with {partition-by keys, order-by keys}
*/
private RelCollation getCollation(Window.Group window) {
List<RelFieldCollation> fields = Lists.newArrayList();
for (int group : BitSets.toIter(window.keys)) {
fields.add(new RelFieldCollation(group));
}
fields.addAll(window.orderKeys.getFieldCollations());
return RelCollations.of(fields);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project drill by apache.
the class MongoPluginImplementor method implement.
@Override
public void implement(PluginSortRel sort) throws IOException {
runAggregate = true;
visitChild(sort.getInput());
if (!sort.collation.getFieldCollations().isEmpty()) {
BsonDocument sortKeys = new BsonDocument();
List<RelDataTypeField> fields = sort.getRowType().getFieldList();
for (RelFieldCollation fieldCollation : sort.collation.getFieldCollations()) {
String name = fields.get(fieldCollation.getFieldIndex()).getName();
sortKeys.put(name, new BsonInt32(direction(fieldCollation)));
}
operations.add(Aggregates.sort(sortKeys).toBsonDocument());
}
if (sort.offset != null) {
operations.add(Aggregates.skip(rexLiteralIntValue((RexLiteral) sort.offset)).toBsonDocument());
}
if (sort.fetch != null) {
operations.add(Aggregates.limit(rexLiteralIntValue((RexLiteral) sort.fetch)).toBsonDocument());
}
}
Aggregations