@Internal public abstract class PrimitiveArrayComparator<T,C extends BasicTypeComparator> extends TypeComparator<T>
Modifier and Type | Field and Description |
---|---|
protected boolean |
ascending |
protected C |
comparator |
protected T |
reference |
Constructor and Description |
---|
PrimitiveArrayComparator(boolean ascending,
C comparator) |
Modifier and Type | Method and Description |
---|---|
int |
compareSerialized(DataInputView firstSource,
DataInputView secondSource)
Compares two records in serialized form.
|
int |
compareToReference(TypeComparator<T> referencedComparator)
This method compares the element that has been set as reference in this type accessor, to the
element set as reference in the given type accessor.
|
boolean |
equalToReference(T candidate)
Checks, whether the given element is equal to the element that has been set as the comparison
reference in this comparator instance.
|
int |
extractKeys(Object record,
Object[] target,
int index)
Extracts the key fields from a record.
|
TypeComparator[] |
getFlatComparators()
Get the field comparators.
|
int |
getNormalizeKeyLen()
Gets the number of bytes that the normalized key would maximally take.
|
boolean |
invertNormalizedKey()
Flag whether normalized key comparisons should be inverted key should be interpreted
inverted, i.e.
|
boolean |
isNormalizedKeyPrefixOnly(int keyBytes)
Checks, whether the given number of bytes for a normalized is only a prefix to determine the
order of elements of the data type for which this comparator provides the comparison methods.
|
void |
putNormalizedKey(T record,
MemorySegment target,
int offset,
int numBytes)
Writes a normalized key for the given record into the target byte array, starting at the
specified position and writing exactly the given number of bytes.
|
T |
readWithKeyDenormalization(T reuse,
DataInputView source)
Reads the record back while de-normalizing the key fields.
|
void |
setReference(T toCompare)
Sets the given element as the comparison reference for future calls to
TypeComparator.equalToReference(Object) and TypeComparator.compareToReference(TypeComparator) . |
boolean |
supportsNormalizedKey()
Checks whether the data type supports the creation of a normalized key for comparison.
|
boolean |
supportsSerializationWithKeyNormalization()
Check whether this comparator supports to serialize the record in a format that replaces its
keys by a normalized key.
|
void |
writeWithKeyNormalization(T record,
DataOutputView target)
Writes the record in such a fashion that all keys are normalizing and at the beginning of the
serialized data.
|
compare, compareAgainstReference, duplicate, hash, supportsCompareAgainstReference
protected final boolean ascending
protected transient T reference
protected final C extends BasicTypeComparator comparator
public PrimitiveArrayComparator(boolean ascending, C comparator)
public void setReference(T toCompare)
TypeComparator
TypeComparator.equalToReference(Object)
and TypeComparator.compareToReference(TypeComparator)
. This method must
set the given element into this comparator instance's state. If the comparison happens on a
subset of the fields from the record, this method may extract those fields.
A typical example for checking the equality of two elements is the following:
E e1 = ...;
E e2 = ...;
TypeComparator<E> acc = ...;
acc.setReference(e1);
boolean equal = acc.equalToReference(e2);
The rational behind this method is that elements are typically compared using certain
features that are extracted from them, (such de-serializing as a subset of fields). When
setting the reference, this extraction happens. The extraction needs happen only once per
element, even though an element is often compared to multiple other elements, such as when
finding equal elements in the process of grouping the elements.setReference
in class TypeComparator<T>
toCompare
- The element to set as the comparison reference.public boolean equalToReference(T candidate)
TypeComparator
equalToReference
in class TypeComparator<T>
candidate
- The candidate to check.TypeComparator.setReference(Object)
public int compareToReference(TypeComparator<T> referencedComparator)
TypeComparator
e1
and e2
via a comparator, this method can be used the following way.
E e1 = ...;
E e2 = ...;
TypeComparator<E> acc1 = ...;
TypeComparator<E> acc2 = ...;
acc1.setReference(e1);
acc2.setReference(e2);
int comp = acc1.compareToReference(acc2);
The rational behind this method is that elements are typically compared using certain
features that are extracted from them, (such de-serializing as a subset of fields). When
setting the reference, this extraction happens. The extraction needs happen only once per
element, even though an element is typically compared to many other elements when
establishing a sorted order. The actual comparison performed by this method may be very
cheap, as it happens on the extracted features.compareToReference
in class TypeComparator<T>
referencedComparator
- The type accessors where the element for comparison has been set
as reference.referencedAccessors
is
smaller than the reference value of this type accessor; a value greater than zero, if it
is larger; zero, if both are equal.TypeComparator.setReference(Object)
public int compareSerialized(DataInputView firstSource, DataInputView secondSource) throws IOException
TypeComparator
Comparator.compare(Object, Object)
.
This method may de-serialize the records or compare them directly based on their binary representation.
compareSerialized
in class TypeComparator<T>
firstSource
- The input view containing the first record.secondSource
- The input view containing the second record.Comparator.compare(Object, Object)
.IOException
- Thrown, if any of the input views raised an exception when reading the
records.Comparator.compare(Object, Object)
public int extractKeys(Object record, Object[] target, int index)
TypeComparator
extractKeys
in class TypeComparator<T>
record
- The record that contains the key(s)target
- The array to write the key(s) into.index
- The offset of the target array to start writing into.public TypeComparator[] getFlatComparators()
TypeComparator
TypeComparator.extractKeys(Object, Object[],
int)
to provide interoperability between different record types. Note, that this should
return at least one Comparator and that the number of Comparators must match the number of
extracted keys.getFlatComparators
in class TypeComparator<T>
public boolean supportsNormalizedKey()
TypeComparator
supportsNormalizedKey
in class TypeComparator<T>
public boolean supportsSerializationWithKeyNormalization()
TypeComparator
supportsSerializationWithKeyNormalization
in class TypeComparator<T>
public int getNormalizeKeyLen()
TypeComparator
Integer
.MAX_VALUE is interpreted as infinite.getNormalizeKeyLen
in class TypeComparator<T>
public boolean isNormalizedKeyPrefixOnly(int keyBytes)
TypeComparator
isNormalizedKeyPrefixOnly
in class TypeComparator<T>
public void putNormalizedKey(T record, MemorySegment target, int offset, int numBytes)
TypeComparator
int byteI = bytes[i] & 0xFF;
If the meaningful part of the normalized key takes less than the given number of bytes,
then it must be padded. Padding is typically required for variable length data types, such as
strings. The padding uses a special character, either 0
or 0xff
, depending on
whether shorter values are sorted to the beginning or the end.
This method is similar to NormalizableKey.copyNormalizedKey(MemorySegment, int, int)
. In the
case that multiple fields of a record contribute to the normalized key, it is crucial that
the fields align on the byte field, i.e. that every field always takes up the exact same
number of bytes.
putNormalizedKey
in class TypeComparator<T>
record
- The record for which to create the normalized key.target
- The byte array into which to write the normalized key bytes.offset
- The offset in the byte array, where to start writing the normalized key bytes.numBytes
- The number of bytes to be written exactly.NormalizableKey.copyNormalizedKey(MemorySegment, int, int)
public void writeWithKeyNormalization(T record, DataOutputView target) throws IOException
TypeComparator
#supportsSerializationWithKeyNormalization()
allows to check
that.writeWithKeyNormalization
in class TypeComparator<T>
record
- The record object into which to read the record data.target
- The stream to which to write the data,IOException
TypeComparator.supportsSerializationWithKeyNormalization()
,
TypeComparator.readWithKeyDenormalization(Object, DataInputView)
,
NormalizableKey.copyNormalizedKey(MemorySegment, int, int)
public T readWithKeyDenormalization(T reuse, DataInputView source) throws IOException
TypeComparator
#supportsSerializationWithKeyNormalization()
method.readWithKeyDenormalization
in class TypeComparator<T>
reuse
- The reuse object into which to read the record data.source
- The stream from which to read the data,IOException
TypeComparator.supportsSerializationWithKeyNormalization()
,
TypeComparator.writeWithKeyNormalization(Object, DataOutputView)
,
NormalizableKey.copyNormalizedKey(MemorySegment, int, int)
public boolean invertNormalizedKey()
TypeComparator
invertNormalizedKey
in class TypeComparator<T>
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.