public GroupReduceProperties(FieldSet groupKeys, Ordering additionalOrderKeys) { super(groupKeys); // if we have an additional ordering, construct the ordering to have primarily the grouping fields if (additionalOrderKeys != null) { this.ordering = new Ordering(); for (Integer key : this.keyList) { this.ordering.appendOrdering(key, null, Order.ANY); } // and next the additional order fields for (int i = 0; i < additionalOrderKeys.getNumberOfFields(); i++) { Integer field = additionalOrderKeys.getFieldNumber(i); Order order = additionalOrderKeys.getOrder(i); this.ordering.appendOrdering(field, additionalOrderKeys.getType(i), order); } } else { this.ordering = null; } }
@Override public boolean equals(Object obj) { if (obj instanceof RequestedLocalProperties) { final RequestedLocalProperties other = (RequestedLocalProperties) obj; return (this.ordering == other.ordering || (this.ordering != null && this.ordering.equals(other.ordering))) && (this.groupedFields == other.groupedFields || (this.groupedFields != null && this.groupedFields.equals(other.groupedFields))); } else { return false; } }
public static boolean[] getDirections(Ordering o, int numFields) { final boolean[] dirs = o.getFieldSortDirections(); if (dirs.length == numFields) { return dirs; } else if (dirs.length > numFields) { final boolean[] subSet = new boolean[numFields]; System.arraycopy(dirs, 0, subSet, 0, numFields); return subSet; } else { throw new CompilerException(); } }
private void addOrderingToSchema(Ordering o, SparseKeySchema schema) throws ConflictingFieldTypeInfoException { for (int i = 0; i < o.getNumberOfFields(); i++) { Integer pos = o.getFieldNumber(i); Class<? extends Key<?>> type = o.getType(i); schema.addType(pos, type); } }
public boolean matchesOrderedPartitioning(Ordering o) { if (this.partitioning == PartitioningProperty.RANGE_PARTITIONED) { if (this.ordering.getNumberOfFields() > o.getNumberOfFields()) { return false; for (int i = 0; i < this.ordering.getNumberOfFields(); i++) { if (this.ordering.getFieldNumber(i) != o.getFieldNumber(i)) { return false; final Order oo = o.getOrder(i); final Order to = this.ordering.getOrder(i); if (oo != Order.NONE) { if (oo == Order.ANY) {
public static final Ordering createOrdering(FieldList fields, boolean[] directions) { final Ordering o = new Ordering(); for (int i = 0; i < fields.size(); i++) { o.appendOrdering(fields.get(i), null, directions == null || directions[i] ? Order.ASCENDING : Order.DESCENDING); } return o; }
public Ordering clone() { final Ordering newOrdering = new Ordering(); newOrdering.indexes.addAll(this.indexes); newOrdering.types.addAll(this.types); newOrdering.orders.addAll(this.orders); return newOrdering; }
@Override public boolean areCoFulfilled(RequestedLocalProperties requested1, RequestedLocalProperties requested2, LocalProperties produced1, LocalProperties produced2) { int numRelevantFields = this.keys1.size(); Ordering prod1 = produced1.getOrdering(); Ordering prod2 = produced2.getOrdering(); if (prod1 == null || prod2 == null || prod1.getNumberOfFields() < numRelevantFields || prod2.getNumberOfFields() < prod2.getNumberOfFields()) { throw new CompilerException("The given properties do not meet this operators requirements."); } for (int i = 0; i < numRelevantFields; i++) { if (prod1.getOrder(i) != prod2.getOrder(i)) { return false; } } return true; }
public boolean isOrderEqualOnFirstNFields(Ordering other, int n) { if (n > getNumberOfFields() || n > other.getNumberOfFields()) { throw new IndexOutOfBoundsException(); } for (int i = 0; i < n; i++) { final Order o = this.orders.get(i); if (o == Order.NONE || o == Order.ANY || o != other.orders.get(i)) { return false; } } return true; }
/** * @param index * @param type * @param order */ public Ordering(int index, Class<? extends Key<?>> type, Order order) { appendOrdering(index, type, order); }
/** * Parameterizes the local strategy fields of a channel such that the channel produces the desired local properties. * * @param channel The channel to parameterize. */ public void parameterizeChannel(Channel channel) { if (this.ordering != null) { channel.setLocalStrategy(LocalStrategy.SORT, this.ordering.getInvolvedIndexes(), this.ordering.getFieldSortDirections()); } else if (this.groupedFields != null) { boolean[] dirs = new boolean[this.groupedFields.size()]; Arrays.fill(dirs, true); channel.setLocalStrategy(LocalStrategy.SORT, Utils.createOrderedFromSet(this.groupedFields), dirs); } }
final FieldList involvedIndexes = this.ordering.getInvolvedIndexes(); for (int i = 0; i < involvedIndexes.size(); i++) { if (!node.isFieldConstant(input, involvedIndexes.get(i))) { ngf = null; } else { no = this.ordering.createNewOrderingUpToIndex(i); ngf = no.getInvolvedIndexes();
/** * Creates a new ordering the represents an ordering on a prefix of the fields. If the * exclusive index up to which to create the ordering is <code>0</code>, then there is * no resulting ordering and this method return <code>null</code>. * * @param exclusiveIndex The index (exclusive) up to which to create the ordering. * @return The new ordering on the prefix of the fields, or <code>null</code>, if the prefix is empty. */ public Ordering createNewOrderingUpToIndex(int exclusiveIndex) { if (exclusiveIndex == 0) { return null; } final Ordering newOrdering = new Ordering(); for (int i = 0; i < exclusiveIndex; i++) { newOrdering.appendOrdering(this.indexes.get(i), this.types.get(i), this.orders.get(i)); } return newOrdering; }
public Ordering clone() { final Ordering newOrdering = new Ordering(); newOrdering.indexes.addAll(this.indexes); newOrdering.types.addAll(this.types); newOrdering.orders.addAll(this.orders); return newOrdering; }
@Override public boolean areCoFulfilled(RequestedLocalProperties requested1, RequestedLocalProperties requested2, LocalProperties produced1, LocalProperties produced2) { int numRelevantFields = this.keys1.size(); Ordering prod1 = produced1.getOrdering(); Ordering prod2 = produced2.getOrdering(); if (prod1 == null || prod2 == null || prod1.getNumberOfFields() < numRelevantFields || prod2.getNumberOfFields() < prod2.getNumberOfFields()) { throw new CompilerException("The given properties do not meet this operators requirements."); } for (int i = 0; i < numRelevantFields; i++) { if (prod1.getOrder(i) != prod2.getOrder(i)) { return false; } } return true; }
public boolean isOrderEqualOnFirstNFields(Ordering other, int n) { if (n > getNumberOfFields() || n > other.getNumberOfFields()) { throw new IndexOutOfBoundsException(); } for (int i = 0; i < n; i++) { final Order o = this.orders.get(i); if (o == Order.NONE || o == Order.ANY || o != other.orders.get(i)) { return false; } } return true; }
private void addOrderingToSchema(Ordering o, SparseKeySchema schema) throws ConflictingFieldTypeInfoException { for (int i = 0; i < o.getNumberOfFields(); i++) { Integer pos = o.getFieldNumber(i); Class<? extends Key<?>> type = o.getType(i); schema.addType(pos, type); } }
/** * @param index * @param type * @param order */ public Ordering(int index, Class<? extends Key<?>> type, Order order) { appendOrdering(index, type, order); }
public boolean matchesOrderedPartitioning(Ordering o) { if (this.partitioning == PartitioningProperty.RANGE_PARTITIONED) { if (this.ordering.getNumberOfFields() > o.getNumberOfFields()) { return false; for (int i = 0; i < this.ordering.getNumberOfFields(); i++) { if (this.ordering.getFieldNumber(i) != o.getFieldNumber(i)) { return false; final Order oo = o.getOrder(i); final Order to = this.ordering.getOrder(i); if (oo != Order.NONE) { if (oo == Order.ANY) {
/** * Parameterizes the local strategy fields of a channel such that the channel produces the desired local properties. * * @param channel The channel to parameterize. */ public void parameterizeChannel(Channel channel) { if (this.ordering != null) { channel.setLocalStrategy(LocalStrategy.SORT, this.ordering.getInvolvedIndexes(), this.ordering.getFieldSortDirections()); } else if (this.groupedFields != null) { boolean[] dirs = new boolean[this.groupedFields.size()]; Arrays.fill(dirs, true); channel.setLocalStrategy(LocalStrategy.SORT, Utils.createOrderedFromSet(this.groupedFields), dirs); } }