use of org.apache.samza.util.TimestampedValue in project samza by apache.
the class TestTimestampedValueSerde method testEmptyValueSerialization.
@Test
public void testEmptyValueSerialization() {
byte[] expectedBytes = new byte[8];
ByteBuffer.wrap(expectedBytes).putLong(1234L);
TimestampedValueSerde<Integer> timestampedValueSerde = new TimestampedValueSerde<>(new IntegerSerde());
TimestampedValue<Integer> timestampedValue = new TimestampedValue<>(null, 1234L);
assertTrue(Arrays.equals(expectedBytes, timestampedValueSerde.toBytes(timestampedValue)));
}
use of org.apache.samza.util.TimestampedValue in project samza by apache.
the class TestTimeSeriesStoreImpl method testGetWithNonExistentKeys.
@Test
public void testGetWithNonExistentKeys() {
TimeSeriesStore<String, byte[]> timeSeriesStore = newTimeSeriesStore(new StringSerde("UTF-8"), true);
timeSeriesStore.put("hello", "world-1".getBytes(), 1L);
// read from a non-existent key
List<TimestampedValue<byte[]>> values = readStore(timeSeriesStore, "non-existent-key", 0, Integer.MAX_VALUE);
Assert.assertEquals(0, values.size());
// read from an existing key but out of range timestamp
values = readStore(timeSeriesStore, "hello", 2, Integer.MAX_VALUE);
Assert.assertEquals(0, values.size());
}
use of org.apache.samza.util.TimestampedValue in project samza by apache.
the class PartialJoinOperatorImpl method handleMessageAsync.
@Override
protected CompletionStage<Collection<JM>> handleMessageAsync(M message, MessageCollector collector, TaskCoordinator coordinator) {
Collection<JM> output = Collections.emptyList();
try {
KeyValueStore<K, TimestampedValue<M>> thisState = thisPartialJoinFn.getState();
KeyValueStore<K, TimestampedValue<OM>> otherState = otherPartialJoinFn.getState();
K key = thisPartialJoinFn.getKey(message);
thisState.put(key, new TimestampedValue<>(message, clock.currentTimeMillis()));
TimestampedValue<OM> otherMessage = otherState.get(key);
long now = clock.currentTimeMillis();
if (otherMessage != null && otherMessage.getTimestamp() > now - ttlMs) {
JM joinResult = thisPartialJoinFn.apply(message, otherMessage.getValue());
output = Collections.singletonList(joinResult);
}
} catch (Exception e) {
throw new SamzaException("Error handling message in PartialJoinOperatorImpl " + getOpImplId(), e);
}
return CompletableFuture.completedFuture(output);
}
use of org.apache.samza.util.TimestampedValue in project samza by apache.
the class TimestampedValueSerde method fromBytes.
@Override
public TimestampedValue<V> fromBytes(byte[] bytes) {
ByteBuffer bb = ByteBuffer.wrap(bytes);
byte[] vBytes = new byte[bytes.length - TIMESTAMP_BYTES];
bb.get(vBytes, 0, vBytes.length);
V v = vSerde.fromBytes(vBytes);
long ts = bb.getLong();
return new TimestampedValue<>(v, ts);
}
Aggregations