use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class AbstractRocksDBSegmentedBytesStore method fetch.
KeyValueIterator<Bytes, byte[]> fetch(final Bytes key, final long from, final long to, final boolean forward) {
final List<S> searchSpace = keySchema.segmentsToSearch(segments, from, to, forward);
final Bytes binaryFrom = keySchema.lowerRangeFixedSize(key, from);
final Bytes binaryTo = keySchema.upperRangeFixedSize(key, to);
return new SegmentIterator<>(searchSpace.iterator(), keySchema.hasNextCondition(key, key, from, to), binaryFrom, binaryTo, forward);
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class AbstractMergedSortedCacheStoreIterator method next.
@Override
public KeyValue<K, V> next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
final Bytes nextCacheKey = cacheIterator.hasNext() ? cacheIterator.peekNextKey() : null;
final KS nextStoreKey = storeIterator.hasNext() ? storeIterator.peekNextKey() : null;
if (nextCacheKey == null) {
return nextStoreValue(nextStoreKey);
}
if (nextStoreKey == null) {
return nextCacheValue(nextCacheKey);
}
final int comparison = compare(nextCacheKey, nextStoreKey);
return chooseNextValue(nextCacheKey, nextStoreKey, comparison);
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class AbstractMergedSortedCacheStoreIterator method peekNextKey.
@Override
public K peekNextKey() {
if (!hasNext()) {
throw new NoSuchElementException();
}
final Bytes nextCacheKey = cacheIterator.hasNext() ? cacheIterator.peekNextKey() : null;
final KS nextStoreKey = storeIterator.hasNext() ? storeIterator.peekNextKey() : null;
if (nextCacheKey == null) {
return deserializeStoreKey(nextStoreKey);
}
if (nextStoreKey == null) {
return deserializeCacheKey(nextCacheKey);
}
final int comparison = compare(nextCacheKey, nextStoreKey);
return chooseNextKey(nextCacheKey, nextStoreKey, comparison);
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class KGroupedTableImplTest method shouldAggregateAndMaterializeResults.
@Test
public void shouldAggregateAndMaterializeResults() {
builder.table(topic, Consumed.with(Serdes.String(), Serdes.String())).groupBy(MockMapper.selectValueKeyValueMapper(), Grouped.with(Serdes.String(), Serdes.String())).aggregate(MockInitializer.STRING_INIT, MockAggregator.TOSTRING_ADDER, MockAggregator.TOSTRING_REMOVER, Materialized.<String, String, KeyValueStore<Bytes, byte[]>>as("aggregate").withValueSerde(Serdes.String()).withKeySerde(Serdes.String()));
try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
processData(topic, driver);
{
{
final KeyValueStore<String, String> aggregate = driver.getKeyValueStore("aggregate");
assertThat(aggregate.get("1"), equalTo("0+1+1+1"));
assertThat(aggregate.get("2"), equalTo("0+2+2"));
}
{
final KeyValueStore<String, ValueAndTimestamp<String>> aggregate = driver.getTimestampedKeyValueStore("aggregate");
assertThat(aggregate.get("1"), equalTo(ValueAndTimestamp.make("0+1+1+1", 50L)));
assertThat(aggregate.get("2"), equalTo(ValueAndTimestamp.make("0+2+2", 60L)));
}
}
}
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class KGroupedTableImplTest method shouldReduce.
@Test
public void shouldReduce() {
final KeyValueMapper<String, Number, KeyValue<String, Integer>> intProjection = (key, value) -> KeyValue.pair(key, value.intValue());
final KTable<String, Integer> reduced = builder.table(topic, Consumed.with(Serdes.String(), Serdes.Double()), Materialized.<String, Double, KeyValueStore<Bytes, byte[]>>as("store").withKeySerde(Serdes.String()).withValueSerde(Serdes.Double())).groupBy(intProjection).reduce(MockReducer.INTEGER_ADDER, MockReducer.INTEGER_SUBTRACTOR, Materialized.as("reduced"));
final MockApiProcessorSupplier<String, Integer, Void, Void> supplier = getReducedResults(reduced);
try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
assertReduced(supplier.theCapturedProcessor().lastValueAndTimestampPerKey(), topic, driver);
assertEquals(reduced.queryableStoreName(), "reduced");
}
}
Aggregations