-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Milestone
Description
Overview
Implement LogQL binary operations between vectors, including arithmetic, comparison, and logical operators with vector matching modifiers.
Parent Issue
Part of #6 (Query Service Implementation), delegated from #8 (LogQL Query Compiler).
Context
Binary operations allow combining two vector expressions. Currently, all binary operations return NotImplemented error. Only scalar literals work in simple contexts.
Requirements
Arithmetic Operators
| Operator | Description |
|---|---|
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
% |
Modulo |
^ |
Exponentiation |
Comparison Operators
| Operator | Description |
|---|---|
== |
Equal (filter or bool) |
!= |
Not equal |
> |
Greater than |
>= |
Greater or equal |
< |
Less than |
<= |
Less or equal |
Logical/Set Operators
| Operator | Description |
|---|---|
and |
Intersection |
or |
Union |
unless |
Difference |
Vector Matching Modifiers
| Modifier | Description |
|---|---|
on(labels...) |
Match only on specified labels |
ignoring(labels...) |
Ignore specified labels when matching |
group_left(labels...) |
Many-to-one matching |
group_right(labels...) |
One-to-many matching |
Example Queries
rate({job="app"}[5m]) * 60
rate({job="app"}[5m]) / rate({job="db"}[5m])
rate({job="app"}[5m]) > 100
sum by (service) (rate({job="app"}[5m])) / on(service) sum by (service) (rate({job="db"}[5m]))
vector1 and vector2
vector1 unless vector2
Implementation Approach
-
Implement binary expression planning in
planner.rs:- Handle
BinOpExprin query planning - Support vector-scalar and vector-vector operations
- Handle
-
Vector matching logic:
- Default: match on all labels
on(): JOIN on specified labels onlyignoring(): JOIN on all labels except specifiedgroup_left/right: handle one-to-many relationships
-
Translation to DataFusion:
- Arithmetic:
col("left.value") + col("right.value") - Comparison:
filter()orCASE WHENforboolmodifier - Logical: INNER/LEFT/ANTI JOINs on label columns
- Arithmetic:
Acceptance Criteria
- All arithmetic operators work between vectors and scalars
- Comparison operators filter or return 0/1 with
boolmodifier - Logical operators perform correct set operations
-
on()andignoring()modifiers work correctly -
group_left()andgroup_right()handle cardinality correctly - Proper error messages for cardinality violations
- Unit tests for each operator
- Integration tests with complex expressions
Technical References
- LogQL Binary Operations
- Vector Matching
- Technical spec:
src/query/logql/TECHNICAL_SPEC.mdSection 6