expression

package
v0.16.0-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2020 License: Apache-2.0 Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ValueTypeStrings = map[ValueType]string{
	ValueTypeUnspecified:   "<<invalid>>",
	ValueTypeString:        "string",
	ValueTypeSignedInt8:    "int8",
	ValueTypeSignedInt16:   "int16",
	ValueTypeSignedInt32:   "int32",
	ValueTypeSignedInt64:   "int64",
	ValueTypeUnsignedInt8:  "uint8",
	ValueTypeUnsignedInt16: "uint16",
	ValueTypeUnsignedInt32: "uint32",
	ValueTypeUnsignedInt64: "uint64",
	ValueTypeBool:          "bool",
	ValueTypeDouble:        "float64",
	ValueTypeTimestamp:     "uint64",
}

ValueTypeStrings is a mapping of value type constants to human-readble string representations

Functions

func BitwiseAnd

func BitwiseAnd(lhs, rhs *telemetryAPI.Expression) *telemetryAPI.Expression

BitwiseAnd creates a new BINARY_AND binary Expression node.

func Equal

Equal creates a new EQ binary Expression node.

func GreaterThan

func GreaterThan(lhs, rhs *telemetryAPI.Expression) *telemetryAPI.Expression

GreaterThan creates a new GT binary expression node.

func GreaterThanEqualTo

func GreaterThanEqualTo(lhs, rhs *telemetryAPI.Expression) *telemetryAPI.Expression

GreaterThanEqualTo creates a new GE binary expression node.

func Identifier

func Identifier(name string) *telemetryAPI.Expression

Identifier creates a new IDENTIFIER Expression node.

func IsNotNull

func IsNotNull(operand *telemetryAPI.Expression) *telemetryAPI.Expression

IsNotNull creates a new IS_NOT_NULL unary Expression node

func IsNull

IsNull creates a new IS_NULL unary Expression node

func IsValueTrue

func IsValueTrue(i interface{}) bool

IsValueTrue determines whether a value's truth value is true or false. Strings are true if they contain one or more characters. Any numeric type is true if it is non-zero.

func LessThan

func LessThan(lhs, rhs *telemetryAPI.Expression) *telemetryAPI.Expression

LessThan creates a new LT binary Expression node.

func LessThanEqualTo

func LessThanEqualTo(lhs, rhs *telemetryAPI.Expression) *telemetryAPI.Expression

LessThanEqualTo creates a new LE binary Expression node.

func Like

Like creates a new LIKE binary Expression node.

func LogicalAnd

func LogicalAnd(lhs, rhs *telemetryAPI.Expression) *telemetryAPI.Expression

LogicalAnd creates a new LOGICAL_AND binary Expression node. If either lhs or rhs is nil, the other will be returned

func LogicalOr

func LogicalOr(lhs, rhs *telemetryAPI.Expression) *telemetryAPI.Expression

LogicalOr creates a new LOGICAL_OR binary Expression node. If either lhs or rhs is nil, the other will be returned

func NewValue

func NewValue(i interface{}) *telemetryAPI.Value

NewValue creates a new Value instance from a native Go type. If a Go type is used that does not have a Value equivalent, the return will be nil.

func NotEqual

func NotEqual(lhs, rhs *telemetryAPI.Expression) *telemetryAPI.Expression

NotEqual creates a new NE binary Expression node.

func Value

func Value(i interface{}) *telemetryAPI.Expression

Value creates a new VALUE Expression node.

Types

type Expression

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

Expression is a wrapper around expressions around the API. It may contain internal information that is used to better support the raw representation.

func ConvertExpression

func ConvertExpression(
	tree *telemetryAPI.Expression,
	types FieldTypeMap,
) (*Expression, error)

ConvertExpression creates a new Expression from a telemetry API expression. If types is not nil, the types are bound to the expression during conversion. Otherwise types must be bound later before evaluation.

func Parse

func Parse(
	r io.Reader,
	mode ParseMode,
	types FieldTypeMap,
) (*Expression, error)

Parse parses an expression from anything implementing the io.Reader interface. The input is always parsed as UTF-8 and does not allow embedded NUL runes.

func ParseBytes

func ParseBytes(
	input []byte,
	mode ParseMode,
	types FieldTypeMap,
) (*Expression, error)

ParseBytes parses an expression from a byte array. The input is always parsed as UTF-8 and does not allow embedded NUL runes.

func ParseString

func ParseString(
	s string,
	mode ParseMode,
	types FieldTypeMap,
) (*Expression, error)

ParseString parses an expression from a string. The input is always parsed as UTF-8 and does not allow embedded NUL runes.

func (*Expression) BindTypes

func (expr *Expression) BindTypes(types FieldTypeMap) error

BindTypes binds field type information to an expression. Binding validates that the expression conforms to the type information being bound. Normally type information is bound during creation of the expression, but there are cases where that may not be possible, and so binding may be deferred to a later time. Type information must be bound before an expression can be evaluated.

func (*Expression) Evaluate

func (expr *Expression) Evaluate(valueGetter FieldValueGetter) (interface{}, error)

Evaluate evaluates an expression using the specified type and value information, and returns the result of that evaluation or an error. Any identifier not present in the types map is considered to be an undefined field and any reference to it is an error. Any identifier present in the types map, but not present in the values map is considered to be NULL; all comparisons against NULL will always evaluate FALSE.

func (*Expression) KernelFilterString

func (expr *Expression) KernelFilterString() string

KernelFilterString returns a string representation of an expression that is suitable for setting a kernel perf_event filter. If the expression is not suitable for use as a kernel filter, the return will be the empty string.

func (*Expression) String

func (expr *Expression) String() string

Return the string representation of an expression.

func (*Expression) ValidateKernelFilter

func (expr *Expression) ValidateKernelFilter() error

ValidateKernelFilter determines whether an expression can be represented as a kernel filter string. If the result is nil, the kernel will most likely accept the expression as a filter. No check is done on the number of predicates in the expression, and some kernel versions do not support bitwise-and; however, this validator will accept bitwise-and because most do. Kernel limits on the number of predicates can vary, so it's not checked. If an expression passes this validation, it is not guaranteed that a given running kernel will absolutely accept it.

type FieldNotSet

type FieldNotSet struct {
	// Name is the name of the field that is not set.
	Name string
}

FieldNotSet is an error type that can be returned by a FieldValueGetter method when the field is not set, in which case the evaluator will treat the value is NULL.

func (FieldNotSet) Error

func (fns FieldNotSet) Error() string

type FieldTypeMap

type FieldTypeMap map[string]ValueType

FieldTypeMap is a mapping of types for field names/identifiers

type FieldTypeMismatch

type FieldTypeMismatch struct {
	// Name is the name of the field that has a type mismatch.
	Name string

	// ExpectedType is the type that was requested.
	ExpectedType ValueType

	// ActualType is the type that was present.
	ActualType ValueType
}

FieldTypeMismatch is an error type that can be returned by a FieldValueGetter method when the field is set, but its value type is not what is requested.

func (FieldTypeMismatch) Error

func (ftm FieldTypeMismatch) Error() string

type FieldValueGetter

type FieldValueGetter interface {
	GetString(name string) (string, error)
	GetSignedInt8(name string) (int8, error)
	GetSignedInt16(name string) (int16, error)
	GetSignedInt32(name string) (int32, error)
	GetSignedInt64(name string) (int64, error)
	GetUnsignedInt8(name string) (uint8, error)
	GetUnsignedInt16(name string) (uint16, error)
	GetUnsignedInt32(name string) (uint32, error)
	GetUnsignedInt64(name string) (uint64, error)
	GetBool(name string) (bool, error)
	GetDouble(name string) (float64, error)
	GetTimestamp(name string) (time.Time, error)
}

FieldValueGetter is an interface that can be implemented to allow for customizing how expression evaluation retrieves values for field references on demand.

type FieldValueMap

type FieldValueMap map[string]interface{}

FieldValueMap is a mapping of values for field names/identifiers.

func (FieldValueMap) GetBool

func (m FieldValueMap) GetBool(name string) (v bool, err error)

GetBool returns the bool value set for the requested field name.

func (FieldValueMap) GetDouble

func (m FieldValueMap) GetDouble(name string) (v float64, err error)

GetDouble returns the double value set for the requested field name.

func (FieldValueMap) GetSignedInt16

func (m FieldValueMap) GetSignedInt16(name string) (v int16, err error)

GetSignedInt16 returns the signed 16-bit integer value set for the requested field name.

func (FieldValueMap) GetSignedInt32

func (m FieldValueMap) GetSignedInt32(name string) (v int32, err error)

GetSignedInt32 returns the signed 32-bit integer value set for the requested field name.

func (FieldValueMap) GetSignedInt64

func (m FieldValueMap) GetSignedInt64(name string) (v int64, err error)

GetSignedInt64 returns the signed 64-bit integer value set for the requested field name.

func (FieldValueMap) GetSignedInt8

func (m FieldValueMap) GetSignedInt8(name string) (v int8, err error)

GetSignedInt8 returns the signed 8-bit integer value set for the requested field name.

func (FieldValueMap) GetString

func (m FieldValueMap) GetString(name string) (v string, err error)

GetString returns the string value set for the requested field name.

func (FieldValueMap) GetTimestamp

func (m FieldValueMap) GetTimestamp(name string) (v time.Time, err error)

GetTimestamp returns the timestamp value set for the requested field name.

func (FieldValueMap) GetUnsignedInt16

func (m FieldValueMap) GetUnsignedInt16(name string) (v uint16, err error)

GetUnsignedInt16 returns the unsigned 16-bit integer value set for the requested field name.

func (FieldValueMap) GetUnsignedInt32

func (m FieldValueMap) GetUnsignedInt32(name string) (v uint32, err error)

GetUnsignedInt32 returns the unsigned 32-bit integer value set for the requested field name.

func (FieldValueMap) GetUnsignedInt64

func (m FieldValueMap) GetUnsignedInt64(name string) (v uint64, err error)

GetUnsignedInt64 returns the unsigned 64-bit integer value set for the requested field name.

func (FieldValueMap) GetUnsignedInt8

func (m FieldValueMap) GetUnsignedInt8(name string) (v uint8, err error)

GetUnsignedInt8 returns the unsigned 8-bit integer value set for the requested field name.

type ParseMode

type ParseMode int

ParseMode is a type representing a parser mode of operation

const (
	// ParseModeInvalid is an invalid parser mode.
	ParseModeInvalid ParseMode = iota

	// ParseModeKernelFilter instructs the parser to parse its input as a
	// Linux kernel tracing filter. The parser is a bit more strict in some
	// respects than the kernel's own parser. Specifically, it requires
	// that string literals are always enclosed in quotation marks. It is
	// also a bit more lax in some respects, although in some places where
	// it allows functionality that the kernel does not (e.g., quotation
	// marks in a string), kernel filter validation may fail.
	ParseModeKernelFilter
)

type ValueType

type ValueType int

ValueType represents the type of a value in an expression

const (
	// ValueTypeUnspecified is an unspecified type
	ValueTypeUnspecified ValueType = iota

	// ValueTypeString is a string
	ValueTypeString

	// ValueTypeSignedInt8 is a signed 8-bit integer
	ValueTypeSignedInt8
	// ValueTypeSignedInt16 is a signed 16-bit integer
	ValueTypeSignedInt16
	// ValueTypeSignedInt32 is a signed 32-bit integer
	ValueTypeSignedInt32
	// ValueTypeSignedInt64 is a signed 64-bit integer
	ValueTypeSignedInt64
	// ValueTypeUnsignedInt8 is an unisnged 8-bit integer
	ValueTypeUnsignedInt8
	// ValueTypeUnsignedInt16 is an unsigned 16-bit integer
	ValueTypeUnsignedInt16
	// ValueTypeUnsignedInt32 is an unsigned 32-bit integer
	ValueTypeUnsignedInt32
	// ValueTypeUnsignedInt64 is an unsigned 64-bit integer
	ValueTypeUnsignedInt64

	// ValueTypeBool is a bool
	ValueTypeBool
	// ValueTypeDouble is a 64-bit floating point
	ValueTypeDouble
	// ValueTypeTimestamp is a timestamp with nanosecond granularity
	ValueTypeTimestamp
)

func ValueTypeOf

func ValueTypeOf(i interface{}) ValueType

ValueTypeOf returns the value type of a value

func (ValueType) IsInteger

func (t ValueType) IsInteger() bool

IsInteger returns true if the specified ValueType represents an integer type.

func (ValueType) IsNumeric

func (t ValueType) IsNumeric() bool

IsNumeric returns true if the specified ValueType represents a numeric type type (integer or double)

func (ValueType) IsString

func (t ValueType) IsString() bool

IsString returns true if the specified ValueType represents a string type.

Jump to

Keyboard shortcuts

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