/** * Generic implementation of the comparator creation. Composite types are supplying the * infrastructure to create the actual comparators * * @return The comparator */ public TypeComparator<T> createComparator( int[] logicalKeyFields, boolean[] orders, int logicalFieldOffset, ExecutionConfig config) { initializeNewComparator(logicalKeyFields.length); for (int logicalKeyFieldIndex = 0; logicalKeyFieldIndex < logicalKeyFields.length; logicalKeyFieldIndex++) { int logicalKeyField = logicalKeyFields[logicalKeyFieldIndex]; int logicalField = logicalFieldOffset; // this is the global/logical field number for (int localFieldId = 0; localFieldId < this.getArity(); localFieldId++) { TypeInformation<?> localFieldType = this.getTypeAt(localFieldId); if (localFieldType instanceof AtomicType && logicalField == logicalKeyField) { // we found an atomic key --> create comparator addCompareField( localFieldId, ((AtomicType<?>) localFieldType) .createComparator(orders[logicalKeyFieldIndex], config)); } else if (localFieldType instanceof CompositeType && // must be a composite type (logicalField <= logicalKeyField // check if keyField can be at or behind the current // logicalField && logicalKeyField <= logicalField + (localFieldType.getTotalFields() - 1)) // check if logical field + lookahead could contain our key ) { // we found a compositeType that is containing the logicalKeyField we are looking for --> // create comparator addCompareField( localFieldId, ((CompositeType<?>) localFieldType) .createComparator( new int[] {logicalKeyField}, new boolean[] {orders[logicalKeyFieldIndex]}, logicalField, config)); } // maintain logicalField if (localFieldType instanceof CompositeType) { // we need to subtract 1 because we are not accounting for the local field (not accessible // for the user) logicalField += localFieldType.getTotalFields() - 1; } logicalField++; } } return getNewComparator(config); }