Skip to content

Commit 6f186bd

Browse files
authored
refactor: use the go generic to rewrite interface of agg iterator (openGemini#591)
Signed-off-by: scuzyj <[email protected]>
1 parent 8ee0210 commit 6f186bd

12 files changed

+1080
-5702
lines changed

engine/executor/agg_func.gen.go

+3-819
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/executor/agg_func.gen.go.tmpl

-423
Large diffs are not rendered by default.

engine/executor/agg_func.go

+628
Large diffs are not rendered by default.

engine/executor/agg_func_prom.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func MinPromReduce(c Chunk, ordinal, start, end int) (int, float64, bool) {
3434
return start, minValue, false
3535
}
3636

37-
func MinPromMerge(prevPoint, currPoint *FloatPoint) {
37+
func MinPromMerge(prevPoint, currPoint *Point[float64]) {
3838
if prevPoint.value > currPoint.value || math.IsNaN(prevPoint.value) {
3939
prevPoint.Assign(currPoint)
4040
}
@@ -51,7 +51,7 @@ func MaxPromReduce(c Chunk, ordinal, start, end int) (int, float64, bool) {
5151
return start, maxValue, false
5252
}
5353

54-
func MaxPromMerge(prevPoint, currPoint *FloatPoint) {
54+
func MaxPromMerge(prevPoint, currPoint *Point[float64]) {
5555
if prevPoint.value < currPoint.value || math.IsNaN(prevPoint.value) {
5656
prevPoint.Assign(currPoint)
5757
}
@@ -62,7 +62,7 @@ func FloatCountPromReduce(c Chunk, ordinal, start, end int) (int, float64, bool)
6262
return start, count, count == 0
6363
}
6464

65-
func FloatCountPromMerge(prevPoint, currPoint *FloatPoint) {
65+
func FloatCountPromMerge(prevPoint, currPoint *Point[float64]) {
6666
prevPoint.value += currPoint.value
6767
}
6868

engine/executor/agg_func_test.go

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
Copyright 2024 Huawei Cloud Computing Technologies Co., Ltd.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package executor
18+
19+
import (
20+
"testing"
21+
22+
"github.com/openGemini/openGemini/engine/hybridqp"
23+
"github.com/openGemini/openGemini/lib/util/lifted/influx/influxql"
24+
)
25+
26+
func TestIntegerFirstReduce(t *testing.T) {
27+
chunk := NewChunkImpl(hybridqp.NewRowDataTypeImpl(
28+
influxql.VarRef{Val: "val_int1", Type: influxql.Integer},
29+
influxql.VarRef{Val: "val_int2", Type: influxql.Integer},
30+
influxql.VarRef{Val: "time", Type: influxql.Integer},
31+
), "test")
32+
33+
c1 := NewColumnImpl(influxql.Integer)
34+
c1.AppendNilsV2(true, true, true, false, false)
35+
c1.AppendIntegerValues([]int64{1, 8, 9})
36+
37+
c2 := NewColumnImpl(influxql.Integer)
38+
c2.AppendNilsV2(true, true, true, true, true)
39+
c2.AppendIntegerValues([]int64{11, 18, 19, 20, 21})
40+
41+
chunk.SetTime([]int64{1, 2, 3, 4, 5})
42+
chunk.ResetIntervalIndex(0)
43+
chunk.AddColumn(c1)
44+
chunk.AddColumn(c2)
45+
46+
// first column
47+
idx, v, isNil := IntegerFirstReduce(chunk, 0, 0, 5)
48+
if !(idx == 0 && v == 1 && !isNil) {
49+
t.Fatal("not expect, idx ", idx, "v ", v, "exist", isNil)
50+
}
51+
52+
// second column
53+
idx, v, isNil = IntegerFirstReduce(chunk, 1, 0, 5)
54+
if !(idx == 0 && v == 11 && !isNil) {
55+
t.Fatal("not expect, idx ", idx, "v ", v, "exist", isNil)
56+
}
57+
}
58+
59+
func TestFloatFirstReduce(t *testing.T) {
60+
chunk := NewChunkImpl(hybridqp.NewRowDataTypeImpl(
61+
influxql.VarRef{Val: "val_float1", Type: influxql.Float},
62+
influxql.VarRef{Val: "val_float2", Type: influxql.Float},
63+
influxql.VarRef{Val: "time", Type: influxql.Integer},
64+
), "test")
65+
66+
c1 := NewColumnImpl(influxql.Float)
67+
c1.AppendNilsV2(true, true, true, false, false)
68+
c1.AppendFloatValues([]float64{1.1, 8.2, 9.3})
69+
70+
c2 := NewColumnImpl(influxql.Float)
71+
c2.AppendNilsV2(true, true, true, true, true)
72+
c2.AppendFloatValues([]float64{11.1, 18.2, 19.3, 20.4, 21.5})
73+
74+
chunk.SetTime([]int64{1, 2, 3, 4, 5})
75+
chunk.ResetIntervalIndex(0)
76+
chunk.AddColumn(c1)
77+
chunk.AddColumn(c2)
78+
79+
// first column
80+
idx, v, isNil := FloatFirstReduce(chunk, 0, 0, 5)
81+
if !(idx == 0 && v == 1.1 && !isNil) {
82+
t.Fatal("not expect, idx ", idx, "v ", v, "exist", isNil)
83+
}
84+
85+
// second column
86+
idx, v, isNil = FloatFirstReduce(chunk, 1, 0, 5)
87+
if !(idx == 0 && v == 11.1 && !isNil) {
88+
t.Fatal("not expect, idx ", idx, "v ", v, "exist", isNil)
89+
}
90+
}
91+
92+
func TestStringFirstReduce(t *testing.T) {
93+
chunk := NewChunkImpl(hybridqp.NewRowDataTypeImpl(
94+
influxql.VarRef{Val: "val_string1", Type: influxql.String},
95+
influxql.VarRef{Val: "val_string2", Type: influxql.String},
96+
influxql.VarRef{Val: "time", Type: influxql.Integer},
97+
), "test")
98+
99+
c1 := NewColumnImpl(influxql.Integer)
100+
c1.AppendNilsV2(true, true, true, false, false)
101+
c1.AppendStringValues([]string{"string1", "string2", "string3"})
102+
103+
c2 := NewColumnImpl(influxql.Integer)
104+
c2.AppendNilsV2(true, true, true, true, true)
105+
c2.AppendStringValues([]string{"string11", "string22", "string33", "string44", "string55"})
106+
107+
chunk.SetTime([]int64{1, 2, 3, 4, 5})
108+
chunk.ResetIntervalIndex(0)
109+
chunk.AddColumn(c1)
110+
chunk.AddColumn(c2)
111+
112+
idx, v, isNil := StringFirstReduce(chunk, 0, 0, 5)
113+
if !(idx == 0 && v == "string1" && !isNil) {
114+
t.Fatal("not expect, idx ", idx, "v ", v, "exist", isNil)
115+
}
116+
117+
idx, v, isNil = StringFirstReduce(chunk, 1, 0, 5)
118+
if !(idx == 0 && v == "string11" && !isNil) {
119+
t.Fatal("not expect, idx ", idx, "v ", v, "exist", isNil)
120+
}
121+
}
122+
123+
func TestBooleanFirstReduce(t *testing.T) {
124+
chunk := NewChunkImpl(hybridqp.NewRowDataTypeImpl(
125+
influxql.VarRef{Val: "val_bool1", Type: influxql.Boolean},
126+
influxql.VarRef{Val: "val_bool2", Type: influxql.Boolean},
127+
influxql.VarRef{Val: "time", Type: influxql.Integer},
128+
), "test")
129+
130+
c1 := NewColumnImpl(influxql.Boolean)
131+
c1.AppendNilsV2(true, true, true, false, false)
132+
c1.AppendBooleanValues([]bool{true, false, false})
133+
134+
c2 := NewColumnImpl(influxql.Integer)
135+
c2.AppendNilsV2(true, true, true, true, true)
136+
c2.AppendBooleanValues([]bool{false, true, true, true, true})
137+
138+
chunk.SetTime([]int64{1, 2, 3, 4, 5})
139+
chunk.ResetIntervalIndex(0)
140+
chunk.AddColumn(c1)
141+
chunk.AddColumn(c2)
142+
143+
idx, v, isNil := BooleanFirstReduce(chunk, 0, 0, 5)
144+
if !(idx == 0 && v == true && !isNil) {
145+
t.Fatal("not expect, idx ", idx, "v ", v, "exist", isNil)
146+
}
147+
148+
idx, v, isNil = BooleanFirstReduce(chunk, 1, 0, 5)
149+
if !(idx == 0 && v == false && !isNil) {
150+
t.Fatal("not expect, idx ", idx, "v ", v, "exist", isNil)
151+
}
152+
}

0 commit comments

Comments
 (0)