Class StateSpecs

java.lang.Object
org.apache.beam.sdk.state.StateSpecs

public class StateSpecs extends Object
Static methods for working with StateSpecs.
  • Method Details

    • value

      public static <T> StateSpec<ValueState<T>> value()
      Create a StateSpec for a single value of type T.

      This method attempts to infer the value coder automatically.

      If the value type has a schema registered, then the schema will be used to encode the values.

      See Also:
    • rowValue

      public static StateSpec<ValueState<Row>> rowValue(Schema schema)
      Create a StateSpec for a row value with the specified schema.
    • value

      public static <T> StateSpec<ValueState<T>> value(Coder<T> valueCoder)
      Identical to value(), but with a coder explicitly supplied.

      If automatic coder inference fails, use this method.

    • combining

      public static <InputT, AccumT, OutputT> StateSpec<CombiningState<InputT,AccumT,OutputT>> combining(Combine.CombineFn<InputT,AccumT,OutputT> combineFn)
      Create a StateSpec for a CombiningState which uses a Combine.CombineFn to automatically merge multiple values of type InputT into a single resulting OutputT.

      This method attempts to infer the accumulator coder automatically.

      See Also:
    • combining

      @Internal public static <InputT, AccumT, OutputT> StateSpec<CombiningState<InputT,AccumT,OutputT>> combining(CombineWithContext.CombineFnWithContext<InputT,AccumT,OutputT> combineFn)
      For internal use only; no backwards compatibility guarantees

      Create a StateSpec for a CombiningState which uses a CombineWithContext.CombineFnWithContext to automatically merge multiple values of type InputT into a single resulting OutputT.

      This method attempts to infer the accumulator coder automatically.

      See Also:
    • combining

      public static <InputT, AccumT, OutputT> StateSpec<CombiningState<InputT,AccumT,OutputT>> combining(Coder<AccumT> accumCoder, Combine.CombineFn<InputT,AccumT,OutputT> combineFn)
      Identical to combining(CombineFn), but with an accumulator coder explicitly supplied.

      If automatic coder inference fails, use this method.

    • combining

      @Internal public static <InputT, AccumT, OutputT> StateSpec<CombiningState<InputT,AccumT,OutputT>> combining(Coder<AccumT> accumCoder, CombineWithContext.CombineFnWithContext<InputT,AccumT,OutputT> combineFn)
      For internal use only; no backwards compatibility guarantees

      Identical to combining(CombineFnWithContext), but with an accumulator coder explicitly supplied.

      If automatic coder inference fails, use this method.

    • bag

      public static <T> StateSpec<BagState<T>> bag()
      Create a StateSpec for a BagState, optimized for adding values frequently and occasionally retrieving all the values that have been added.

      This method attempts to infer the element coder automatically.

      If the element type has a schema registered, then the schema will be used to encode the values.

      See Also:
    • rowBag

      public static StateSpec<BagState<Row>> rowBag(Schema schema)
      Create a StateSpec for a BagState, optimized for adding values frequently and occasionally retrieving all the values that have been added.

      This method is for storing row elements with the given schema.

    • bag

      public static <T> StateSpec<BagState<T>> bag(Coder<T> elemCoder)
      Identical to bag(), but with an element coder explicitly supplied.

      If automatic coder inference fails, use this method.

    • set

      public static <T> StateSpec<SetState<T>> set()
      Create a StateSpec for a SetState, optimized for checking membership.

      This method attempts to infer the element coder automatically.

      If the element type has a schema registered, then the schema will be used to encode the values.

      See Also:
    • rowSet

      public static StateSpec<SetState<Row>> rowSet(Schema schema)
      Create a StateSpec for a SetState, optimized for checking membership.

      This method is for storing row elements with the given schema.

    • set

      public static <T> StateSpec<SetState<T>> set(Coder<T> elemCoder)
      Identical to set(), but with an element coder explicitly supplied.

      If automatic coder inference fails, use this method.

    • map

      public static <K, V> StateSpec<MapState<K,V>> map()
      Create a StateSpec for a MapState, optimized for key lookups and writes.

      This method attempts to infer the key and value coders automatically.

      If the key and value types have schemas registered, then the schemas will be used to encode the elements.

      See Also:
    • rowMap

      public static StateSpec<MapState<Row,Row>> rowMap(Schema keySchema, Schema valueSchema)
      Create a StateSpec for a MapState, optimized for key lookups and writes.

      This method is for storing maps where both the keys and the values are rows with the specified schemas.

      See Also:
    • map

      public static <K, V> StateSpec<MapState<K,V>> map(Coder<K> keyCoder, Coder<V> valueCoder)
      Identical to map(), but with key and value coders explicitly supplied.

      If automatic coder inference fails, use this method.

    • orderedList

      public static <T> StateSpec<OrderedListState<T>> orderedList(Coder<T> elemCoder)
    • rowOrderedList

      public static StateSpec<OrderedListState<Row>> rowOrderedList(Schema valueSchema)
    • multimap

      public static <K, V> StateSpec<MultimapState<K,V>> multimap()
      Create a StateSpec for a MultimapState, optimized for key lookups, key puts, and clear.

      This method attempts to infer the key and value coders automatically.

      If the key and value types have schemas registered, then the schemas will be used to encode the elements.

      See Also:
    • rowMultimap

      public static StateSpec<MultimapState<Row,Row>> rowMultimap(Schema keySchema, Schema valueSchema)
      Create a StateSpec for a MultimapState, optimized for key lookups, key puts, and clear.

      This method is for storing multimaps where both the keys and the values are rows with the specified schemas.

      See Also:
    • multimap

      public static <K, V> StateSpec<MultimapState<K,V>> multimap(Coder<K> keyCoder, Coder<V> valueCoder)
      Identical to multimap(), but with key and value coders explicitly supplied.

      If automatic coder inference fails, use this method.

    • combiningFromInputInternal

      @Internal public static <InputT, AccumT, OutputT> StateSpec<CombiningState<InputT,AccumT,OutputT>> combiningFromInputInternal(Coder<InputT> inputCoder, Combine.CombineFn<InputT,AccumT,OutputT> combineFn)
      For internal use only; no backwards-compatibility guarantees.

      Create a state spec for values that use a Combine.CombineFn to automatically merge multiple InputTs into a single OutputT.

      This determines the Coder<AccumT> from the given Coder<InputT>, and should only be used to initialize static values.

    • watermarkStateInternal

      @Internal public static StateSpec<WatermarkHoldState> watermarkStateInternal(TimestampCombiner timestampCombiner)
      For internal use only; no backwards-compatibility guarantees.

      Create a state spec for a watermark hold.

    • convertToBagSpecInternal

      @Internal public static <InputT, AccumT, OutputT> StateSpec<BagState<AccumT>> convertToBagSpecInternal(StateSpec<CombiningState<InputT,AccumT,OutputT>> combiningSpec)
      For internal use only; no backwards-compatibility guarantees.

      Convert a combining state spec to a bag of accumulators.

    • convertToMapSpecInternal

      @Internal public static <KeyT> StateSpec<MapState<KeyT,Boolean>> convertToMapSpecInternal(StateSpec<SetState<KeyT>> setStateSpec)
      For internal use only; no backwards-compatibility guarantees.

      Convert a set state spec to a map-state spec.

    • convertToMultimapSpecInternal

      @Internal public static <KeyT, ValueT> StateSpec<MultimapState<KeyT,ValueT>> convertToMultimapSpecInternal(StateSpec<MapState<KeyT,ValueT>> spec)
      For internal use only; no backwards-compatibility guarantees.

      Convert a set state spec to a map-state spec.