Documentation ¶
Overview ¶
Package mapping provides a parser for the full bloblang mapping spec.
Index ¶
- func LineAndColOf(input, clip []rune) (line, col int)
- type Assignment
- type AssignmentContext
- type Executor
- func (e *Executor) Annotation() string
- func (e *Executor) AssignmentTargets() []TargetPath
- func (e *Executor) Exec(ctx query.FunctionContext) (any, error)
- func (e *Executor) ExecOnto(ctx query.FunctionContext, onto AssignmentContext) error
- func (e *Executor) MapOnto(part *message.Part, index int, msg Message) (*message.Part, error)
- func (e *Executor) MapPart(index int, msg Message) (*message.Part, error)
- func (e *Executor) Maps() map[string]query.Function
- func (e *Executor) QueryPart(index int, msg Message) (bool, error)
- func (e *Executor) QueryTargets(ctx query.TargetsContext) (query.TargetsContext, []query.TargetPath)
- func (e *Executor) SetMaxMapRecursion(m int)
- func (e *Executor) ToBytes(ctx query.FunctionContext) ([]byte, error)
- func (e *Executor) ToString(ctx query.FunctionContext) (string, error)
- type JSONAssignment
- type Message
- type MetaAssignment
- type Statement
- type TargetPath
- type TargetType
- type VarAssignment
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LineAndColOf ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) QueryPart ¶
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 ¶
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.
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 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 ¶
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 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 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 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(value 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.