mapping

package
v4.5.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: MIT Imports: 7 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

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  metaMsg
	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

func (e *Executor) Annotation() string

Annotation returns a string annotation that describes the mapping executor.

func (*Executor) AssignmentTargets

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

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

ExecOnto a provided assignment context.

func (*Executor) MapOnto

func (e *Executor) MapOnto(part *message.Part, index int, msg Message) (*message.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) (*message.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

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

Maps returns any map definitions contained within the mapping.

func (*Executor) QueryPart

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

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) SetMaxMapRecursion

func (e *Executor) SetMaxMapRecursion(m int)

SetMaxMapRecursion configures the maximum recursion allowed for maps, if the execution of this mapping matches this number of recursive map calls the mapping will error out.

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

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

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

func NewJSONAssignment

func NewJSONAssignment(path ...string) *JSONAssignment

NewJSONAssignment creates a new JSON assignment.

func (*JSONAssignment) Apply

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

Apply a value to the target JSON path.

func (*JSONAssignment) Target

func (j *JSONAssignment) Target() TargetPath

Target returns a representation of what the assignment targets.

type Message

type Message interface {
	Get(p int) *message.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

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

func NewMetaAssignment(key *string) *MetaAssignment

NewMetaAssignment creates a new meta assignment.

func (*MetaAssignment) Apply

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

Apply a value to a metadata key.

func (*MetaAssignment) Target

func (m *MetaAssignment) Target() TargetPath

Target returns a representation of what the assignment targets.

type Statement

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

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

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

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

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

type TargetType

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

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

VarAssignment creates a variable and assigns it a value.

func NewVarAssignment

func NewVarAssignment(name string) *VarAssignment

NewVarAssignment creates a new variable assignment.

func (*VarAssignment) Apply

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

Apply a value to a variable.

func (*VarAssignment) Target

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