forked from apache/kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAFKA-3522: Add public interfaces for timestamped stores (apache#6175)
Reviewers: Bill Bejeck <[email protected]>, John Roesler <[email protected]>, Guozhang Wang <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,300 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
streams/src/main/java/org/apache/kafka/streams/state/TimestampedWindowStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.kafka.streams.state; | ||
|
||
import org.apache.kafka.streams.kstream.Windowed; | ||
|
||
/** | ||
* Interface for storing the aggregated values of fixed-size time windows. | ||
* <p> | ||
* Note, that the stores's physical key type is {@link Windowed Windowed<K>}. | ||
* In contrast to a {@link WindowStore} that stores plain windowedKeys-value pairs, | ||
* a {@code TimestampedWindowStore} stores windowedKeys-(value/timestamp) pairs. | ||
* <p> | ||
* While the window start- and end-timestamp are fixed per window, the value-side timestamp is used | ||
* to store the last update timestamp of the corresponding window. | ||
* | ||
* @param <K> Type of keys | ||
* @param <V> Type of values | ||
*/ | ||
public interface TimestampedWindowStore<K, V> extends WindowStore<K, ValueAndTimestamp<V>> { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
streams/src/main/java/org/apache/kafka/streams/state/internals/KeyValueIteratorFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.kafka.streams.state.internals; | ||
|
||
import org.apache.kafka.streams.KeyValue; | ||
import org.apache.kafka.streams.state.KeyValueIterator; | ||
import org.apache.kafka.streams.state.ValueAndTimestamp; | ||
|
||
public class KeyValueIteratorFacade<K, V> implements KeyValueIterator<K, V> { | ||
private final KeyValueIterator<K, ValueAndTimestamp<V>> innerIterator; | ||
|
||
public KeyValueIteratorFacade(final KeyValueIterator<K, ValueAndTimestamp<V>> iterator) { | ||
innerIterator = iterator; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return innerIterator.hasNext(); | ||
} | ||
|
||
@Override | ||
public K peekNextKey() { | ||
return innerIterator.peekNextKey(); | ||
} | ||
|
||
@Override | ||
public KeyValue<K, V> next() { | ||
final KeyValue<K, ValueAndTimestamp<V>> innerKeyValue = innerIterator.next(); | ||
return KeyValue.pair(innerKeyValue.key, innerKeyValue.value.value()); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
innerIterator.close(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...s/src/main/java/org/apache/kafka/streams/state/internals/ReadOnlyKeyValueStoreFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.kafka.streams.state.internals; | ||
|
||
import org.apache.kafka.streams.state.KeyValueIterator; | ||
import org.apache.kafka.streams.state.ReadOnlyKeyValueStore; | ||
import org.apache.kafka.streams.state.TimestampedKeyValueStore; | ||
import org.apache.kafka.streams.state.ValueAndTimestamp; | ||
|
||
public class ReadOnlyKeyValueStoreFacade<K, V> implements ReadOnlyKeyValueStore<K, V> { | ||
protected final TimestampedKeyValueStore<K, V> inner; | ||
|
||
protected ReadOnlyKeyValueStoreFacade(final TimestampedKeyValueStore<K, V> store) { | ||
inner = store; | ||
} | ||
|
||
@Override | ||
public V get(final K key) { | ||
final ValueAndTimestamp<V> valueAndTimestamp = inner.get(key); | ||
return valueAndTimestamp == null ? null : valueAndTimestamp.value(); | ||
} | ||
|
||
@Override | ||
public KeyValueIterator<K, V> range(final K from, | ||
final K to) { | ||
return new KeyValueIteratorFacade<>(inner.range(from, to)); | ||
} | ||
|
||
@Override | ||
public KeyValueIterator<K, V> all() { | ||
return new KeyValueIteratorFacade<>(inner.all()); | ||
} | ||
|
||
@Override | ||
public long approximateNumEntries() { | ||
return inner.approximateNumEntries(); | ||
} | ||
} |
Oops, something went wrong.