org.apache.flink.table.runtime.functions.ExecutionContext Maven / Gradle / Ivy
/*
* 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.table.runtime.functions;
import org.apache.flink.api.common.functions.RuntimeContext;
import org.apache.flink.api.common.state.ListStateDescriptor;
import org.apache.flink.api.common.state.MapStateDescriptor;
import org.apache.flink.api.common.state.SortedMapStateDescriptor;
import org.apache.flink.api.common.state.ValueStateDescriptor;
import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.runtime.state.keyed.KeyedListState;
import org.apache.flink.runtime.state.keyed.KeyedMapState;
import org.apache.flink.runtime.state.keyed.KeyedSortedMapState;
import org.apache.flink.runtime.state.keyed.KeyedState;
import org.apache.flink.runtime.state.keyed.KeyedStateDescriptor;
import org.apache.flink.runtime.state.keyed.KeyedValueState;
import org.apache.flink.runtime.state.subkeyed.SubKeyedListState;
import org.apache.flink.runtime.state.subkeyed.SubKeyedMapState;
import org.apache.flink.runtime.state.subkeyed.SubKeyedSortedMapState;
import org.apache.flink.runtime.state.subkeyed.SubKeyedState;
import org.apache.flink.runtime.state.subkeyed.SubKeyedStateDescriptor;
import org.apache.flink.runtime.state.subkeyed.SubKeyedValueState;
import org.apache.flink.table.dataformat.BaseRow;
import org.apache.flink.table.dataview.StateDataView;
import org.apache.flink.table.dataview.StateListView;
import org.apache.flink.table.dataview.StateMapView;
import org.apache.flink.table.dataview.StateSortedMapView;
import org.apache.flink.table.typeutils.ListViewTypeInfo;
import org.apache.flink.table.typeutils.MapViewTypeInfo;
import org.apache.flink.table.typeutils.SortedMapViewTypeInfo;
/**
* A ExecutionContext contains information about the context in which functions are executed and
* the APIs to create v2 state.
*/
public interface ExecutionContext {
/**
* Creates a keyed state described by the given descriptor.
*
* @param descriptor The descriptor of the keyed state to be created.
* @param Type of the keys in the state.
* @param Type of the values in the state.
* @param Type of the state to be created.
* @return The state described by the given descriptor.
*/
> S getKeyedState(
final KeyedStateDescriptor descriptor) throws Exception;
/**
* Creates a subkeyed state described by the given descriptor.
*
* @param descriptor The descriptor of the subkeyed state to be created.
* @param Type of the keys in the state.
* @param Type of the namespaces in the state.
* @param Type of the values in the state.
* @param Type of the state to be created.
* @return The state described by the given descriptor.
*/
> S getSubKeyedState(
final SubKeyedStateDescriptor descriptor) throws Exception;
/**
* Creates a keyed value state.
* @param descriptor The descriptor defining the properties of the state.
* @param Type of the key
* @param Type of the element in the value state
* @return a keyed value state
*/
KeyedValueState getKeyedValueState(
final ValueStateDescriptor descriptor) throws Exception;
/**
* Creates a keyed list state.
* @param descriptor The descriptor defining the properties of the state.
* @param Type of the key
* @param Type of the elements in the list state
* @return a keyed list state
*/
KeyedListState getKeyedListState(
final ListStateDescriptor descriptor) throws Exception;
/**
* Creates a keyed map state.
* @param descriptor The descriptor defining the properties of the state.
* @param Type of the key
* @param Type of the keys in the map state
* @param Type of the values in the map state
* @return a keyed map state
*/
KeyedMapState getKeyedMapState(
final MapStateDescriptor descriptor) throws Exception;
/**
* Creates a keyed sorted map state.
* @param descriptor The descriptor defining the properties of the state.
* @param Type of the key
* @param Type of the keys in the sorted map state
* @param Type of the values in the sorted map state
* @return a keyed sorted map state
*/
KeyedSortedMapState getKeyedSortedMapState(
final SortedMapStateDescriptor descriptor) throws Exception;
/**
* Creates a subkeyed value state.
* @param descriptor The descriptor defining the properties of the state.
* @param Type of the key
* @param Type of the namespace
* @param Type of the element in the value state
* @return a subkeyed value state
*/
SubKeyedValueState getSubKeyedValueState(
final ValueStateDescriptor descriptor) throws Exception;
/**
* Creates a subkeyed list state.
* @param descriptor The descriptor defining the properties of the state.
* @param Type of the key
* @param Type of the namespace
* @param Type of the elements in the list state
* @return a subkeyed list state
*/
SubKeyedListState getSubKeyedListState(
final ListStateDescriptor descriptor) throws Exception;
/**
* Creates a subkeyed map state.
* @param descriptor The descriptor defining the properties of the state.
* @param Type of the key
* @param Type of the namespace
* @param Type of the keys in the map state
* @param Type of the values in the map state
* @return a subkeyed map state
*/
SubKeyedMapState getSubKeyedMapState(
final MapStateDescriptor descriptor) throws Exception;
/**
* Creates a subkeyed sorted map state.
* @param descriptor The descriptor defining the properties of the state.
* @param Type of the key
* @param Type of the namespace
* @param Type of the keys in the sorted map state
* @param Type of the values in the sorted map state
* @return a subkeyed sorted map state
*/
SubKeyedSortedMapState getSubKeyedSortedMapState(
final SortedMapStateDescriptor descriptor) throws Exception;
/**
* Creates a state map view.
* @param stateName The name of underlying state of the map view
* @param mapViewTypeInfo The type of the map view
* @param hasNamespace whether the state map view works on subkeyed state
* @param Type of the key
* @param Type of the keys in the map state
* @param Type of the values in the map state
* @return a keyed map state
*/
StateMapView getStateMapView(
String stateName, MapViewTypeInfo mapViewTypeInfo, boolean hasNamespace) throws Exception;
/**
* Creates a state map view.
* @param stateName The name of underlying state of the sorted map view
* @param sortedMapViewTypeInfo The type of the sorted map view
* @param Type of the key
* @param Type of the keys in the map state
* @param Type of the values in the map state
* @return a keyed map state
*/
StateSortedMapView getStateSortedMapView(
String stateName, SortedMapViewTypeInfo sortedMapViewTypeInfo, boolean hasNamespace) throws Exception;
/**
* Creates a state list view.
* @param stateName The name of underlying state of the list view
* @param listViewTypeInfo The type of the list view
* @param hasNamespace whether the state list view works on subkeyed state
* @param Type of the key
* @param Type of the elements in the list state
* @return a keyed list state
*/
StateListView getStateListView(
String stateName, ListViewTypeInfo listViewTypeInfo, boolean hasNamespace) throws Exception;
/**
* Registers stateDataView to the context. {@link #setCurrentKey(BaseRow)} will set the
* currentKey to all the registered stateDataViews current key.
*/
void registerStateDataView(StateDataView stateDataView);
/**
* @return the key serializer of state key
*/
TypeSerializer getKeySerializer();
/**
* @return key of the current processed element.
*/
BaseRow currentKey();
/**
* Sets current key.
*/
void setCurrentKey(BaseRow key);
RuntimeContext getRuntimeContext();
}