state

package
v3.0.0-...-7ba4d6b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 3 Imported by: 0

Documentation

Overview

Package state contains structs for reading and manipulating pipeline state.

Index

Constants

View Source
const (
	// TransactionTypeSet is the set transaction type
	TransactionTypeSet TransactionTypeEnum = 0
	// TransactionTypeClear is the set transaction type
	TransactionTypeClear TransactionTypeEnum = 1
	// TransactionTypeAppend is the append transaction type
	TransactionTypeAppend TransactionTypeEnum = 2
	// TypeValue represents a value state
	TypeValue TypeEnum = 0
	// TypeBag represents a bag state
	TypeBag TypeEnum = 1
	// TypeCombining represents a combining state
	TypeCombining TypeEnum = 2
	// TypeMap represents a map state
	TypeMap TypeEnum = 3
	// TypeSet represents a set state
	TypeSet TypeEnum = 4
)

Variables

View Source
var (
	// ProviderType is the state provider type
	ProviderType = reflect.TypeOf((*Provider)(nil)).Elem()
)

Functions

This section is empty.

Types

type Bag

type Bag[T any] struct {
	Key string
}

Bag is used to read and write global pipeline state representing a collection of values. Key represents the key used to lookup this state.

func MakeBagState

func MakeBagState[T any](k string) Bag[T]

MakeBagState is a factory function to create an instance of BagState with the given key.

func (*Bag[T]) Add

func (s *Bag[T]) Add(p Provider, val T) error

Add is used to write append to the bag pipeline state.

func (*Bag[T]) Clear

func (s *Bag[T]) Clear(p Provider) error

Clear is used to clear this instance of global pipeline state representing a bag.

func (Bag[T]) CoderType

func (s Bag[T]) CoderType() reflect.Type

CoderType returns the type of the bag state which should be used for a coder.

func (Bag[T]) KeyCoderType

func (s Bag[T]) KeyCoderType() reflect.Type

KeyCoderType returns nil since Bag types aren't keyed.

func (*Bag[T]) Read

func (s *Bag[T]) Read(p Provider) ([]T, bool, error)

Read is used to read this instance of global pipeline state representing a bag. When a value is not found, returns an empty list and false.

func (Bag[T]) StateKey

func (s Bag[T]) StateKey() string

StateKey returns the key for this pipeline state entry.

func (Bag[T]) StateType

func (s Bag[T]) StateType() TypeEnum

StateType returns the type of the state (in this case always Bag).

type Combining

type Combining[T1, T2, T3 any] struct {
	Key string
	// contains filtered or unexported fields
}

Combining is used to read and write global pipeline state representing a single combined value. It uses 3 generic values, [T1, T2, T3], to represent the accumulator, input, and output types respectively. Key represents the key used to lookup this state.

func MakeCombiningState

func MakeCombiningState[T1, T2, T3 any](k string, combiner any) Combining[T1, T2, T3]

MakeCombiningState is a factory function to create an instance of Combining state with the given key and combiner when the combiner may have different types for its accumulator, input, and output. Takes 3 generic constraints [T1, T2, T3 any] representing the accumulator/input/output types respectively. If no accumulator or output types are defined, use the input type.

func (*Combining[T1, T2, T3]) Add

func (s *Combining[T1, T2, T3]) Add(p Provider, val T2) error

Add is used to write add an element to the combining pipeline state.

func (*Combining[T1, T2, T3]) Clear

func (s *Combining[T1, T2, T3]) Clear(p Provider) error

Clear is used to clear this instance of global pipeline state representing a combiner.

func (Combining[T1, T2, T3]) CoderType

func (s Combining[T1, T2, T3]) CoderType() reflect.Type

CoderType returns the type of the bag state which should be used for a coder.

func (Combining[T1, T2, T3]) GetCombineFn

func (s Combining[T1, T2, T3]) GetCombineFn() any

GetCombineFn returns this state instance's CombineFn

func (Combining[T1, T2, T3]) KeyCoderType

func (s Combining[T1, T2, T3]) KeyCoderType() reflect.Type

KeyCoderType returns nil since combining state types aren't keyed.

func (*Combining[T1, T2, T3]) Read

func (s *Combining[T1, T2, T3]) Read(p Provider) (T3, bool, error)

Read is used to read this instance of global pipeline state representing a combiner. When a value is not found, returns an empty list and false.

func (Combining[T1, T2, T3]) StateKey

func (s Combining[T1, T2, T3]) StateKey() string

StateKey returns the key for this pipeline state entry.

func (Combining[T1, T2, T3]) StateType

func (s Combining[T1, T2, T3]) StateType() TypeEnum

StateType returns the type of the state (in this case always Bag).

type CombiningPipelineState

type CombiningPipelineState interface {
	GetCombineFn() any
}

CombiningPipelineState is an interface representing combining pipeline state. It is primarily meant for Beam packages to use and is probably not useful for most pipeline authors.

type Map

type Map[K comparable, V any] struct {
	Key string
}

Map is used to read and write global pipeline state representing a map. Key represents the key used to lookup this state (not the key of map entries).

func MakeMapState

func MakeMapState[K comparable, V any](k string) Map[K, V]

MakeMapState is a factory function to create an instance of MapState with the given key.

func (*Map[K, V]) Clear

func (s *Map[K, V]) Clear(p Provider) error

Clear deletes all entries from this instance of map state.

func (Map[K, V]) CoderType

func (s Map[K, V]) CoderType() reflect.Type

CoderType returns the type of the value state which should be used for a coder for map values.

func (*Map[K, V]) Get

func (s *Map[K, V]) Get(p Provider, key K) (V, bool, error)

Get is used to read a value given a key. When a value is not found, returns the 0 value and false.

func (Map[K, V]) KeyCoderType

func (s Map[K, V]) KeyCoderType() reflect.Type

KeyCoderType returns the type of the value state which should be used for a coder for map keys.

func (*Map[K, V]) Keys

func (s *Map[K, V]) Keys(p Provider) ([]K, bool, error)

Keys is used to read the keys of this map state. When a value is not found, returns an empty list and false.

func (*Map[K, V]) Put

func (s *Map[K, V]) Put(p Provider, key K, val V) error

Put is used to write a key/value pair to this instance of global map state.

func (*Map[K, V]) Remove

func (s *Map[K, V]) Remove(p Provider, key K) error

Remove deletes an entry from this instance of map state.

func (Map[K, V]) StateKey

func (s Map[K, V]) StateKey() string

StateKey returns the key for this pipeline state entry.

func (Map[K, V]) StateType

func (s Map[K, V]) StateType() TypeEnum

StateType returns the type of the state (in this case always Map).

type PipelineState

type PipelineState interface {
	StateKey() string
	KeyCoderType() reflect.Type
	CoderType() reflect.Type
	StateType() TypeEnum
}

PipelineState is an interface representing different kinds of PipelineState (currently just state.Value). It is primarily meant for Beam packages to use and is probably not useful for most pipeline authors.

type Provider

type Provider interface {
	ReadValueState(id string) (any, []Transaction, error)
	WriteValueState(val Transaction) error
	ClearValueState(val Transaction) error
	ReadBagState(id string) ([]any, []Transaction, error)
	WriteBagState(val Transaction) error
	ClearBagState(val Transaction) error
	CreateAccumulatorFn(userStateID string) reflectx.Func
	AddInputFn(userStateID string) reflectx.Func
	MergeAccumulatorsFn(userStateID string) reflectx.Func
	ExtractOutputFn(userStateID string) reflectx.Func
	ReadMapStateValue(userStateID string, key any) (any, []Transaction, error)
	ReadMapStateKeys(userStateID string) ([]any, []Transaction, error)
	WriteMapState(val Transaction) error
	ClearMapStateKey(val Transaction) error
	ClearMapState(val Transaction) error
}

Provider represents the DoFn parameter used to get and manipulate pipeline state stored as key value pairs (https://beam.apache.org/documentation/programming-guide/#state-and-timers). This should not be manipulated directly. Instead it should be used as a parameter to functions on State objects like state.Value.

type Set

type Set[K comparable] struct {
	Key string
}

Set is used to read and write global pipeline state representing a Set. Key represents the key used to lookup this state (not the key of Set entries).

func MakeSetState

func MakeSetState[K comparable](k string) Set[K]

MakeSetState is a factory function to create an instance of SetState with the given key.

func (*Set[K]) Add

func (s *Set[K]) Add(p Provider, key K) error

Add is used to write a key to this instance of global Set state.

func (Set[K]) Clear

func (s Set[K]) Clear(p Provider) error

Clear deletes all entries from this instance of set state.

func (Set[K]) CoderType

func (s Set[K]) CoderType() reflect.Type

CoderType returns the type of the coder used for values, in this case nil since there are no values associated with a set.

func (*Set[K]) Contains

func (s *Set[K]) Contains(p Provider, key K) (bool, error)

Contains is used to determine if a given a key exists in the set.

func (Set[K]) KeyCoderType

func (s Set[K]) KeyCoderType() reflect.Type

KeyCoderType returns the type of the value state which should be used for a coder for set keys.

func (*Set[K]) Keys

func (s *Set[K]) Keys(p Provider) ([]K, bool, error)

Keys is used to read the keys of this set state. When a value is not found, returns an empty list and false.

func (Set[K]) Remove

func (s Set[K]) Remove(p Provider, key K) error

Remove deletes an entry from this instance of set state.

func (Set[K]) StateKey

func (s Set[K]) StateKey() string

StateKey returns the key for this pipeline state entry.

func (Set[K]) StateType

func (s Set[K]) StateType() TypeEnum

StateType returns the type of the state (in this case always Set).

type Transaction

type Transaction struct {
	Key    string
	Type   TransactionTypeEnum
	MapKey any
	Val    any
}

Transaction is used to represent a pending state transaction. This should not be manipulated directly; it is primarily used for implementations of the Provider interface to talk to the various State objects.

type TransactionTypeEnum

type TransactionTypeEnum int32

TransactionTypeEnum represents the type of state transaction (e.g. set, clear)

type TypeEnum

type TypeEnum int32

TypeEnum represents the type of a state instance (e.g. value, bag, etc...)

type Value

type Value[T any] struct {
	Key string
}

Value is used to read and write global pipeline state representing a single value. Key represents the key used to lookup this state.

func MakeValueState

func MakeValueState[T any](k string) Value[T]

MakeValueState is a factory function to create an instance of ValueState with the given key.

func (*Value[T]) Clear

func (s *Value[T]) Clear(p Provider) error

Clear is used to clear this instance of global pipeline state representing a single value.

func (Value[T]) CoderType

func (s Value[T]) CoderType() reflect.Type

CoderType returns the type of the value state which should be used for a coder.

func (Value[T]) KeyCoderType

func (s Value[T]) KeyCoderType() reflect.Type

KeyCoderType returns nil since Value types aren't keyed.

func (*Value[T]) Read

func (s *Value[T]) Read(p Provider) (T, bool, error)

Read is used to read this instance of global pipeline state representing a single value. When a value is not found, returns the 0 value and false.

func (Value[T]) StateKey

func (s Value[T]) StateKey() string

StateKey returns the key for this pipeline state entry.

func (Value[T]) StateType

func (s Value[T]) StateType() TypeEnum

StateType returns the type of the state (in this case always Value).

func (*Value[T]) Write

func (s *Value[T]) Write(p Provider, val T) error

Write is used to write this instance of global pipeline state representing a single value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL