condition

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AndCondKind      CondKind = 1
	OrCondKind                = 2
	NotCondKind               = 3
	CategoryCondKind          = 4
	CompareCondKind           = 5
	ExprCondKind              = 6
	ErrorCondKind             = 7
)
View Source
const (
	CompareEqualOp          CompareOp = 1
	CompareNotEqualOp                 = 2
	CompareGreaterOp                  = 3
	CompareGreaterOrEqualOp           = 4
	CompareLessOp                     = 5
	CompareLessOrEqualOp              = 6
	CompareContainsOp                 = 7
	CompareInvalidOp                  = 99
)
View Source
const (
	StringOperandKind     OperandKind = 1
	IntOperandKind                    = 2
	FloatOperandKind                  = 3
	BooleanOperandKind                = 4
	TimeOperandKind                   = 5
	AttributeOperandKind              = 6
	ExpressionOperandKind             = 7
	AddressOperandKind                = 8
	SelOperandKind                    = 9
	IndexOperandKind                  = 10
	NullOperandKind                   = 11
	ListOperandKind                   = 12
	ErrorOperandKind                  = 13
)

Variables

This section is empty.

Functions

func ReconcileOperands

func ReconcileOperands(x, y Operand) (Operand, Operand)

ReconcileOperands TODO: may need to add reconcile kind, e.g. compare, arithmetic, string, etc.

Types

type AddressOperand

type AddressOperand struct {
	Address        []int
	FullAddress    []int
	ParameterIndex int
	ExprOperand    *ExprOperand
	Hash           uint64
}

func NewAddressOperand

func NewAddressOperand(address []int, fullAddress []int, parameterIndex int, exprOperand *ExprOperand) *AddressOperand

func (*AddressOperand) Convert

func (v *AddressOperand) Convert(to OperandKind) Operand

func (*AddressOperand) Equals

func (v *AddressOperand) Equals(o immutable.SetElement) bool

func (*AddressOperand) Evaluate

func (v *AddressOperand) Evaluate(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand

func (*AddressOperand) GetHash

func (v *AddressOperand) GetHash() uint64

func (*AddressOperand) GetKind

func (v *AddressOperand) GetKind() OperandKind

func (*AddressOperand) Greater

func (v *AddressOperand) Greater(o Operand) bool

func (*AddressOperand) IsConst

func (v *AddressOperand) IsConst() bool

type AndCond

type AndCond struct {
	Operands []Condition
	Hash     uint64
}

func (*AndCond) Equals

func (c *AndCond) Equals(v immutable.SetElement) bool

func (*AndCond) GetHash

func (c *AndCond) GetHash() uint64

func (*AndCond) GetKind

func (c *AndCond) GetKind() CondKind

func (*AndCond) GetOperands

func (c *AndCond) GetOperands() []Condition

type AttributeOperand

type AttributeOperand struct {
	AttributePath string
}

func NewAttributeOperand

func NewAttributeOperand(attributePath string) *AttributeOperand

func (*AttributeOperand) Convert

func (v *AttributeOperand) Convert(to OperandKind) Operand

func (*AttributeOperand) Equals

func (*AttributeOperand) Evaluate

func (v *AttributeOperand) Evaluate(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand

func (*AttributeOperand) GetHash

func (v *AttributeOperand) GetHash() uint64

func (*AttributeOperand) GetKind

func (v *AttributeOperand) GetKind() OperandKind

func (*AttributeOperand) Greater

func (v *AttributeOperand) Greater(o Operand) bool

func (*AttributeOperand) IsConst

func (v *AttributeOperand) IsConst() bool

type BooleanOperand

type BooleanOperand bool

func NewBooleanOperand

func NewBooleanOperand(val bool) BooleanOperand

func (BooleanOperand) Convert

func (v BooleanOperand) Convert(to OperandKind) Operand

func (BooleanOperand) Equals

func (BooleanOperand) Evaluate

func (v BooleanOperand) Evaluate(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand

func (BooleanOperand) GetHash

func (v BooleanOperand) GetHash() uint64

func (BooleanOperand) GetKind

func (v BooleanOperand) GetKind() OperandKind

func (BooleanOperand) Greater

func (v BooleanOperand) Greater(o Operand) bool

func (BooleanOperand) IsConst

func (v BooleanOperand) IsConst() bool

type CategoryCond

type CategoryCond struct {
	Cat  types.Category
	Hash uint64
}

func (*CategoryCond) Equals

func (c *CategoryCond) Equals(v immutable.SetElement) bool

func (*CategoryCond) GetHash

func (c *CategoryCond) GetHash() uint64

func (*CategoryCond) GetKind

func (c *CategoryCond) GetKind() CondKind

func (*CategoryCond) GetOperands

func (c *CategoryCond) GetOperands() []Condition

type CompareCondition

type CompareCondition struct {
	CompareOp    CompareOp
	LeftOperand  Operand
	RightOperand Operand
	Hash         uint64
}

func NewCompareCond

func NewCompareCond(op CompareOp, l Operand, r Operand) *CompareCondition

func (*CompareCondition) Equals

func (cond *CompareCondition) Equals(v immutable.SetElement) bool

func (*CompareCondition) GetHash

func (cond *CompareCondition) GetHash() uint64

func (*CompareCondition) GetKind

func (cond *CompareCondition) GetKind() CondKind

func (*CompareCondition) GetOperands

func (cond *CompareCondition) GetOperands() []Condition

type CompareOp

type CompareOp uint8

type CondKind

type CondKind int8

type Condition

type Condition interface {
	immutable.SetElement
	GetOperands() []Condition
	GetKind() CondKind
}

func AndOrSetToCondition

func AndOrSetToCondition(set types.AndOrSet) Condition

func CategoryArraysToCondition

func CategoryArraysToCondition(cats [][]types.Category) Condition

func FindFirstError

func FindFirstError(cond []Condition) *Condition

func FirstError

func FirstError(cond []Condition) Condition

func NewAndCond

func NewAndCond(cond ...Condition) Condition

func NewCategoryCond

func NewCategoryCond(cat types.Category) Condition

func NewErrorCondition

func NewErrorCondition(val error) Condition

func NewExprCondition

func NewExprCondition(val string) Condition

func NewNotCond

func NewNotCond(cond Condition) Condition

func NewOrCond

func NewOrCond(cond ...Condition) Condition

type ErrorCondition

type ErrorCondition struct {
	Err  error
	Hash uint64
}

func (*ErrorCondition) Equals

func (c *ErrorCondition) Equals(v immutable.SetElement) bool

func (*ErrorCondition) GetHash

func (c *ErrorCondition) GetHash() uint64

func (*ErrorCondition) GetKind

func (c *ErrorCondition) GetKind() CondKind

func (*ErrorCondition) GetOperands

func (c *ErrorCondition) GetOperands() []Condition

type ErrorOperand

type ErrorOperand struct {
	Err error
}

func (ErrorOperand) Convert

func (v ErrorOperand) Convert(to OperandKind) Operand

func (ErrorOperand) Equals

func (v ErrorOperand) Equals(o immutable.SetElement) bool

func (ErrorOperand) Error

func (v ErrorOperand) Error() string

func (ErrorOperand) Evaluate

func (v ErrorOperand) Evaluate(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand

func (ErrorOperand) GetHash

func (v ErrorOperand) GetHash() uint64

func (ErrorOperand) GetKind

func (v ErrorOperand) GetKind() OperandKind

func (ErrorOperand) Greater

func (v ErrorOperand) Greater(o Operand) bool

func (ErrorOperand) IsConst

func (v ErrorOperand) IsConst() bool

type EvalOperandFunc

type EvalOperandFunc func(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand

type ExprCondition

type ExprCondition struct {
	Expr string
	Hash uint64
}

func (*ExprCondition) Equals

func (c *ExprCondition) Equals(v immutable.SetElement) bool

func (*ExprCondition) GetHash

func (c *ExprCondition) GetHash() uint64

func (*ExprCondition) GetKind

func (c *ExprCondition) GetKind() CondKind

func (*ExprCondition) GetOperands

func (c *ExprCondition) GetOperands() []Condition

type ExprOperand

type ExprOperand struct {
	Func EvalOperandFunc
	Args []Operand
	Hash uint64
}

func NewExprOperand

func NewExprOperand(f EvalOperandFunc, args ...Operand) *ExprOperand

func (*ExprOperand) Convert

func (v *ExprOperand) Convert(to OperandKind) Operand

func (*ExprOperand) Equals

func (v *ExprOperand) Equals(o immutable.SetElement) bool

func (*ExprOperand) Evaluate

func (v *ExprOperand) Evaluate(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand

func (*ExprOperand) GetHash

func (v *ExprOperand) GetHash() uint64

func (*ExprOperand) GetKind

func (v *ExprOperand) GetKind() OperandKind

func (*ExprOperand) Greater

func (v *ExprOperand) Greater(o Operand) bool

func (*ExprOperand) IsConst

func (v *ExprOperand) IsConst() bool

type Factory

type Factory struct {
	OperandCache   *hashmap.Map[Operand, Operand]
	ConditionCache *hashmap.Map[Condition, Condition]
}

func NewFactory

func NewFactory() *Factory

func (*Factory) CacheCondition

func (factory *Factory) CacheCondition(cond Condition) Condition

func (*Factory) CacheOperand

func (factory *Factory) CacheOperand(operand Operand) Operand

func (*Factory) NewAddressOperand

func (factory *Factory) NewAddressOperand(address []int, fullAddress []int, parameterIndex int, exprOperand *ExprOperand) Operand

func (*Factory) NewAndCond

func (factory *Factory) NewAndCond(cond ...Condition) Condition

func (*Factory) NewAttributeOperand

func (factory *Factory) NewAttributeOperand(val string) Operand

func (*Factory) NewBooleanOperand

func (factory *Factory) NewBooleanOperand(val bool) Operand

func (*Factory) NewCompareCond

func (factory *Factory) NewCompareCond(op CompareOp, l Operand, r Operand) Condition

func (*Factory) NewErrorOperand

func (factory *Factory) NewErrorOperand(val error) Operand

func (*Factory) NewExprOperand

func (factory *Factory) NewExprOperand(f EvalOperandFunc, args ...Operand) *ExprOperand

func (*Factory) NewFloatOperand

func (factory *Factory) NewFloatOperand(val float64) Operand

func (*Factory) NewIndexOperand

func (factory *Factory) NewIndexOperand(base Operand, indexExpr Operand) Operand

func (*Factory) NewIntOperand

func (factory *Factory) NewIntOperand(val int64) Operand

func (*Factory) NewNotCond

func (factory *Factory) NewNotCond(cond Condition) Condition

func (*Factory) NewOrCond

func (factory *Factory) NewOrCond(cond ...Condition) Condition

func (*Factory) NewSelOperand

func (factory *Factory) NewSelOperand(base Operand, selector string) Operand

func (*Factory) NewStringOperand

func (factory *Factory) NewStringOperand(val string) Operand

type FloatOperand

type FloatOperand float64
var FloatConst0 FloatOperand = 0
var FloatConst1 FloatOperand = 1

func (FloatOperand) Convert

func (v FloatOperand) Convert(to OperandKind) Operand

func (FloatOperand) Equals

func (v FloatOperand) Equals(o immutable.SetElement) bool

func (FloatOperand) Evaluate

func (v FloatOperand) Evaluate(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand

func (FloatOperand) GetHash

func (v FloatOperand) GetHash() uint64

func (FloatOperand) GetKind

func (v FloatOperand) GetKind() OperandKind

func (FloatOperand) Greater

func (v FloatOperand) Greater(o Operand) bool

func (FloatOperand) IsConst

func (v FloatOperand) IsConst() bool

type ForEach

type ForEach interface {
	GetElement() string
	GetPath() string
	GetCond() Condition
	GetHash() uint64
	Equals(element immutable.SetElement) bool
}

type IndexOperand

type IndexOperand struct {
	Base      Operand
	IndexExpr Operand
	Hash      uint64
}

func NewIndexOperand

func NewIndexOperand(base Operand, indexExpr Operand) *IndexOperand

func (*IndexOperand) Convert

func (v *IndexOperand) Convert(to OperandKind) Operand

func (*IndexOperand) Equals

func (v *IndexOperand) Equals(o immutable.SetElement) bool

func (*IndexOperand) Evaluate

func (v *IndexOperand) Evaluate(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand

func (*IndexOperand) GetHash

func (v *IndexOperand) GetHash() uint64

func (*IndexOperand) GetKind

func (v *IndexOperand) GetKind() OperandKind

func (*IndexOperand) Greater

func (v *IndexOperand) Greater(o Operand) bool

func (*IndexOperand) IsConst

func (v *IndexOperand) IsConst() bool

type IntOperand

type IntOperand int64
var IntConst0 IntOperand = 0
var IntConst1 IntOperand = 1

func (IntOperand) Convert

func (v IntOperand) Convert(to OperandKind) Operand

func (IntOperand) Equals

func (v IntOperand) Equals(o immutable.SetElement) bool

func (IntOperand) Evaluate

func (v IntOperand) Evaluate(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand

func (IntOperand) GetHash

func (v IntOperand) GetHash() uint64

func (IntOperand) GetKind

func (v IntOperand) GetKind() OperandKind

func (IntOperand) Greater

func (v IntOperand) Greater(o Operand) bool

func (IntOperand) IsConst

func (v IntOperand) IsConst() bool

type ListOperand

type ListOperand struct {
	List []Operand
}

func NewListOperand

func NewListOperand(list []Operand) *ListOperand

NewListOperand do not compute hash on creation. We use ListOperand at runtime and need it to be fast

func (*ListOperand) Convert

func (v *ListOperand) Convert(to OperandKind) Operand

func (*ListOperand) Equals

func (v *ListOperand) Equals(o immutable.SetElement) bool

func (*ListOperand) Evaluate

func (v *ListOperand) Evaluate(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand

func (*ListOperand) GetHash

func (v *ListOperand) GetHash() uint64

func (*ListOperand) GetKind

func (v *ListOperand) GetKind() OperandKind

func (*ListOperand) Greater

func (v *ListOperand) Greater(o Operand) bool

func (*ListOperand) IsConst

func (v *ListOperand) IsConst() bool

type NotCond

type NotCond struct {
	Operand Condition
	Hash    uint64
}

func (*NotCond) Equals

func (c *NotCond) Equals(v immutable.SetElement) bool

func (*NotCond) GetHash

func (c *NotCond) GetHash() uint64

func (*NotCond) GetKind

func (c *NotCond) GetKind() CondKind

func (*NotCond) GetOperands

func (c *NotCond) GetOperands() []Condition

type NullOperand

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

func (NullOperand) Convert

func (v NullOperand) Convert(to OperandKind) Operand

func (NullOperand) Equals

func (v NullOperand) Equals(o immutable.SetElement) bool

func (NullOperand) Evaluate

func (v NullOperand) Evaluate(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand

func (NullOperand) GetHash

func (v NullOperand) GetHash() uint64

func (NullOperand) GetKind

func (v NullOperand) GetKind() OperandKind

func (NullOperand) Greater

func (v NullOperand) Greater(o Operand) bool

func (NullOperand) IsConst

func (v NullOperand) IsConst() bool

type Operand

type Operand interface {
	immutable.SetElement
	IsConst() bool
	GetKind() OperandKind
	Greater(o Operand) bool
	Convert(to OperandKind) Operand
	OperandEvaluator
}

func NewErrorOperand

func NewErrorOperand(val error) Operand

func NewFloatOperand

func NewFloatOperand(val float64) Operand

func NewIntOperand

func NewIntOperand(val int64) Operand

func NewInterfaceOperand

func NewInterfaceOperand(v interface{}, ctx *types.AppContext) Operand

func NewNullOperand

func NewNullOperand(val *AddressOperand) Operand

func NewStringOperand

func NewStringOperand(val string) Operand

func NewTimeOperand

func NewTimeOperand(val time.Time) Operand

type OperandEvaluator

type OperandEvaluator interface {
	Evaluate(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand
}

type OperandKind

type OperandKind uint8

type OrCond

type OrCond struct {
	Operands []Condition
	Hash     uint64
}

func (*OrCond) Equals

func (c *OrCond) Equals(v immutable.SetElement) bool

func (*OrCond) GetHash

func (c *OrCond) GetHash() uint64

func (*OrCond) GetKind

func (c *OrCond) GetKind() CondKind

func (*OrCond) GetOperands

func (c *OrCond) GetOperands() []Condition

type Rule

type Rule struct {
	RuleId RuleIdType
	Cond   Condition
}

func NewRule

func NewRule(RuleId RuleIdType, Cond Condition) *Rule

type RuleIdType

type RuleIdType uint32

type RuleIndexType

type RuleIndexType int32

type RuleRec

type RuleRec struct {
	Rule      *Rule
	RuleIndex RuleIndexType
}

type RuleRepo

type RuleRepo struct {
	Rules []*Rule
}

func AndOrTablesToRuleRepo

func AndOrTablesToRuleRepo(tables [][][]types.Category) *RuleRepo

func NewRuleRepo

func NewRuleRepo(rules []*Rule) *RuleRepo

func (*RuleRepo) Register

func (repo *RuleRepo) Register(rule *Rule)

type SelOperand

type SelOperand struct {
	Base     Operand
	Selector string
	Hash     uint64
}

func NewSelOperand

func NewSelOperand(base Operand, selector string) *SelOperand

func (*SelOperand) Convert

func (v *SelOperand) Convert(to OperandKind) Operand

func (*SelOperand) Equals

func (v *SelOperand) Equals(o immutable.SetElement) bool

func (*SelOperand) Evaluate

func (v *SelOperand) Evaluate(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand

func (*SelOperand) GetHash

func (v *SelOperand) GetHash() uint64

func (*SelOperand) GetKind

func (v *SelOperand) GetKind() OperandKind

func (*SelOperand) Greater

func (v *SelOperand) Greater(o Operand) bool

func (*SelOperand) IsConst

func (v *SelOperand) IsConst() bool

type StringOperand

type StringOperand string

func (StringOperand) Convert

func (v StringOperand) Convert(to OperandKind) Operand

func (StringOperand) Equals

func (v StringOperand) Equals(o immutable.SetElement) bool

func (StringOperand) Evaluate

func (v StringOperand) Evaluate(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand

func (StringOperand) GetHash

func (v StringOperand) GetHash() uint64

func (StringOperand) GetKind

func (v StringOperand) GetKind() OperandKind

func (StringOperand) Greater

func (v StringOperand) Greater(o Operand) bool

func (StringOperand) IsConst

func (v StringOperand) IsConst() bool

type TimeOperand

type TimeOperand time.Time

func (TimeOperand) Convert

func (v TimeOperand) Convert(to OperandKind) Operand

func (TimeOperand) Equals

func (v TimeOperand) Equals(o immutable.SetElement) bool

func (TimeOperand) Evaluate

func (v TimeOperand) Evaluate(event *objectmap.ObjectAttributeMap, frames []interface{}) Operand

func (TimeOperand) GetHash

func (v TimeOperand) GetHash() uint64

func (TimeOperand) GetKind

func (v TimeOperand) GetKind() OperandKind

func (TimeOperand) Greater

func (v TimeOperand) Greater(o Operand) bool

func (TimeOperand) IsConst

func (v TimeOperand) IsConst() bool

Jump to

Keyboard shortcuts

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