/** * This method is handling the IllegalAccess exceptions of Field.get() */ public final Object accessField(Field field, Object object) { try { object = field.get(object); } catch (NullPointerException npex) { throw new NullKeyFieldException("Unable to access field "+field+" on object "+object); } catch (IllegalAccessException iaex) { throw new RuntimeException("This should not happen since we call setAccesssible(true) in PojoTypeInfo." + " fields: " + field + " obj: " + object); } return object; }
@Override public int compareToReference(TypeComparator<T> referencedComparator) { PojoComparator<T> other = (PojoComparator<T>) referencedComparator; int i = 0; try { for (; i < this.keyFields.length; i++) { int cmp = this.comparators[i].compareToReference(other.comparators[i]); if (cmp != 0) { return cmp; } } return 0; } catch (NullPointerException npex) { throw new NullKeyFieldException(this.keyFields[i].toString()); } }
@SuppressWarnings("unchecked") @Override public void putNormalizedKey(T value, MemorySegment target, int offset, int numBytes) { int i = 0; try { for (; i < this.numLeadingNormalizableKeys && numBytes > 0; i++) { int len = this.normalizedKeyLengths[i]; len = numBytes >= len ? len : numBytes; this.comparators[i].putNormalizedKey(value.getFieldNotNull(this.keyPositions[i]), target, offset, len); numBytes -= len; offset += len; } } catch (NullFieldException nfex) { throw new NullKeyFieldException(nfex); } catch (NullPointerException npex) { throw new NullKeyFieldException(this.keyPositions[i]); } }
/** * Gets the fields at the given positions into an array. * If at any position a field is null, then this method throws a @link NullKeyFieldException. * All fields that have been successfully read until the failing read are correctly contained in the record. * All other fields are not set. * * @param positions The positions of the fields to get. * @param targets The values into which the content of the fields is put. * * @throws NullKeyFieldException in case of a failing field read. */ public void getFieldsIntoCheckingNull(int[] positions, Value[] targets) { for (int i = 0; i < positions.length; i++) { if (!getFieldInto(positions[i], targets[i])) { throw new NullKeyFieldException(i); } } }
@Override public int compareToReference(TypeComparator<T> referencedComparator) { TupleComparatorBase<T> other = (TupleComparatorBase<T>) referencedComparator; int i = 0; try { for (; i < this.keyPositions.length; i++) { @SuppressWarnings("unchecked") int cmp = this.comparators[i].compareToReference(other.comparators[i]); if (cmp != 0) { return cmp; } } return 0; } catch (NullPointerException npex) { throw new NullKeyFieldException(keyPositions[i]); } catch (IndexOutOfBoundsException iobex) { throw new KeyFieldOutOfBoundsException(keyPositions[i]); } }
@SuppressWarnings("unchecked") @Override public boolean equalToReference(T candidate) { int i = 0; try { for (; i < this.keyPositions.length; i++) { if (!this.comparators[i].equalToReference(candidate.getFieldNotNull(this.keyPositions[i]))) { return false; } } return true; } catch (NullFieldException nfex) { throw new NullKeyFieldException(nfex); } catch (IndexOutOfBoundsException iobex) { throw new KeyFieldOutOfBoundsException(keyPositions[i]); } }
@SuppressWarnings("unchecked") @Override public void setReference(T toCompare) { int i = 0; try { for (; i < this.keyPositions.length; i++) { this.comparators[i].setReference(toCompare.getFieldNotNull(this.keyPositions[i])); } } catch (NullFieldException nfex) { throw new NullKeyFieldException(nfex); } catch (IndexOutOfBoundsException iobex) { throw new KeyFieldOutOfBoundsException(keyPositions[i]); } }
@SuppressWarnings("unchecked") @Override public int compare(T first, T second) { int i = 0; try { for (; i < keyPositions.length; i++) { int keyPos = keyPositions[i]; int cmp = comparators[i].compare(first.getFieldNotNull(keyPos), second.getFieldNotNull(keyPos)); if (cmp != 0) { return cmp; } } return 0; } catch (NullFieldException nfex) { throw new NullKeyFieldException(nfex); } catch (IndexOutOfBoundsException iobex) { throw new KeyFieldOutOfBoundsException(keyPositions[i]); } }
@SuppressWarnings("unchecked") @Override public int hash(T value) { int i = 0; try { int code = this.comparators[0].hash(value.getFieldNotNull(keyPositions[0])); for (i = 1; i < this.keyPositions.length; i++) { code *= HASH_SALT[i & 0x1F]; // salt code with (i % HASH_SALT.length)-th salt component code += this.comparators[i].hash(value.getFieldNotNull(keyPositions[i])); } return code; } catch (NullFieldException nfex) { throw new NullKeyFieldException(nfex); } catch (IndexOutOfBoundsException iobex) { throw new KeyFieldOutOfBoundsException(keyPositions[i]); } }
@SuppressWarnings("unchecked") @Override public int compareSerialized(DataInputView firstSource, DataInputView secondSource) throws IOException { if (deserializedFields1 == null) { instantiateDeserializationUtils(); } int i = 0; try { for (; i < serializers.length; i++) { deserializedFields1[i] = serializers[i].deserialize(deserializedFields1[i], firstSource); deserializedFields2[i] = serializers[i].deserialize(deserializedFields2[i], secondSource); } for (i = 0; i < keyPositions.length; i++) { int keyPos = keyPositions[i]; int cmp = comparators[i].compare(deserializedFields1[keyPos], deserializedFields2[keyPos]); if (cmp != 0) { return cmp; } } return 0; } catch (NullPointerException npex) { throw new NullKeyFieldException(keyPositions[i]); } catch (IndexOutOfBoundsException iobex) { throw new KeyFieldOutOfBoundsException(keyPositions[i], iobex); } }
/** * This method is handling the IllegalAccess exceptions of Field.get() */ public final Object accessField(Field field, Object object) { try { object = field.get(object); } catch (NullPointerException npex) { throw new NullKeyFieldException("Unable to access field "+field+" on object "+object); } catch (IllegalAccessException iaex) { throw new RuntimeException("This should not happen since we call setAccesssible(true) in PojoTypeInfo." + " fields: " + field + " obj: " + object); } return object; }
/** * This method is handling the IllegalAccess exceptions of Field.get() */ public final Object accessField(Field field, Object object) { try { object = field.get(object); } catch (NullPointerException npex) { throw new NullKeyFieldException("Unable to access field "+field+" on object "+object); } catch (IllegalAccessException iaex) { throw new RuntimeException("This should not happen since we call setAccesssible(true) in PojoTypeInfo." + " fields: " + field + " obj: " + object); } return object; }
@Override public int compareToReference(TypeComparator<T> referencedComparator) { PojoComparator<T> other = (PojoComparator<T>) referencedComparator; int i = 0; try { for (; i < this.keyFields.length; i++) { int cmp = this.comparators[i].compareToReference(other.comparators[i]); if (cmp != 0) { return cmp; } } return 0; } catch (NullPointerException npex) { throw new NullKeyFieldException(this.keyFields[i].toString()); } }
@Override public int compareToReference(TypeComparator<T> referencedComparator) { PojoComparator<T> other = (PojoComparator<T>) referencedComparator; int i = 0; try { for (; i < this.keyFields.length; i++) { int cmp = this.comparators[i].compareToReference(other.comparators[i]); if (cmp != 0) { return cmp; } } return 0; } catch (NullPointerException npex) { throw new NullKeyFieldException(this.keyFields[i].toString()); } }
@SuppressWarnings("unchecked") @Override public void putNormalizedKey(T value, MemorySegment target, int offset, int numBytes) { int i = 0; try { for (; i < this.numLeadingNormalizableKeys && numBytes > 0; i++) { int len = this.normalizedKeyLengths[i]; len = numBytes >= len ? len : numBytes; this.comparators[i].putNormalizedKey(value.getFieldNotNull(this.keyPositions[i]), target, offset, len); numBytes -= len; offset += len; } } catch (NullFieldException nfex) { throw new NullKeyFieldException(nfex); } catch (NullPointerException npex) { throw new NullKeyFieldException(this.keyPositions[i]); } }
/** * Gets the fields at the given positions into an array. * If at any position a field is null, then this method throws a @link NullKeyFieldException. * All fields that have been successfully read until the failing read are correctly contained in the record. * All other fields are not set. * * @param positions The positions of the fields to get. * @param targets The values into which the content of the fields is put. * * @throws NullKeyFieldException in case of a failing field read. */ public void getFieldsIntoCheckingNull(int[] positions, Value[] targets) { for (int i = 0; i < positions.length; i++) { if (!getFieldInto(positions[i], targets[i])) { throw new NullKeyFieldException(i); } } }
@SuppressWarnings("unchecked") @Override public void putNormalizedKey(T value, MemorySegment target, int offset, int numBytes) { int i = 0; try { for (; i < this.numLeadingNormalizableKeys && numBytes > 0; i++) { int len = this.normalizedKeyLengths[i]; len = numBytes >= len ? len : numBytes; this.comparators[i].putNormalizedKey(value.getFieldNotNull(this.keyPositions[i]), target, offset, len); numBytes -= len; offset += len; } } catch (NullFieldException nfex) { throw new NullKeyFieldException(nfex); } catch (NullPointerException npex) { throw new NullKeyFieldException(this.keyPositions[i]); } }
/** * Gets the fields at the given positions into an array. * If at any position a field is null, then this method throws a @link NullKeyFieldException. * All fields that have been successfully read until the failing read are correctly contained in the record. * All other fields are not set. * * @param positions The positions of the fields to get. * @param targets The values into which the content of the fields is put. * * @throws NullKeyFieldException in case of a failing field read. */ public void getFieldsIntoCheckingNull(int[] positions, Value[] targets) { for (int i = 0; i < positions.length; i++) { if (!getFieldInto(positions[i], targets[i])) { throw new NullKeyFieldException(i); } } }
private TypeSerializer<Object> createSerializer(Object key, int pos) { if (key == null) { throw new NullKeyFieldException(pos); } try { TypeInformation<Object> info = TypeExtractor.getForObject(key); return info.createSerializer(executionConfig); } catch (Throwable t) { throw new RuntimeException("Could not create key serializer for type " + key); } }
private TypeSerializer<Object> createSerializer(Object key, int pos) { if (key == null) { throw new NullKeyFieldException(pos); } try { TypeInformation<Object> info = TypeExtractor.getForObject(key); return info.createSerializer(executionConfig); } catch (Throwable t) { throw new RuntimeException("Could not create key serializer for type " + key); } }