mapping

package
v3.57.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package mapping provides a parser for the full bloblang mapping spec.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LineAndColOf added in v3.25.0

func LineAndColOf(input, clip []rune) (line, col int)

LineAndColOf returns the line and column position of a tailing clip from an input.

Types

type Assignment

type Assignment interface {
	Apply(value interface{}, ctx AssignmentContext) error
	Target() TargetPath
}

Assignment represents a way of assigning a queried value to something within an assignment context. This could be a Benthos message, a variable, a metadata field, etc.

type AssignmentContext

type AssignmentContext struct {
	Vars  map[string]interface{}
	Meta  types.Metadata
	Value *interface{}
}

AssignmentContext contains references to all potential assignment destinations of a given mapping.

type Executor

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

Executor is a parsed bloblang mapping that can be executed on a Benthos message.

func NewExecutor

func NewExecutor(annotation string, input []rune, maps map[string]query.Function, statements ...Statement) *Executor

NewExecutor initialises a new mapping executor from a map of query functions, and a list of assignments to be executed on each mapping. The input parameter is an optional slice pointing to the parsed expression that created the executor.

func (*Executor) Annotation added in v3.43.1

func (e *Executor) Annotation() string

Annotation returns a string annotation that describes the mapping executor.

func (*Executor) AssignmentTargets added in v3.25.0

func (e *Executor) AssignmentTargets() []TargetPath

AssignmentTargets returns a slice of all targets assigned to by statements within the mapping.

func (*Executor) Exec

func (e *Executor) Exec(ctx query.FunctionContext) (interface{}, error)

Exec this function with a context struct.

func (*Executor) ExecOnto added in v3.31.0

func (e *Executor) ExecOnto(ctx query.FunctionContext, onto AssignmentContext) error

ExecOnto a provided assignment context.

func (*Executor) MapOnto added in v3.25.0

func (e *Executor) MapOnto(part types.Part, index int, msg Message) (types.Part, error)

MapOnto maps into an existing message part, where mappings are appended to the message rather than being used to construct a new message.

func (*Executor) MapPart

func (e *Executor) MapPart(index int, msg Message) (types.Part, error)

MapPart executes the bloblang mapping on a particular message index of a batch. The message is parsed as a JSON document in order to provide the mapping context. Returns an error if any stage of the mapping fails to execute.

A resulting mapped message part is returned, unless the mapping results in a query.Delete value, in which case nil is returned and the part should be discarded.

func (*Executor) Maps added in v3.25.0

func (e *Executor) Maps() map[string]query.Function

Maps returns any map definitions contained within the mapping.

func (*Executor) QueryPart added in v3.28.0

func (e *Executor) QueryPart(index int, msg Message) (bool, error)

QueryPart executes the bloblang mapping on a particular message index of a batch. The message is parsed as a JSON document in order to provide the mapping context. The result of the mapping is expected to be a boolean value at the root, this is not the case, or if any stage of the mapping fails to execute, an error is returned.

func (*Executor) QueryTargets added in v3.25.0

func (e *Executor) QueryTargets(ctx query.TargetsContext) (query.TargetsContext, []query.TargetPath)

QueryTargets returns a slice of all targets referenced by queries within the mapping.

func (*Executor) ToBytes

func (e *Executor) ToBytes(ctx query.FunctionContext) []byte

ToBytes executes this function for a message of a batch and returns the result marshalled into a byte slice.

func (*Executor) ToString

func (e *Executor) ToString(ctx query.FunctionContext) string

ToString executes this function for a message of a batch and returns the result marshalled into a string.

type JSONAssignment added in v3.25.0

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

JSONAssignment creates a path within the structured message and assigns it a value.

func NewJSONAssignment added in v3.25.0

func NewJSONAssignment(path ...string) *JSONAssignment

NewJSONAssignment creates a new JSON assignment.

func (*JSONAssignment) Apply added in v3.25.0

func (j *JSONAssignment) Apply(value interface{}, ctx AssignmentContext) error

Apply a value to the target JSON path.

func (*JSONAssignment) Target added in v3.25.0

func (j *JSONAssignment) Target() TargetPath

Target returns a representation of what the assignment targets.

type Message

type Message interface {
	Get(p int) types.Part
	Len() int
}

Message is an interface type to be given to a query function, it allows the function to resolve fields and metadata from a message.

type MetaAssignment added in v3.25.0

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

MetaAssignment assigns a value to a metadata key of a message. If the key is omitted and the value is an object then the metadata of the message is reset to the contents of the value.

func NewMetaAssignment added in v3.25.0

func NewMetaAssignment(key *string) *MetaAssignment

NewMetaAssignment creates a new meta assignment.

func (*MetaAssignment) Apply added in v3.25.0

func (m *MetaAssignment) Apply(value interface{}, ctx AssignmentContext) error

Apply a value to a metadata key.

func (*MetaAssignment) Target added in v3.25.0

func (m *MetaAssignment) Target() TargetPath

Target returns a representation of what the assignment targets.

type Statement added in v3.25.0

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

Statement describes an isolated mapping statement, where the result of a query function is to be mapped according to an Assignment.

func NewStatement added in v3.25.0

func NewStatement(input []rune, assignment Assignment, query query.Function) Statement

NewStatement initialises a new mapping statement from an Assignment and query.Function. The input parameter is an optional slice pointing to the parsed expression that created the statement.

type TargetPath added in v3.25.0

type TargetPath struct {
	Type TargetType
	Path []string
}

TargetPath represents a target type and segmented path that a query function references. An empty path indicates the root of the type is targetted.

func NewTargetPath added in v3.25.0

func NewTargetPath(t TargetType, path ...string) TargetPath

NewTargetPath constructs a new target path from a type and zero or more path segments.

type TargetType added in v3.25.0

type TargetType int

TargetType represents a mapping target type, which is a destination for a query result to be mapped into a message.

const (
	TargetMetadata TargetType = iota
	TargetValue
	TargetVariable
)

TargetTypes

type VarAssignment added in v3.25.0

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

VarAssignment creates a variable and assigns it a value.

func NewVarAssignment added in v3.25.0

func NewVarAssignment(name string) *VarAssignment

NewVarAssignment creates a new variable assignment.

func (*VarAssignment) Apply added in v3.25.0

func (v *VarAssignment) Apply(value interface{}, ctx AssignmentContext) error

Apply a value to a variable.

func (*VarAssignment) Target added in v3.25.0

func (v *VarAssignment) Target() TargetPath

Target returns a representation of what the assignment targets.

Jump to

Keyboard shortcuts

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