github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/compile/scopeRemoteRun_test.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package compile 16 17 import ( 18 "fmt" 19 "testing" 20 21 "github.com/matrixorigin/matrixone/pkg/pb/plan" 22 "github.com/matrixorigin/matrixone/pkg/sql/colexec/anti" 23 "github.com/matrixorigin/matrixone/pkg/sql/colexec/connector" 24 "github.com/matrixorigin/matrixone/pkg/sql/colexec/deletion" 25 "github.com/matrixorigin/matrixone/pkg/sql/colexec/dispatch" 26 "github.com/matrixorigin/matrixone/pkg/sql/colexec/external" 27 "github.com/matrixorigin/matrixone/pkg/sql/colexec/group" 28 "github.com/matrixorigin/matrixone/pkg/sql/colexec/hashbuild" 29 "github.com/matrixorigin/matrixone/pkg/sql/colexec/insert" 30 "github.com/matrixorigin/matrixone/pkg/sql/colexec/intersect" 31 "github.com/matrixorigin/matrixone/pkg/sql/colexec/intersectall" 32 "github.com/matrixorigin/matrixone/pkg/sql/colexec/join" 33 "github.com/matrixorigin/matrixone/pkg/sql/colexec/left" 34 "github.com/matrixorigin/matrixone/pkg/sql/colexec/limit" 35 "github.com/matrixorigin/matrixone/pkg/sql/colexec/loopanti" 36 "github.com/matrixorigin/matrixone/pkg/sql/colexec/loopjoin" 37 "github.com/matrixorigin/matrixone/pkg/sql/colexec/loopleft" 38 "github.com/matrixorigin/matrixone/pkg/sql/colexec/loopmark" 39 "github.com/matrixorigin/matrixone/pkg/sql/colexec/loopsemi" 40 "github.com/matrixorigin/matrixone/pkg/sql/colexec/loopsingle" 41 "github.com/matrixorigin/matrixone/pkg/sql/colexec/mark" 42 "github.com/matrixorigin/matrixone/pkg/sql/colexec/merge" 43 "github.com/matrixorigin/matrixone/pkg/sql/colexec/mergegroup" 44 "github.com/matrixorigin/matrixone/pkg/sql/colexec/mergelimit" 45 "github.com/matrixorigin/matrixone/pkg/sql/colexec/mergeoffset" 46 "github.com/matrixorigin/matrixone/pkg/sql/colexec/mergeorder" 47 "github.com/matrixorigin/matrixone/pkg/sql/colexec/mergetop" 48 "github.com/matrixorigin/matrixone/pkg/sql/colexec/minus" 49 "github.com/matrixorigin/matrixone/pkg/sql/colexec/offset" 50 "github.com/matrixorigin/matrixone/pkg/sql/colexec/order" 51 "github.com/matrixorigin/matrixone/pkg/sql/colexec/output" 52 "github.com/matrixorigin/matrixone/pkg/sql/colexec/product" 53 "github.com/matrixorigin/matrixone/pkg/sql/colexec/projection" 54 "github.com/matrixorigin/matrixone/pkg/sql/colexec/restrict" 55 "github.com/matrixorigin/matrixone/pkg/sql/colexec/semi" 56 "github.com/matrixorigin/matrixone/pkg/sql/colexec/single" 57 "github.com/matrixorigin/matrixone/pkg/sql/colexec/table_function" 58 "github.com/matrixorigin/matrixone/pkg/sql/colexec/top" 59 "github.com/matrixorigin/matrixone/pkg/sql/colexec/update" 60 "github.com/matrixorigin/matrixone/pkg/vm" 61 "github.com/stretchr/testify/require" 62 ) 63 64 func TestInstructionSerializationCover(t *testing.T) { 65 // ensure that encodeScope and decodeScope can reach every instruction types. 66 testCases := []struct { 67 instruction vm.Instruction 68 ignore bool 69 }{ 70 {instruction: vm.Instruction{Op: vm.Top, Arg: &top.Argument{}}}, 71 {instruction: vm.Instruction{Op: vm.Join, Arg: &join.Argument{Conditions: make([][]*plan.Expr, 2)}}}, 72 {instruction: vm.Instruction{Op: vm.Semi, Arg: &semi.Argument{Conditions: make([][]*plan.Expr, 2)}}}, 73 {instruction: vm.Instruction{Op: vm.Left, Arg: &left.Argument{Conditions: make([][]*plan.Expr, 2)}}}, 74 {instruction: vm.Instruction{Op: vm.Limit, Arg: &limit.Argument{}}}, 75 {instruction: vm.Instruction{Op: vm.Merge, Arg: &merge.Argument{}}}, 76 {instruction: vm.Instruction{Op: vm.Order, Arg: &order.Argument{}}}, 77 {instruction: vm.Instruction{Op: vm.Group, Arg: &group.Argument{}}}, 78 {instruction: vm.Instruction{Op: vm.Output, Arg: &output.Argument{}}, ignore: true}, 79 {instruction: vm.Instruction{Op: vm.Offset, Arg: &offset.Argument{}}}, 80 {instruction: vm.Instruction{Op: vm.Product, Arg: &product.Argument{}}}, 81 {instruction: vm.Instruction{Op: vm.Restrict, Arg: &restrict.Argument{}}}, 82 {instruction: vm.Instruction{Op: vm.Dispatch, Arg: &dispatch.Argument{}}}, 83 {instruction: vm.Instruction{Op: vm.Connector, Arg: &connector.Argument{}}, ignore: true}, 84 {instruction: vm.Instruction{Op: vm.Projection, Arg: &projection.Argument{}}}, 85 {instruction: vm.Instruction{Op: vm.Anti, Arg: &anti.Argument{Conditions: make([][]*plan.Expr, 2)}}}, 86 {instruction: vm.Instruction{Op: vm.Single, Arg: &single.Argument{Conditions: make([][]*plan.Expr, 2)}}}, 87 {instruction: vm.Instruction{Op: vm.Mark, Arg: &mark.Argument{Conditions: make([][]*plan.Expr, 2)}}}, 88 {instruction: vm.Instruction{Op: vm.LoopJoin, Arg: &loopjoin.Argument{}}}, 89 {instruction: vm.Instruction{Op: vm.LoopLeft, Arg: &loopleft.Argument{}}}, 90 {instruction: vm.Instruction{Op: vm.LoopSemi, Arg: &loopsemi.Argument{}}}, 91 {instruction: vm.Instruction{Op: vm.LoopAnti, Arg: &loopanti.Argument{}}}, 92 {instruction: vm.Instruction{Op: vm.LoopSingle, Arg: &loopsingle.Argument{}}}, 93 {instruction: vm.Instruction{Op: vm.LoopMark, Arg: &loopmark.Argument{}}}, 94 {instruction: vm.Instruction{Op: vm.MergeTop, Arg: &mergetop.Argument{}}}, 95 {instruction: vm.Instruction{Op: vm.MergeLimit, Arg: &mergelimit.Argument{}}}, 96 {instruction: vm.Instruction{Op: vm.MergeOrder, Arg: &mergeorder.Argument{}}}, 97 {instruction: vm.Instruction{Op: vm.MergeGroup, Arg: &mergegroup.Argument{}}}, 98 {instruction: vm.Instruction{Op: vm.MergeOffset, Arg: &mergeoffset.Argument{}}}, 99 {instruction: vm.Instruction{Op: vm.Deletion, Arg: &deletion.Argument{}}, ignore: true}, 100 {instruction: vm.Instruction{Op: vm.Insert, Arg: &insert.Argument{}}, ignore: true}, 101 {instruction: vm.Instruction{Op: vm.Update, Arg: &update.Argument{}}, ignore: true}, 102 {instruction: vm.Instruction{Op: vm.External, Arg: &external.Argument{Es: &external.ExternalParam{}}}}, 103 {instruction: vm.Instruction{Op: vm.Minus, Arg: &minus.Argument{}}}, 104 {instruction: vm.Instruction{Op: vm.Intersect, Arg: &intersect.Argument{}}}, 105 {instruction: vm.Instruction{Op: vm.IntersectAll, Arg: &intersectall.Argument{}}}, 106 {instruction: vm.Instruction{Op: vm.HashBuild, Arg: &hashbuild.Argument{}}}, 107 {instruction: vm.Instruction{Op: vm.TableFunction, Arg: &table_function.Argument{}}}, 108 } 109 { 110 typeReached := make([]int, vm.LastInstructionOp) 111 for _, tc := range testCases { 112 typeReached[tc.instruction.Op]++ 113 } 114 for i, num := range typeReached { 115 require.Greater(t, num, 0, fmt.Sprintf("lack of serialization ut for instruction (op is %d)", i)) 116 } 117 } 118 119 for _, tc := range testCases { 120 if tc.ignore { 121 continue 122 } 123 _, encode, err := convertToPipelineInstruction( 124 &tc.instruction, 125 nil, 126 0, 127 ) 128 require.NoError(t, err) 129 _, err = convertToVmInstruction(encode, nil) 130 require.NoError(t, err) 131 } 132 }