mapping

package
v4.26.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 any, 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]any
	Meta  metaMsg
	Value *any
}

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) (any, 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 value.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, error)

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, error)

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(val any, 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(val any, 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 RootLevelIfStatement added in v4.26.0

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

func NewRootLevelIfStatement added in v4.26.0

func NewRootLevelIfStatement(input []rune) *RootLevelIfStatement

func (*RootLevelIfStatement) Add added in v4.26.0

func (r *RootLevelIfStatement) Add(query query.Function, statements ...Statement) *RootLevelIfStatement

func (*RootLevelIfStatement) AssignmentTargets added in v4.26.0

func (r *RootLevelIfStatement) AssignmentTargets() []TargetPath

func (*RootLevelIfStatement) Execute added in v4.26.0

func (r *RootLevelIfStatement) Execute(fnContext query.FunctionContext, asContext AssignmentContext) error

func (*RootLevelIfStatement) Input added in v4.26.0

func (r *RootLevelIfStatement) Input() []rune

func (*RootLevelIfStatement) QueryTargets added in v4.26.0

type SingleStatement added in v4.26.0

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

func NewSingleStatement added in v4.26.0

func NewSingleStatement(input []rune, assignment Assignment, query query.Function) *SingleStatement

func (*SingleStatement) AssignmentTargets added in v4.26.0

func (s *SingleStatement) AssignmentTargets() []TargetPath

func (*SingleStatement) Execute added in v4.26.0

func (s *SingleStatement) Execute(fnContext query.FunctionContext, asContext AssignmentContext) error

func (*SingleStatement) Input added in v4.26.0

func (s *SingleStatement) Input() []rune

func (*SingleStatement) QueryTargets added in v4.26.0

type Statement

type Statement interface {
	QueryTargets(ctx query.TargetsContext) (query.TargetsContext, []query.TargetPath)
	AssignmentTargets() []TargetPath
	Input() []rune
	Execute(fnContext query.FunctionContext, asContext AssignmentContext) error
}

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 targeted.

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(val any, 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