MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / Compile

Method Compile

pkg/filter/filter.go:160–244  ·  view source on GitHub ↗

Compile parsers the filter expression and builds a binary expression tree where leaf nodes represent constants/variables while internal nodes are operators. Operators can be binary (=) or unary (not). Fields in filter expressions are replaced with respective event parameters via map valuer. For func

()

Source from the content-addressed store, hash-verified

158// Matching the filter involves descending the binary expression tree recursively
159// until all nodes are visited.
160func (f *filter) Compile() error {
161 var err error
162 if f.parser.IsSequence() {
163 f.seq, err = f.parser.ParseSequence()
164 } else {
165 f.expr, err = f.parser.ParseExpr()
166 }
167 if err != nil {
168 return err
169 }
170
171 // traverse the expression tree
172 walk := func(n ql.Node) {
173 switch expr := n.(type) {
174 case *ql.BinaryExpr:
175 if lhs, ok := expr.LHS.(*ql.FieldLiteral); ok {
176 f.addField(lhs)
177 f.addStringFields(lhs.Field, expr.RHS)
178 }
179 if rhs, ok := expr.RHS.(*ql.FieldLiteral); ok {
180 f.addField(rhs)
181 f.addStringFields(rhs.Field, expr.LHS)
182 }
183 if lhs, ok := expr.LHS.(*ql.BoundFieldLiteral); ok {
184 f.addField(lhs.Field)
185 f.addBoundField(lhs)
186 }
187 if rhs, ok := expr.RHS.(*ql.BoundFieldLiteral); ok {
188 f.addField(rhs.Field)
189 f.addBoundField(rhs)
190 }
191 case *ql.Function:
192 f.hasFunctions = true
193 for _, arg := range expr.Args {
194 if field, ok := arg.(*ql.FieldLiteral); ok {
195 f.addField(field)
196 }
197 if field, ok := arg.(*ql.BoundFieldLiteral); ok {
198 f.addField(field.Field)
199 f.addBoundField(field)
200 }
201 switch exp := arg.(type) {
202 case *ql.BinaryExpr:
203 if segment, ok := exp.LHS.(*ql.BoundSegmentLiteral); ok {
204 f.addSegment(segment)
205 }
206 if segment, ok := exp.RHS.(*ql.BoundSegmentLiteral); ok {
207 f.addSegment(segment)
208 }
209 }
210 }
211 case *ql.FieldLiteral:
212 if fields.IsBoolean(expr.Field) {
213 f.addField(expr)
214 }
215 }
216 }
217

Callers 1

Calls 11

addFieldMethod · 0.95
addStringFieldsMethod · 0.95
addBoundFieldMethod · 0.95
addSegmentMethod · 0.95
narrowAccessorsMethod · 0.95
checkBoundRefsMethod · 0.95
IsBooleanFunction · 0.92
WalkFuncFunction · 0.92
ParseSequenceMethod · 0.80
ParseExprMethod · 0.80
IsSequenceMethod · 0.65

Tested by

no test coverage detected