use of org.apache.calcite.rel.RelFieldCollation in project drill by apache.
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.calcite.rel.RelFieldCollation in project drill by apache.
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.calcite.rel.RelFieldCollation in project drill by apache.
the class DrillWindowRel method implement.
@Override
public LogicalOperator implement(DrillImplementor implementor) {
final LogicalOperator inputOp = implementor.visitChild(this, 0, getInput());
org.apache.drill.common.logical.data.Window.Builder builder = new org.apache.drill.common.logical.data.Window.Builder();
final List<String> fields = getRowType().getFieldNames();
final List<String> childFields = getInput().getRowType().getFieldNames();
for (Group window : groups) {
for (RelFieldCollation orderKey : window.orderKeys.getFieldCollations()) {
builder.addOrdering(new Order.Ordering(orderKey.getDirection(), new FieldReference(fields.get(orderKey.getFieldIndex()))));
}
for (int group : BitSets.toIter(window.keys)) {
FieldReference fr = new FieldReference(childFields.get(group), ExpressionPosition.UNKNOWN);
builder.addWithin(fr, fr);
}
int groupCardinality = window.keys.cardinality();
for (Ord<AggregateCall> aggCall : Ord.zip(window.getAggregateCalls(this))) {
FieldReference ref = new FieldReference(fields.get(groupCardinality + aggCall.i));
LogicalExpression expr = toDrill(aggCall.e, childFields);
builder.addAggregation(ref, expr);
}
}
builder.setInput(inputOp);
org.apache.drill.common.logical.data.Window frame = builder.build();
return frame;
}
use of org.apache.calcite.rel.RelFieldCollation in project drill by apache.
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.calcite.rel.RelFieldCollation in project lucene-solr by apache.
the class SolrSort method implement.
public void implement(Implementor implementor) {
implementor.visitChild(0, getInput());
List<RelFieldCollation> sortCollations = collation.getFieldCollations();
if (!sortCollations.isEmpty()) {
// Construct a series of order clauses from the desired collation
final List<RelDataTypeField> fields = getRowType().getFieldList();
for (RelFieldCollation fieldCollation : sortCollations) {
final String name = fields.get(fieldCollation.getFieldIndex()).getName();
String direction = "asc";
if (fieldCollation.getDirection().equals(RelFieldCollation.Direction.DESCENDING)) {
direction = "desc";
}
implementor.addOrder(name, direction);
}
}
if (fetch != null) {
implementor.setLimit(((RexLiteral) fetch).getValue().toString());
}
}
Aggregations