Skip to content

Commit 7564510

Browse files
committed
make projection a pointer
Signed-off-by: yeya24 <[email protected]>
1 parent 7a5c77d commit 7564510

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

logicalplan/logical_nodes.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type VectorSelector struct {
7373
Filters []*labels.Matcher
7474
BatchSize int64
7575
SelectTimestamp bool
76-
Projection Projection
76+
Projection *Projection
7777
// When set, histogram iterators can return objects which only have their
7878
// CounterResetHint, Count and Sum values populated. Histogram buckets and spans
7979
// will not be used during query evaluation.
@@ -87,8 +87,11 @@ func (f *VectorSelector) Clone() Node {
8787

8888
clone.Filters = shallowCloneSlice(f.Filters)
8989
clone.LabelMatchers = shallowCloneSlice(f.LabelMatchers)
90-
clone.Projection.Labels = shallowCloneSlice(f.Projection.Labels)
91-
clone.Projection.Include = f.Projection.Include
90+
if f.Projection != nil {
91+
clone.Projection = &Projection{}
92+
clone.Projection.Labels = shallowCloneSlice(f.Projection.Labels)
93+
clone.Projection.Include = f.Projection.Include
94+
}
9295

9396
if f.VectorSelector.Timestamp != nil {
9497
ts := *f.VectorSelector.Timestamp

logicalplan/plan_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ func renderExprTree(expr Node) string {
4040
if t.BatchSize > 0 {
4141
base += fmt.Sprintf("[batch=%d]", t.BatchSize)
4242
}
43-
if t.Projection.Labels != nil {
44-
sort.Strings(t.Projection.Labels)
45-
if t.Projection.Include {
46-
base += fmt.Sprintf("[projection=include(%s)]", strings.Join(t.Projection.Labels, ","))
47-
} else {
48-
base += fmt.Sprintf("[projection=exclude(%s)]", strings.Join(t.Projection.Labels, ","))
43+
if t.Projection != nil {
44+
if t.Projection.Labels != nil {
45+
sort.Strings(t.Projection.Labels)
46+
if t.Projection.Include {
47+
base += fmt.Sprintf("[projection=include(%s)]", strings.Join(t.Projection.Labels, ","))
48+
} else {
49+
base += fmt.Sprintf("[projection=exclude(%s)]", strings.Join(t.Projection.Labels, ","))
50+
}
4951
}
5052
}
5153
if len(t.Filters) > 0 {

logicalplan/projection_pushdown.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ func (p ProjectionPushdown) pushProjection(node *Node, requiredLabels map[string
2323
case *VectorSelector:
2424
// Apply projection if we have required labels
2525
if requiredLabels != nil {
26-
projection := Projection{
26+
projection := &Projection{
2727
Labels: make([]string, 0, len(requiredLabels)),
2828
Include: !isWithout,
2929
}
3030
for lbl := range requiredLabels {
3131
projection.Labels = append(projection.Labels, lbl)
3232
}
3333
n.Projection = projection
34+
} else {
35+
// Set dummy projection.
36+
n.Projection = &Projection{}
3437
}
3538

3639
case *Aggregation:

storage/prometheus/scanners.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ func (p Scanners) NewVectorSelector(
5454
logicalNode logicalplan.VectorSelector,
5555
) (model.VectorOperator, error) {
5656
// Update hints with projection information if available
57-
hints.Grouping = logicalNode.Projection.Labels
58-
hints.By = logicalNode.Projection.Include
57+
if logicalNode.Projection != nil {
58+
hints.Grouping = logicalNode.Projection.Labels
59+
hints.By = logicalNode.Projection.Include
60+
}
5961

6062
selector := p.selectors.GetFilteredSelector(hints.Start, hints.End, opts.Step.Milliseconds(), logicalNode.VectorSelector.LabelMatchers, logicalNode.Filters, hints)
6163
if logicalNode.DecodeNativeHistogramStats {
@@ -125,8 +127,10 @@ func (p Scanners) NewMatrixSelector(
125127
}
126128

127129
vs := logicalNode.VectorSelector
128-
hints.Grouping = vs.Projection.Labels
129-
hints.By = vs.Projection.Include
130+
if vs.Projection != nil {
131+
hints.Grouping = vs.Projection.Labels
132+
hints.By = vs.Projection.Include
133+
}
130134

131135
selector := p.selectors.GetFilteredSelector(hints.Start, hints.End, opts.Step.Milliseconds(), vs.LabelMatchers, vs.Filters, hints)
132136
if logicalNode.VectorSelector.DecodeNativeHistogramStats {

0 commit comments

Comments
 (0)