@Override public Stream<T> getElements() { return backend .getKeys(stateDescriptor.getName(), VoidNamespace.INSTANCE) .flatMap( key -> { try { backend.setCurrentKey(key); ListState<T> state = backend.getPartitionedState( VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, stateDescriptor); return StreamSupport.stream(state.get().spliterator(), false); } catch (Exception e) { throw new RuntimeException("Error reading keyed state.", e); } }); }
@Override public Stream<T> getElements() { return backend .getKeys(stateDescriptor.getName(), VoidNamespace.INSTANCE) .flatMap( key -> { try { backend.setCurrentKey(key); ListState<T> state = backend.getPartitionedState( VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, stateDescriptor); return StreamSupport.stream(state.get().spliterator(), false); } catch (Exception e) { throw new RuntimeException("Error reading keyed state.", e); } }); }
@Override public void clear() throws Exception { // TODO we have to collect all keys because otherwise we get ConcurrentModificationExceptions // from flink. We can change this once it's fixed in Flink List<K> keys = backend .getKeys(stateDescriptor.getName(), VoidNamespace.INSTANCE) .collect(Collectors.toList()); for (K key : keys) { backend.setCurrentKey(key); ListState<T> state = backend.getPartitionedState( VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, stateDescriptor); state.clear(); } }
@Override public void clear() throws Exception { // TODO we have to collect all keys because otherwise we get ConcurrentModificationExceptions // from flink. We can change this once it's fixed in Flink List<K> keys = backend .getKeys(stateDescriptor.getName(), VoidNamespace.INSTANCE) .collect(Collectors.toList()); for (K key : keys) { backend.setCurrentKey(key); ListState<T> state = backend.getPartitionedState( VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, stateDescriptor); state.clear(); } }