Search in sources :

Example 1 with MeteredWindowStore

use of org.apache.kafka.streams.state.internals.MeteredWindowStore in project ksql by confluentinc.

the class WindowStoreCacheBypass method fetchRangeUncached.

/*
  This method is used for range queries. It is invoked by the fetchRange method
   */
private static KeyValueIterator<Windowed<GenericKey>, ValueAndTimestamp<GenericRow>> fetchRangeUncached(final ReadOnlyWindowStore<GenericKey, ValueAndTimestamp<GenericRow>> windowStore, final GenericKey keyFrom, final GenericKey keyTo, final Instant lower, final Instant upper) {
    if (!(windowStore instanceof MeteredWindowStore)) {
        throw new IllegalStateException("Expecting a MeteredWindowStore");
    }
    final StateSerdes<GenericKey, ValueAndTimestamp<GenericRow>> serdes = getSerdes(windowStore);
    final WindowStore<Bytes, byte[]> wrapped = getInnermostStore(windowStore);
    final Bytes rawKeyFrom = Bytes.wrap(serdes.rawKey(keyFrom));
    final Bytes rawKeyTo = Bytes.wrap(serdes.rawKey(keyTo));
    final KeyValueIterator<Windowed<Bytes>, byte[]> fetch = wrapped.fetch(rawKeyFrom, rawKeyTo, lower, upper);
    return new DeserializingKeyValueIterator(fetch, serdes);
}
Also used : ValueAndTimestamp(org.apache.kafka.streams.state.ValueAndTimestamp) Windowed(org.apache.kafka.streams.kstream.Windowed) Bytes(org.apache.kafka.common.utils.Bytes) MeteredWindowStore(org.apache.kafka.streams.state.internals.MeteredWindowStore) GenericKey(io.confluent.ksql.GenericKey)

Example 2 with MeteredWindowStore

use of org.apache.kafka.streams.state.internals.MeteredWindowStore in project ksql by confluentinc.

the class WindowStoreCacheBypass method fetchUncached.

/*
  This method is used for single key lookups. It is invoked by the fetch method
   */
private static WindowStoreIterator<ValueAndTimestamp<GenericRow>> fetchUncached(final ReadOnlyWindowStore<GenericKey, ValueAndTimestamp<GenericRow>> windowStore, final GenericKey key, final Instant lower, final Instant upper) {
    if (!(windowStore instanceof MeteredWindowStore)) {
        throw new IllegalStateException("Expecting a MeteredWindowStore");
    }
    final StateSerdes<GenericKey, ValueAndTimestamp<GenericRow>> serdes = getSerdes(windowStore);
    final WindowStore<Bytes, byte[]> wrapped = getInnermostStore(windowStore);
    final Bytes rawKey = Bytes.wrap(serdes.rawKey(key));
    final WindowStoreIterator<byte[]> fetch = wrapped.fetch(rawKey, lower, upper);
    return new DeserializingIterator(fetch, serdes);
}
Also used : ValueAndTimestamp(org.apache.kafka.streams.state.ValueAndTimestamp) Bytes(org.apache.kafka.common.utils.Bytes) MeteredWindowStore(org.apache.kafka.streams.state.internals.MeteredWindowStore) GenericKey(io.confluent.ksql.GenericKey)

Example 3 with MeteredWindowStore

use of org.apache.kafka.streams.state.internals.MeteredWindowStore in project ksql by confluentinc.

the class WindowStoreCacheBypass method getInnermostStore.

@SuppressWarnings("unchecked")
private static WindowStore<Bytes, byte[]> getInnermostStore(final ReadOnlyWindowStore<GenericKey, ValueAndTimestamp<GenericRow>> windowStore) {
    WindowStore<Bytes, byte[]> wrapped = ((MeteredWindowStore<GenericKey, ValueAndTimestamp<GenericRow>>) windowStore).wrapped();
    // layer.
    while (wrapped instanceof WrappedStateStore) {
        final StateStore store = ((WrappedStateStore<?, ?, ?>) wrapped).wrapped();
        // we just store there.
        if (!(store instanceof WindowStore)) {
            break;
        }
        wrapped = (WindowStore<Bytes, byte[]>) store;
    }
    // now we have the innermost layer of the store.
    return wrapped;
}
Also used : GenericRow(io.confluent.ksql.GenericRow) ReadOnlyWindowStore(org.apache.kafka.streams.state.ReadOnlyWindowStore) WindowStore(org.apache.kafka.streams.state.WindowStore) MeteredWindowStore(org.apache.kafka.streams.state.internals.MeteredWindowStore) CompositeReadOnlyWindowStore(org.apache.kafka.streams.state.internals.CompositeReadOnlyWindowStore) Bytes(org.apache.kafka.common.utils.Bytes) MeteredWindowStore(org.apache.kafka.streams.state.internals.MeteredWindowStore) WrappedStateStore(org.apache.kafka.streams.state.internals.WrappedStateStore) WrappedStateStore(org.apache.kafka.streams.state.internals.WrappedStateStore) StateStore(org.apache.kafka.streams.processor.StateStore)

Aggregations

Bytes (org.apache.kafka.common.utils.Bytes)3 MeteredWindowStore (org.apache.kafka.streams.state.internals.MeteredWindowStore)3 GenericKey (io.confluent.ksql.GenericKey)2 ValueAndTimestamp (org.apache.kafka.streams.state.ValueAndTimestamp)2 GenericRow (io.confluent.ksql.GenericRow)1 Windowed (org.apache.kafka.streams.kstream.Windowed)1 StateStore (org.apache.kafka.streams.processor.StateStore)1 ReadOnlyWindowStore (org.apache.kafka.streams.state.ReadOnlyWindowStore)1 WindowStore (org.apache.kafka.streams.state.WindowStore)1 CompositeReadOnlyWindowStore (org.apache.kafka.streams.state.internals.CompositeReadOnlyWindowStore)1 WrappedStateStore (org.apache.kafka.streams.state.internals.WrappedStateStore)1