Interface EntryTransformer
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
This interface defines a transformation operation that accepts binary-serialized key and value objects and produces a Result.
An example implementation which converts every column to string representation:
class StringifyTransformer implements EntryTransformer {
@Override
public Result transform(BinaryObjectReader keyReader, @Nullable BinaryObjectReader valueReader) {
// Skip entries of unwanted type.
if (valueReader != null && !"org.myValue".equals(valueReader.typeName())) {
return Result.skip();
}
Tuple key = Tuple.create();
for (String fieldName : keyReader.fieldNames()) {
key.set(fieldName, "" + keyReader.readField(fieldName));
}
// If value reader is not presented, then this event belongs to a Remove operation.
// Let's remove this entry from GG9 cluster as well.
if (valueReader == null) {
return Result.remove(key);
}
Tuple value = Tuple.create();
for (String fieldName : valueReader.fieldNames()) {
value.set(fieldName, "" + valueReader.readField(fieldName));
}
return Result.upsert(key, value);
}
}
Lifecycle: Transformer is created by factory class specified in mapping configuration during connector startup once per mapping. The same instance of transformer will be reused to process all batches from related cache as per mapping configuration.
Thread Safety: Implementations are expected to be thread-safe as the same instance of transformer may be used by different threads to process incoming batches.
Exception Handling: Implementations should be designed to handle errors gracefully. If any exception is thrown from
the transform(org.gridgain.dr.conversion.BinaryObjectReader, org.gridgain.dr.conversion.BinaryObjectReader) method during execution, the result of the transformation operation, and therefore of the replication is
undefined.
-
Method Summary
Modifier and TypeMethodDescriptiontransform(BinaryObjectReader keyReader, @Nullable BinaryObjectReader valueReader) Transforms a key-value entry.
-
Method Details
-
transform
Transforms a key-value entry.This method receives binary object readers for both the key and value components of an GridGain 8 entry. The key reader is always non-null, while the value reader may be
nullfor removed entries (e.g. tombstones).If key and/or value part of GridGain 8 entry is simple object (like in case of
IgniteCache<Long, String>for example), thenBinaryObjectReaderwith single field will be created. For key part the field name will be_key, for value part the field name will be_val.Implementations can:
- Extract and process fields from the key and value using
BinaryObjectReader.readField(String). - Filter entries by returning appropriate Result states.
- Transform the entry data into a different format.
- Perform validation or enrichment operations.
Exception Behavior: If this method throws any exception during execution, the result of the transformation is undefined.
- Parameters:
keyReader- the binary reader for the entry's key, nevernull.valueReader- The binary reader for the entry's value, may benullif the entry represents a deletion.- Returns:
- The transformation result, should not be
null.
- Extract and process fields from the key and value using
-