feat: Support Filtering by multiple or filters
@yuanbohan Hi Yuanbo, I want to support or filter but even if I add something in promql.y I get the error "invalid promql query", I am new to yacc and I have used antlr before (anltr is relatively It's relatively simple, just modify the grammar definition, but yacc doesn't seem to work), so I hope you can give me some suggestions.
【victoriametrics or expression】
https://docs.victoriametrics.com/keyconcepts/#filtering-by-multiple-or-filters
【promql.y】
label_match_list -> Result<Matchers, String>:
label_match_list COMMA label_matcher { Ok($1?.append($3?)) }
| label_match_list LOR label_matcher { Ok($1?.append($3?)) } // support or filter
| label_matcher { Ok(Matchers::empty().append($1?)) }
;
【error】
expression:
a{label1="1" or label2="2"}
Err("invalid promql query")
MetricsQL is an enhancement option, and our team has discussed it. But we have no plan to totally implement the extension, and have no milestone for it.
This issue can be kept here, and we will resolve it
@yuanbohan Thanks! Looking forward to the progress
I have not tested yet, but I think it should be placed in label_matchers production
label_matchers -> Result<Matchers, String>:
LEFT_BRACE label_match_list LOR label_match_list RIGHT_BRACE { $2 }
| LEFT_BRACE label_match_list RIGHT_BRACE { $2 }
| LEFT_BRACE label_match_list COMMA RIGHT_BRACE { $2 }
| LEFT_BRACE RIGHT_BRACE { Ok(Matchers::empty()) }
| LEFT_BRACE COMMA RIGHT_BRACE
{ Err("unexpected ',' in label matching, expected identifier or right_brace".into()) }
;
and maybe there SHOULD BE some special logic in inside_braces for the LOR, maybe it is tokenized as identifier instead of the LOR token
I have not tested yet, but I think it should be placed in
label_matchersproductionlabel_matchers -> Result<Matchers, String>: LEFT_BRACE label_match_list LOR label_match_list RIGHT_BRACE { $2 } | LEFT_BRACE label_match_list RIGHT_BRACE { $2 } | LEFT_BRACE label_match_list COMMA RIGHT_BRACE { $2 } | LEFT_BRACE RIGHT_BRACE { Ok(Matchers::empty()) } | LEFT_BRACE COMMA RIGHT_BRACE { Err("unexpected ',' in label matching, expected identifier or right_brace".into()) } ;and maybe there SHOULD BE some special logic in inside_braces for the
LOR, maybe it is tokenized as identifier instead of the LOR token
@yuanbohan Thanks, I'll try to modify it and test it
@groobyming If you're trying this way as I mentioned above, you should notice that it's not exactly tested.
LEFT_BRACE label_match_list LOR label_match_list RIGHT_BRACE { $2 }
NOTE the tail part, the { $2 } is wrongly typed, and you MUST change it. And the following part MUST BE considered carefully:
- lexer: treat the LOR as not identifier
- ast: the
VectorSelectorstruct may not match this feature. Maybe theMatchersstruct has to extend the vector of Matcher to support theORfeature
If you do have time and interest to commit PR to extend MetricsQL, we can discuss it in details, and make a plan before your work.
Thanks for your passion and time for open-source promql-parser.
fixed by #84