Search in sources :

Example 1 with KeyValueIterator

use of org.apache.kafka.streams.state.KeyValueIterator in project kafka by apache.

the class SessionKeySchema method hasNextCondition.

@Override
public HasNextCondition hasNextCondition(final Bytes binaryKey, final long from, final long to) {
    return new HasNextCondition() {

        @Override
        public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) {
            if (iterator.hasNext()) {
                final Bytes bytes = iterator.peekNextKey();
                final Bytes keyBytes = Bytes.wrap(SessionKeySerde.extractKeyBytes(bytes.get()));
                if (!keyBytes.equals(binaryKey)) {
                    return false;
                }
                final long start = SessionKeySerde.extractStart(bytes.get());
                final long end = SessionKeySerde.extractEnd(bytes.get());
                return end >= from && start <= to;
            }
            return false;
        }
    };
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) KeyValueIterator(org.apache.kafka.streams.state.KeyValueIterator)

Example 2 with KeyValueIterator

use of org.apache.kafka.streams.state.KeyValueIterator in project kafka by apache.

the class WindowKeySchema method hasNextCondition.

@Override
public HasNextCondition hasNextCondition(final Bytes binaryKey, final long from, final long to) {
    return new HasNextCondition() {

        @Override
        public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) {
            if (iterator.hasNext()) {
                final Bytes bytes = iterator.peekNextKey();
                final Bytes keyBytes = WindowStoreUtils.bytesKeyFromBinaryKey(bytes.get());
                if (!keyBytes.equals(binaryKey)) {
                    return false;
                }
                final long time = WindowStoreUtils.timestampFromBinaryKey(bytes.get());
                return time >= from && time <= to;
            }
            return false;
        }
    };
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) KeyValueIterator(org.apache.kafka.streams.state.KeyValueIterator)

Aggregations

Bytes (org.apache.kafka.common.utils.Bytes)2 KeyValueIterator (org.apache.kafka.streams.state.KeyValueIterator)2