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

Method ParseSequence

pkg/filter/ql/parser.go:56–203  ·  view source on GitHub ↗

ParseSequence parses the collection of binary expressions with possible join statements and time frame constraints. This method assumes the SEQUENCE token has already been consumed.

()

Source from the content-addressed store, hash-verified

54// statements and time frame constraints. This method assumes the SEQUENCE token
55// has already been consumed.
56func (p *Parser) ParseSequence() (*Sequence, error) {
57 seq := &Sequence{}
58 var exprs []SequenceExpr
59
60 // parse optional max span
61 tok, _, _ := p.scanIgnoreWhitespace()
62 if tok == MaxSpan {
63 var err error
64 seq.MaxSpan, err = p.parseDuration()
65 if err != nil {
66 return nil, err
67 }
68 if seq.MaxSpan > time.Hour*4 {
69 return nil, fmt.Errorf("maximum span %v cannot be greater than 4h", seq.MaxSpan)
70 }
71 } else {
72 p.unscan()
73 }
74
75 // parse optional global link
76 tok, _, _ = p.scanIgnoreWhitespace()
77 if tok == By {
78 tok, pos, lit := p.scanIgnoreWhitespace()
79 if !fields.IsField(lit) {
80 return nil, newParseError(tokstr(tok, lit), []string{"field"}, pos, p.expr)
81 }
82 var err error
83 field, err := p.parseField(lit)
84 if err != nil {
85 return nil, err
86 }
87
88 seqLink := &SequenceLink{Fields: []*FieldLiteral{field}}
89
90 // handle multiple join fields separated by comma
91 for {
92 if tok, _, _ := p.scanIgnoreWhitespace(); tok != Comma {
93 p.unscan()
94 break
95 }
96
97 tok, pos, lit := p.scanIgnoreWhitespace()
98 if !fields.IsField(lit) {
99 return nil, newParseError(tokstr(tok, lit), []string{"field"}, pos, p.expr)
100 }
101 field, err := p.parseField(lit)
102 if err != nil {
103 return nil, err
104 }
105
106 seqLink.Fields = append(seqLink.Fields, field)
107 }
108
109 seq.By = seqLink
110 } else {
111 p.unscan()
112 }
113

Callers 3

TestParseSequenceFunction · 0.95
TestIsSequenceUnorderedFunction · 0.95
CompileMethod · 0.80

Calls 13

scanIgnoreWhitespaceMethod · 0.95
parseDurationMethod · 0.95
unscanMethod · 0.95
parseFieldMethod · 0.95
impairByMethod · 0.95
initMethod · 0.95
ParseExprMethod · 0.95
initMethod · 0.95
walkMethod · 0.95
IsFieldFunction · 0.92
newParseErrorFunction · 0.85

Tested by 2

TestParseSequenceFunction · 0.76
TestIsSequenceUnorderedFunction · 0.76