tzulitai commented on a change in pull request #8615: [FLINK-12729][state-processor-api] Add state reader for consuming non-partitioned operator state URL: https://github.com/apache/flink/pull/8615#discussion_r296537903
########## File path: flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/ExistingSavepoint.java ########## @@ -0,0 +1,171 @@ +/* + * 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.flink.state.api; + +import org.apache.flink.annotation.PublicEvolving; +import org.apache.flink.api.common.state.ListStateDescriptor; +import org.apache.flink.api.common.state.MapStateDescriptor; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeutils.TypeSerializer; +import org.apache.flink.api.java.DataSet; +import org.apache.flink.api.java.ExecutionEnvironment; +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.api.java.typeutils.TupleTypeInfo; +import org.apache.flink.runtime.state.StateBackend; +import org.apache.flink.state.api.input.BroadcastStateInputFormat; +import org.apache.flink.state.api.input.ListStateInputFormat; +import org.apache.flink.state.api.input.UnionStateInputFormat; + +/** + * An existing savepoint. + */ +@PublicEvolving +@SuppressWarnings("WeakerAccess") +public class ExistingSavepoint { + private final ExecutionEnvironment env; + + private final String existingSavepoint; + + private final StateBackend stateBackend; + + ExistingSavepoint(ExecutionEnvironment env, String path, StateBackend stateBackend) { + this.env = env; + this.existingSavepoint = path; + this.stateBackend = stateBackend; + } + + /** + * Read operator {@code ListState} from a {@code Savepoint}. + * @param uid The uid of the operator. + * @param name The (unique) name for the state. + * @param typeInfo The type of the elements in the state. + * @param <T> The type of the values that are in the list state. + * @return A {@code DataSet} representing the elements in state. + */ + public <T> DataSet<T> readListState(String uid, String name, TypeInformation<T> typeInfo) { + ListStateDescriptor<T> descriptor = new ListStateDescriptor<>(name, typeInfo); + ListStateInputFormat<T> inputFormat = new ListStateInputFormat<>(existingSavepoint, uid, descriptor); + return env.createInput(inputFormat, typeInfo); + } + + /** + * Read operator {@code ListState} from a {@code Savepoint} when a + * custom serializer was used; e.g., a different serializer than the + * one returned by {@code TypeInformation#createSerializer}. + * @param uid The uid of the operator. + * @param name The (unique) name for the state. + * @param typeInfo The type of the elements in the state. + * @param serializer The serializer used to write the elements into state. + * @param <T> The type of the values that are in the list state. + * @return A {@code DataSet} representing the elements in state. + */ + public <T> DataSet<T> readListState( + String uid, + String name, + TypeInformation<T> typeInfo, + TypeSerializer<T> serializer) { Review comment: As a follow-up, we can probably think about a variant where the user simply passes in a `TypeSerializer` and no `TypeInformation`. In this case, can we just wrap the given serializer into a "dummy" type info? Not entirely sure what methods of the `TypeInformation` will be used in the batch processing API. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
