|
| 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_test |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/openGemini/openGemini/engine/executor" |
| 23 | + "github.com/openGemini/openGemini/engine/hybridqp" |
| 24 | + "github.com/openGemini/openGemini/lib/util/lifted/influx/influxql" |
| 25 | + "github.com/openGemini/openGemini/lib/util/lifted/influx/query" |
| 26 | + "github.com/stretchr/testify/assert" |
| 27 | +) |
| 28 | + |
| 29 | +func buildOrderByTransformRowDataType() hybridqp.RowDataType { |
| 30 | + rowDataType := hybridqp.NewRowDataTypeImpl( |
| 31 | + influxql.VarRef{Val: "value", Type: influxql.Float}, |
| 32 | + ) |
| 33 | + return rowDataType |
| 34 | +} |
| 35 | + |
| 36 | +func buildOrderByTransformInChunk() executor.Chunk { |
| 37 | + rowDataType := buildOrderByTransformRowDataType() |
| 38 | + b := executor.NewChunkBuilder(rowDataType) |
| 39 | + chunk := b.NewChunk("tag1") |
| 40 | + chunk.AppendTimes([]int64{1, 3, 4}) |
| 41 | + chunk.AddTagAndIndex(*ParseChunkTags("tag1=tag1val,tag2=tag2val"), 0) |
| 42 | + chunk.AddIntervalIndex(0) |
| 43 | + AppendFloatValues(chunk, 0, []float64{1.1, 3.3, 4.4}, []bool{true, true, true}) |
| 44 | + return chunk |
| 45 | +} |
| 46 | + |
| 47 | +func TestOrderByTransformInitPromDims1(t *testing.T) { |
| 48 | + inRowDataType := buildOrderByTransformRowDataType() |
| 49 | + outRowDataType := inRowDataType |
| 50 | + exprOpt := []hybridqp.ExprOptions{ |
| 51 | + { |
| 52 | + Expr: &influxql.VarRef{Val: "val0", Type: influxql.Float}, |
| 53 | + Ref: influxql.VarRef{Val: "val0", Type: influxql.Float}, |
| 54 | + }, |
| 55 | + } |
| 56 | + chunk := buildOrderByTransformInChunk() |
| 57 | + opt1 := query.ProcessorOptions{ |
| 58 | + PromQuery: true, |
| 59 | + GroupByAllDims: true, |
| 60 | + } |
| 61 | + trans1 := executor.NewOrderByTransform(inRowDataType, outRowDataType, exprOpt, &opt1, nil) |
| 62 | + trans1.GetTagAndIndexes(chunk) |
| 63 | + assert.Equal(t, trans1.GetCurrTags(0), "\x04\x00\x05\x00\r\x00\x12\x00\x1a\x00tag1\x00tag1val\x00tag2\x00tag2val\x00") |
| 64 | + opt2 := query.ProcessorOptions{ |
| 65 | + PromQuery: true, |
| 66 | + Without: true, |
| 67 | + Dimensions: []string{"tag1"}, |
| 68 | + } |
| 69 | + trans2 := executor.NewOrderByTransform(inRowDataType, outRowDataType, exprOpt, &opt2, nil) |
| 70 | + trans2.GetTagAndIndexes(chunk) |
| 71 | + assert.Equal(t, trans2.GetCurrTags(0), "\x02\x00\x05\x00\r\x00tag2\x00tag2val\x00") |
| 72 | + opt3 := query.ProcessorOptions{ |
| 73 | + PromQuery: true, |
| 74 | + Dimensions: []string{"tag1"}, |
| 75 | + } |
| 76 | + trans3 := executor.NewOrderByTransform(inRowDataType, outRowDataType, exprOpt, &opt3, opt3.Dimensions) |
| 77 | + trans3.GetTagAndIndexes(chunk) |
| 78 | + assert.Equal(t, trans3.GetCurrTags(0), "\x02\x00\x05\x00\r\x00tag1\x00tag1val\x00") |
| 79 | +} |
| 80 | + |
| 81 | +func TestOrderByTransformInitPromDims2(t *testing.T) { |
| 82 | + inRowDataType := buildOrderByTransformRowDataType() |
| 83 | + outRowDataType := inRowDataType |
| 84 | + exprOpt := []hybridqp.ExprOptions{ |
| 85 | + { |
| 86 | + Expr: &influxql.VarRef{Val: "val0", Type: influxql.Float}, |
| 87 | + Ref: influxql.VarRef{Val: "val0", Type: influxql.Float}, |
| 88 | + }, |
| 89 | + } |
| 90 | + chunk := buildOrderByTransformInChunk() |
| 91 | + opt1 := query.ProcessorOptions{ |
| 92 | + PromQuery: true, |
| 93 | + GroupByAllDims: true, |
| 94 | + } |
| 95 | + trans1 := executor.NewOrderByTransform(inRowDataType, outRowDataType, exprOpt, &opt1, nil) |
| 96 | + trans1.GetTagsResetTagIndexes(chunk) |
| 97 | + assert.Equal(t, trans1.GetCurrTags(0), "\x04\x00\x05\x00\r\x00\x12\x00\x1a\x00tag1\x00tag1val\x00tag2\x00tag2val\x00") |
| 98 | + opt2 := query.ProcessorOptions{ |
| 99 | + PromQuery: true, |
| 100 | + Without: true, |
| 101 | + Dimensions: []string{"tag1"}, |
| 102 | + } |
| 103 | + trans2 := executor.NewOrderByTransform(inRowDataType, outRowDataType, exprOpt, &opt2, nil) |
| 104 | + trans2.GetTagsResetTagIndexes(chunk) |
| 105 | + assert.Equal(t, trans2.GetCurrTags(0), "\x02\x00\x05\x00\r\x00tag2\x00tag2val\x00") |
| 106 | + opt3 := query.ProcessorOptions{ |
| 107 | + PromQuery: true, |
| 108 | + Dimensions: []string{"tag1"}, |
| 109 | + } |
| 110 | + trans3 := executor.NewOrderByTransform(inRowDataType, outRowDataType, exprOpt, &opt3, opt3.Dimensions) |
| 111 | + trans3.GetTagsResetTagIndexes(chunk) |
| 112 | + assert.Equal(t, trans3.GetCurrTags(0), "\x02\x00\x05\x00\r\x00tag1\x00tag1val\x00") |
| 113 | +} |
0 commit comments