@Override public T deserialize(T reuse, DataInputView source) throws IOException { boolean isNull = deserializeNull(source); return isNull ? null : (reuse == null ? originalSerializer.deserialize(source) : originalSerializer.deserialize(reuse, source)); }
@Override public int compareSerialized(final DataInputView firstSource, final DataInputView secondSource) throws IOException { if (this.reference == null) { this.reference = this.serializer.createInstance(); } if (this.tmpReference == null) { this.tmpReference = this.serializer.createInstance(); } this.reference = this.serializer.deserialize(this.reference, firstSource); this.tmpReference = this.serializer.deserialize(this.tmpReference, secondSource); int cmp = this.reference.compareTo(this.tmpReference); return this.ascending ? cmp : -cmp; }
@Override public void writeRecord(T record) throws IOException { T recordCopy = this.typeSerializer.createInstance(); recordCopy = this.typeSerializer.copy(record, recordCopy); this.taskResult.add(recordCopy); }
public void migrateSerializedValue( DataInputDeserializer serializedOldValueInput, DataOutputSerializer serializedMigratedValueOutput, TypeSerializer<V> priorSerializer, TypeSerializer<V> newSerializer) throws StateMigrationException { try { V value = priorSerializer.deserialize(serializedOldValueInput); newSerializer.serialize(value, serializedMigratedValueOutput); } catch (Exception e) { throw new StateMigrationException("Error while trying to migrate RocksDB state.", e); } }
int length = serializer.getLength() > 0 ? serializer.getLength() : 1; DataOutputSerializer dos = new DataOutputSerializer(length); try { serializer.serialize(null, dos); serializer.getLength() < 0 || serializer.getLength() == dos.getCopyOfBuffer().length, "The serialized form of the null value should have the same length " + "as any other if the length is fixed in the serializer"); DataInputDeserializer dis = new DataInputDeserializer(dos.getSharedBuffer()); try { checkArgument(serializer.deserialize(dis) == null); serializer.copy(null) == null, "Serializer %s has to be able properly copy null value if it can serialize it", serializer.getClass().getName());
protected void writeSortedData(T value, TestOutputView out) throws IOException { TypeSerializer<T> serializer = getSerializer(); // Write data into a outputView serializer.serialize(value, out); // This are the same tests like in the serializer // Just look if the data is really there after serialization, before testing comparator on it TestInputView in = out.getInputView(); assertTrue("No data available during deserialization.", in.available() > 0); T deserialized = serializer.deserialize(serializer.createInstance(), in); deepEquals("Deserialized value is wrong.", value, deserialized); }
private static TypeSerializer[] duplicateFieldSerializers(TypeSerializer<Object>[] fieldSerializers) { TypeSerializer[] duplicatedSerializers = new TypeSerializer[fieldSerializers.length]; for (int index = 0; index < fieldSerializers.length; index++) { duplicatedSerializers[index] = fieldSerializers[index].duplicate(); assert duplicatedSerializers[index] != null; } return duplicatedSerializers; }
static PrecomputedParameters precompute( boolean immutableTargetType, TypeSerializer<Object>[] fieldSerializers) { Preconditions.checkNotNull(fieldSerializers); int totalLength = 0; boolean fieldsImmutable = true; boolean stateful = false; for (TypeSerializer<Object> fieldSerializer : fieldSerializers) { Preconditions.checkNotNull(fieldSerializer); if (fieldSerializer != fieldSerializer.duplicate()) { stateful = true; } if (!fieldSerializer.isImmutableType()) { fieldsImmutable = false; } if (fieldSerializer.getLength() < 0) { totalLength = -1; } totalLength = totalLength >= 0 ? totalLength + fieldSerializer.getLength() : totalLength; } return new PrecomputedParameters(immutableTargetType, fieldsImmutable, totalLength, stateful); } }
private static int computeTotalByteLength( TypeSerializer<?> keySerializer, TypeSerializer<?> namespaceSerializer) { if (keySerializer.getLength() >= 0 && namespaceSerializer.getLength() >= 0) { // timestamp + key + namespace return Long.BYTES + keySerializer.getLength() + namespaceSerializer.getLength(); } else { return -1; } }
protected final void instantiateDeserializationUtils() { this.deserializedFields1 = new Object[this.serializers.length]; this.deserializedFields2 = new Object[this.serializers.length]; for (int i = 0; i < this.serializers.length; i++) { this.deserializedFields1[i] = this.serializers[i].createInstance(); this.deserializedFields2[i] = this.serializers[i].createInstance(); } }
public CompositeTypeSerializerConfigSnapshot(TypeSerializer<?>... nestedSerializers) { Preconditions.checkNotNull(nestedSerializers); this.nestedSerializersAndConfigs = new ArrayList<>(nestedSerializers.length); for (TypeSerializer<?> nestedSerializer : nestedSerializers) { TypeSerializerSnapshot<?> configSnapshot = nestedSerializer.snapshotConfiguration(); this.nestedSerializersAndConfigs.add( new Tuple2<>(nestedSerializer.duplicate(), Preconditions.checkNotNull(configSnapshot))); } }
@Override public int compareSerialized(DataInputView firstSource, DataInputView secondSource) throws IOException { T first = this.serializer.createInstance(); T second = this.serializer.createInstance(); first = this.serializer.deserialize(first, firstSource); second = this.serializer.deserialize(second, secondSource); return this.compare(first, second); }
private GenericTypeComparator(GenericTypeComparator<T> toClone) { this.ascending = toClone.ascending; this.serializer = toClone.serializer.duplicate(); this.type = toClone.type; }
private Object[] instantiateDeserializationFields() { Object[] newFields = new Object[serializers.length]; for (int i = 0; i < serializers.length; i++) { newFields[i] = serializers[i].createInstance(); } return newFields; }
@Override public boolean equals(Object obj) { return obj == this || (obj != null && obj.getClass() == getClass() && elementSerializer.equals(((ListSerializer<?>) obj).elementSerializer)); }