Documentation ¶
Overview ¶
Package query provides a parser for the right-hand side query part of the bloblang spec. This is useful as a separate package as it is used in isolation within interpolation functions.
Index ¶
- Variables
- func ExecToBytes(fn Function, ctx FunctionContext) []byte
- func ExecToString(fn Function, ctx FunctionContext) string
- func IClone(root interface{}) interface{}
- func IGetBool(v interface{}) (bool, error)
- func IGetInt(v interface{}) (int64, error)
- func IGetNumber(v interface{}) (float64, error)
- func IGetString(v interface{}) (string, error)
- func IIsNull(i interface{}) bool
- func ISanitize(i interface{}) interface{}
- func IToBool(v interface{}) (bool, error)
- func IToBytes(i interface{}) []byte
- func IToNumber(v interface{}) (float64, error)
- func IToString(i interface{}) string
- func ListFunctions() []string
- func ListMethods() []string
- func Parse(input []rune) parser.Result
- func ParseDeprecated(input []rune) parser.Result
- func RegisterFunction(name string, allowDynamicArgs bool, ctor FunctionCtor, checks ...ArgCheckFn) struct{}
- func RegisterMethod(name string, allowDynamicArgs bool, ctor MethodCtor, checks ...ArgCheckFn) struct{}
- type ArgCheckFn
- type Delete
- type ErrRecoverable
- type Function
- type FunctionContext
- type FunctionCtor
- type MessageBatch
- type MethodCtor
- type Nothing
- type TypeError
- type TypeMismatch
- type ValueType
Constants ¶
This section is empty.
Variables ¶
var ErrDivideByZero = errors.New("attempted to divide by zero")
ErrDivideByZero occurs when an arithmetic operator is prevented from dividing a value by zero.
Functions ¶
func ExecToBytes ¶ added in v3.14.0
func ExecToBytes(fn Function, ctx FunctionContext) []byte
ExecToBytes returns a byte slice from a function exection.
func ExecToString ¶ added in v3.14.0
func ExecToString(fn Function, ctx FunctionContext) string
ExecToString returns a string from a function exection.
func IClone ¶ added in v3.13.0
func IClone(root interface{}) interface{}
IClone performs a deep copy of a generic value.
func IGetBool ¶ added in v3.15.0
IGetBool takes a boxed value and attempts to extract a boolean from it.
func IGetInt ¶ added in v3.15.0
IGetInt takes a boxed value and attempts to extract an integer (int64) from it.
func IGetNumber ¶ added in v3.13.0
IGetNumber takes a boxed value and attempts to extract a number (float64) from it.
func IGetString ¶ added in v3.16.0
IGetString takes a boxed value and attempts to return a string value. Returns an error if the value is not a string or byte slice.
func IIsNull ¶ added in v3.13.0
func IIsNull(i interface{}) bool
IIsNull returns whether a bloblang type is null, this includes Delete and Nothing types.
func ISanitize ¶ added in v3.13.0
func ISanitize(i interface{}) interface{}
ISanitize takes a boxed value of any type and attempts to convert it into one of the following types: string, []byte, int64, uint64, float64, bool, []interface{}, map[string]interface{}, Delete, Nothing.
func IToBool ¶ added in v3.16.0
IToBool takes a boxed value and attempts to extract a boolean from it or parse it into a bool.
func IToBytes ¶ added in v3.13.0
func IToBytes(i interface{}) []byte
IToBytes takes a boxed value of any type and attempts to convert it into a byte slice.
func IToNumber ¶ added in v3.16.0
IToNumber takes a boxed value and attempts to extract a number (float64) from it or parse one.
func IToString ¶ added in v3.13.0
func IToString(i interface{}) string
IToString takes a boxed value of any type and attempts to convert it into a string.
func ListFunctions ¶ added in v3.14.0
func ListFunctions() []string
ListFunctions returns a slice of function names, sorted alphabetically.
func ListMethods ¶ added in v3.14.0
func ListMethods() []string
ListMethods returns a slice of method names, sorted alphabetically.
func ParseDeprecated ¶
ParseDeprecated parses an input into a query.Function, but permits deprecated function interpolations. In order to support old functions this parser does not include field literals.
func RegisterFunction ¶ added in v3.13.0
func RegisterFunction(name string, allowDynamicArgs bool, ctor FunctionCtor, checks ...ArgCheckFn) struct{}
RegisterFunction to be accessible from Bloblang queries. Returns an empty struct in order to allow inline calls.
func RegisterMethod ¶ added in v3.13.0
func RegisterMethod(name string, allowDynamicArgs bool, ctor MethodCtor, checks ...ArgCheckFn) struct{}
RegisterMethod to be accessible from Bloblang queries. Returns an empty struct in order to allow inline calls.
Types ¶
type ArgCheckFn ¶ added in v3.13.0
type ArgCheckFn func(args []interface{}) error
ArgCheckFn is an optional argument type checker for a function constructor.
func ExpectAllStringArgs ¶ added in v3.17.0
func ExpectAllStringArgs() ArgCheckFn
ExpectAllStringArgs returns an error if any argument is not a string type (or a byte slice that can be converted).
func ExpectAtLeastOneArg ¶ added in v3.14.0
func ExpectAtLeastOneArg() ArgCheckFn
ExpectAtLeastOneArg returns an error unless >0 arguments are specified.
func ExpectBoolArg ¶ added in v3.15.0
func ExpectBoolArg(i int) ArgCheckFn
ExpectBoolArg returns an error if an argument i is not a boolean type.
func ExpectFloatArg ¶ added in v3.15.0
func ExpectFloatArg(i int) ArgCheckFn
ExpectFloatArg returns an error if an argument i is not a float type.
func ExpectIntArg ¶ added in v3.13.0
func ExpectIntArg(i int) ArgCheckFn
ExpectIntArg returns an error if an argument i is not an integer type.
func ExpectNArgs ¶ added in v3.13.0
func ExpectNArgs(i int) ArgCheckFn
ExpectNArgs returns an error unless exactly N arguments are specified.
func ExpectOneOrZeroArgs ¶ added in v3.13.0
func ExpectOneOrZeroArgs() ArgCheckFn
ExpectOneOrZeroArgs returns an error if more than one arg is specified.
func ExpectStringArg ¶ added in v3.13.0
func ExpectStringArg(i int) ArgCheckFn
ExpectStringArg returns an error if an argument i is not a string type (or a byte slice that can be converted).
type Delete ¶ added in v3.13.0
type Delete *struct{}
Delete is a special type that serializes to `null` when forced but indicates a target should be deleted.
type ErrRecoverable ¶
type ErrRecoverable struct { Recovered interface{} Err error }
ErrRecoverable represents a function execution error that can optionally be recovered into a zero-value.
func (*ErrRecoverable) Error ¶
func (e *ErrRecoverable) Error() string
Error implements the standard error interface.
type Function ¶
type Function interface { // Execute this function for a message of a batch. Exec(ctx FunctionContext) (interface{}, error) }
Function takes a set of contextual parameters and returns the result of the query.
type FunctionContext ¶
type FunctionContext struct { Value *interface{} Maps map[string]Function Vars map[string]interface{} Index int MsgBatch MessageBatch Legacy bool }
FunctionContext provides access to a root message, its index within the batch, and
type FunctionCtor ¶ added in v3.13.0
FunctionCtor constructs a new function from input arguments.
type MessageBatch ¶ added in v3.17.0
MessageBatch is an interface type to be given to a query function, it allows the function to resolve fields and metadata from a Benthos message batch.
type MethodCtor ¶ added in v3.13.0
MethodCtor constructs a new method from a target function and input args.
type Nothing ¶ added in v3.13.0
type Nothing *struct{}
Nothing is a special type that serializes to `null` when forced but indicates a query should be disregarded (and not mapped).
type TypeError ¶ added in v3.16.0
TypeError represents an error where a value of a type was required for a function, method or operator but instead a different type was found.
func NewTypeError ¶ added in v3.16.0
NewTypeError creates a new type error.
type TypeMismatch ¶ added in v3.16.0
TypeMismatch represents an error where two values should be a comparable type but are not.
func NewTypeMismatch ¶ added in v3.16.0
func NewTypeMismatch(left, right interface{}) *TypeMismatch
NewTypeMismatch creates a new type mismatch error.
func (*TypeMismatch) Error ¶ added in v3.16.0
func (t *TypeMismatch) Error() string
Error implements the standard error interface.
type ValueType ¶ added in v3.16.0
type ValueType string
ValueType represents a discrete value type supported by Bloblang queries.
var ( ValueString ValueType = "string" ValueBytes ValueType = "bytes" ValueNumber ValueType = "number" ValueBool ValueType = "bool" ValueArray ValueType = "array" ValueObject ValueType = "object" ValueNull ValueType = "null" ValueDelete ValueType = "delete" ValueNothing ValueType = "nothing" ValueUnknown ValueType = "unknown" )
ValueType variants.