utils

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTransformerRegistry = NewTransformerRegistry()
View Source
var ErrRowTransformationTimeout = errors.New("row transformation timeout")

Functions

func DefaultSchemaValidator

func DefaultSchemaValidator(
	ctx context.Context, driver *toolkit.Driver, properties *TransformerProperties,
	parameters map[string]*toolkit.StaticParameter) (toolkit.ValidationWarnings, error)

func ValidateSchema

func ValidateSchema(
	table *toolkit.Table, column *toolkit.Column, columnProperties *toolkit.ColumnProperties,
) toolkit.ValidationWarnings

Types

type CancelFunction

type CancelFunction func() error

type CmdTransformerBase

type CmdTransformerBase struct {
	Name                     string
	Cmd                      *exec.Cmd
	ExpectedExitCode         int
	Driver                   *toolkit.Driver
	Api                      toolkit.InteractionApi
	ProcessedLines           int
	RowTransformationTimeout time.Duration

	StdoutReader *bufio.Reader
	StderrReader *bufio.Reader
	StdinWriter  io.Writer
	Cancel       CancelFunction
	// contains filtered or unexported fields
}

func NewCmdTransformerBase

func NewCmdTransformerBase(
	name string,
	expectedExitCode int,
	rowTransformationTimeout time.Duration,
	driver *toolkit.Driver,
	api toolkit.InteractionApi,
) *CmdTransformerBase

func (*CmdTransformerBase) BaseDone

func (ctb *CmdTransformerBase) BaseDone() error

func (*CmdTransformerBase) BaseInit

func (ctb *CmdTransformerBase) BaseInit(executable string, args []string) error

func (*CmdTransformerBase) BaseInitWithContext

func (ctb *CmdTransformerBase) BaseInitWithContext(ctx context.Context, executable string, args []string) error

func (*CmdTransformerBase) ReceiveStderrLine

func (ctb *CmdTransformerBase) ReceiveStderrLine(ctx context.Context) (line []byte, err error)

func (*CmdTransformerBase) ReceiveStdoutLine

func (ctb *CmdTransformerBase) ReceiveStdoutLine(ctx context.Context) (line []byte, err error)

func (*CmdTransformerBase) Transform

func (ctb *CmdTransformerBase) Transform(ctx context.Context, r *toolkit.Record) (*toolkit.Record, error)

type MetaKey added in v0.2.1

type MetaKey string

type NewTransformerFunc

type NewTransformerFunc func(ctx context.Context, driver *toolkit.Driver, parameters map[string]toolkit.Parameterizer) (
	Transformer, toolkit.ValidationWarnings, error,
)

NewTransformerFunc - make new transformer. This function receives Driver for making some steps for validation or anything else. parameters - the map of the parsed parameters, for get an appropriate parameter find it in the map by the Name. All those parameters has been defined in the TransformerDefinition object of the transformer

type SchemaValidationFunc

type SchemaValidationFunc func(ctx context.Context, table *toolkit.Driver, properties *TransformerProperties, parameters map[string]*toolkit.StaticParameter) (toolkit.ValidationWarnings, error)

type Transformer

type Transformer interface {
	Init(ctx context.Context) error
	Done(ctx context.Context) error
	Transform(ctx context.Context, r *toolkit.Record) (*toolkit.Record, error)
	GetAffectedColumns() map[int]string
}

type TransformerContext added in v0.2.0

type TransformerContext struct {
	Transformer       Transformer
	StaticParameters  map[string]*toolkit.StaticParameter
	DynamicParameters map[string]*toolkit.DynamicParameter
	When              *toolkit.WhenCond
}

func (*TransformerContext) EvaluateWhen added in v0.2.1

func (tc *TransformerContext) EvaluateWhen(r *toolkit.Record) (bool, error)

type TransformerDefinition added in v0.2.0

type TransformerDefinition struct {
	Properties      *TransformerProperties         `json:"properties"`
	New             NewTransformerFunc             `json:"-"`
	Parameters      []*toolkit.ParameterDefinition `json:"parameters"`
	SchemaValidator SchemaValidationFunc           `json:"-"`
}

func NewTransformerDefinition added in v0.2.0

func NewTransformerDefinition(
	properties *TransformerProperties, newTransformerFunc NewTransformerFunc,
	parameters ...*toolkit.ParameterDefinition,
) *TransformerDefinition

func (*TransformerDefinition) Instance added in v0.2.0

func (d *TransformerDefinition) Instance(
	ctx context.Context, driver *toolkit.Driver, rawParams map[string]toolkit.ParamsValue, dynamicParameters map[string]*toolkit.DynamicParamValue,
	whenCond string,
) (*TransformerContext, toolkit.ValidationWarnings, error)

func (*TransformerDefinition) SetSchemaValidator added in v0.2.0

type TransformerProperties

type TransformerProperties struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	IsCustom    bool            `json:"is_custom"`
	Meta        map[MetaKey]any `json:"meta"`
}

func NewTransformerProperties

func NewTransformerProperties(
	name, description string,
) *TransformerProperties

func (*TransformerProperties) AddMeta added in v0.2.1

func (tp *TransformerProperties) AddMeta(key MetaKey, value any) *TransformerProperties

func (*TransformerProperties) GetMeta added in v0.2.1

func (tp *TransformerProperties) GetMeta(key MetaKey) (any, bool)

type TransformerRegistry

type TransformerRegistry struct {
	M map[string]*TransformerDefinition
}

func NewTransformerRegistry

func NewTransformerRegistry() *TransformerRegistry

func (*TransformerRegistry) Get

func (*TransformerRegistry) MustRegister

func (tm *TransformerRegistry) MustRegister(definition *TransformerDefinition)

func (*TransformerRegistry) Register

func (tm *TransformerRegistry) Register(definition *TransformerDefinition) error

Jump to

Keyboard shortcuts

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