pystate

package
v0.0.0-...-2255a89 Latest Latest
Warning

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

Go to latest
Published: May 23, 2016 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyTerminated = errors.New("pystate is already terminated")

ErrAlreadyTerminated is occurred when called some python method after the SharedState is terminated.

Functions

func CallMethod

func CallMethod(ctx *core.Context, stateName, funcName string, dt ...data.Value) (
	data.Value, error)

CallMethod calls an instance method and returns its value.

func MustRegisterPyUDF

func MustRegisterPyUDF(udfName string, modulePath string, moduleName string,
	funcName string)

MustRegisterPyUDF is like MustRegisterGlobalUDF for Python module method.

func MustRegisterPyUDSCreator

func MustRegisterPyUDSCreator(typeName string, modulePath string,
	moduleName string, className string, writeMethodName string)

MustRegisterPyUDSCreator is like MustRegisterGlobalUDSCreator for Python instance, just an alias of pystate.

func New

func New(baseParams *BaseParams, params data.Map) (core.SharedState, error)

New creates `core.SharedState` for python constructor.

Types

type Base

type Base struct {
	// contains filtered or unexported fields
}

Base is a wrapper of a UDS written in Python. It has common implementations that can be shared with State, WritableState, and other wrappers. Base doesn't acquire lock and the caller should provide concurrency control over them. Each method describes what kind of lock it requires.

func LoadBase

func LoadBase(ctx *core.Context, r io.Reader, params data.Map) (*Base, error)

LoadBase loads a new Base state.

func NewBase

func NewBase(baseParams *BaseParams, params data.Map) (*Base, error)

NewBase creates a new Base state.

func (*Base) Call

func (s *Base) Call(funcName string, dt ...data.Value) (data.Value, error)

Call calls an instance method and returns its value.

Although this call may modify the state of the Python UDS, it doesn't change this Base Go instance itself. Therefore, this method requires read-lock.

func (*Base) CheckTermination

func (s *Base) CheckTermination() error

CheckTermination checks if the Base is already terminated. It returns nil if the Base is still working. It returns ErrAlreadyTerminated if the Base has already been terminated.

This method requires read-lock.

func (*Base) Load

func (s *Base) Load(ctx *core.Context, r io.Reader, params data.Map) error

Load loads the model of the state. It reads the header of the saved file and calls 'load' static method of the Python UDS. 'load' static method creates a new instance of the Python UDS.

This method requires write-lock.

func (*Base) Save

func (s *Base) Save(ctx *core.Context, w io.Writer, params data.Map) error

Save saves the model of the state. It saves its internal state and also calls 'save' method of the Python UDS. The Python UDS must save all the information necessary to reconstruct the current state including parameters passed by CREATE STATE statement.

This method requires read-Lock.

func (*Base) Terminate

func (s *Base) Terminate(ctx *core.Context) error

Terminate terminates the state.

This method requires write-lock.

func (*Base) Write

func (s *Base) Write(ctx *core.Context, t *core.Tuple) error

Write calls "write" function of the Python UDS.

Although this write may modify the state of the Python UDS, it doesn't change this Base Go instance itself. Therefore, RLock is fine here.

type BaseLoadParams

type BaseLoadParams struct {
}

BaseLoadParams has parameters for Base given in SET clause of LOAD STATE statement.

func ExtractBaseLoadParams

func ExtractBaseLoadParams(params data.Map, removeBaseKeys bool) (*BaseLoadParams, error)

ExtractBaseLoadParams extracts parameters for Base from parameters given in a SET clause of LOAD STATE statement. If removeBaseKeys is true, this function removes base parameters from params and only other parameters remain in the map when this function succeeds. If this function fails, all parameters including base parameters remain in the map.

type BaseParams

type BaseParams struct {
	// ModulePath is a path at where the target Python module is located.
	// This parameter can be set as "module_path" in a WITH clause. This is
	// a required parameter.
	ModulePath string `codec:"module_path"`

	// ModuleName is a name of a Python module to be loaded. This parameter
	// can be set as "module_name" in a WITH clause. This is a required parameter.
	ModuleName string `codec:"module_name"`

	// ClassName is a name of a class in the Python module to be loaded. This
	// parameter can be set as "class_name" in a WITH clause. This is a required
	// parameter.
	ClassName string `codec:"class_name"`

	// WriteMethodName is a name of a method which handles Write calls, which
	// is mostly done by 'uds' Sink. When this parameter is specified, a UDS
	// will be writable. Otherwise, it doesn't support Write.
	WriteMethodName string `codec:"write_method"`
}

BaseParams has parameters for Base given in WITH clause of CREATE STATE statement.

func ExtractBaseParams

func ExtractBaseParams(params data.Map, removeBaseKeys bool) (*BaseParams, error)

ExtractBaseParams extracts parameters for Base from parameters given in a WITH clause of a CREATE STATE statement. If removeBaseKeys is true, this function removes base parameters from params and only other parameters remain in the map when this function succeeds. If this function fails, all parameters including base parameters remain in the map.

type Creator

type Creator struct {
}

Creator is used by BQL to create state as a UDS.

func (*Creator) CreateState

func (c *Creator) CreateState(ctx *core.Context, params data.Map) (
	core.SharedState, error)

CreateState creates `core.SharedState` of a UDS written in Python. If params has parameters other than the ones defined in BaseParams, they will be directly passed to 'create' static method of the Python UDS.

func (*Creator) LoadState

func (c *Creator) LoadState(ctx *core.Context, r io.Reader, params data.Map) (
	core.SharedState, error)

LoadState loads saved state and creates a new instance from it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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