github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/colexec/preinsertsecondaryindex/preinsertsecondaryindex_test.go (about) 1 // Copyright 2022 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 preinsertsecondaryindex 16 17 import ( 18 "context" 19 "testing" 20 "time" 21 22 "github.com/golang/mock/gomock" 23 "github.com/matrixorigin/matrixone/pkg/container/batch" 24 "github.com/matrixorigin/matrixone/pkg/container/types" 25 "github.com/matrixorigin/matrixone/pkg/container/vector" 26 mock_frontend "github.com/matrixorigin/matrixone/pkg/frontend/test" 27 "github.com/matrixorigin/matrixone/pkg/pb/plan" 28 "github.com/matrixorigin/matrixone/pkg/sql/colexec/value_scan" 29 "github.com/matrixorigin/matrixone/pkg/testutil" 30 "github.com/matrixorigin/matrixone/pkg/vm" 31 "github.com/matrixorigin/matrixone/pkg/vm/engine" 32 "github.com/stretchr/testify/require" 33 ) 34 35 func TestPreInsertSecondaryIndex(t *testing.T) { 36 ctrl := gomock.NewController(t) 37 defer ctrl.Finish() 38 39 ctx := context.TODO() 40 txnOperator := mock_frontend.NewMockTxnOperator(ctrl) 41 txnOperator.EXPECT().Commit(gomock.Any()).Return(nil).AnyTimes() 42 txnOperator.EXPECT().Rollback(ctx).Return(nil).AnyTimes() 43 44 txnClient := mock_frontend.NewMockTxnClient(ctrl) 45 txnClient.EXPECT().New(gomock.Any(), gomock.Any()).Return(txnOperator, nil).AnyTimes() 46 47 eng := mock_frontend.NewMockEngine(ctrl) 48 eng.EXPECT().New(gomock.Any(), gomock.Any()).Return(nil).AnyTimes() 49 eng.EXPECT().Hints().Return(engine.Hints{ 50 CommitOrRollbackTimeout: time.Second, 51 }).AnyTimes() 52 53 proc := testutil.NewProc() 54 proc.TxnClient = txnClient 55 proc.Ctx = ctx 56 // create table t1( 57 // col1 int primary key, 58 // col2 int key, 59 // col3 int 60 // ); 61 // (1, 11, 23) 62 // (2, 22, 23) 63 // (3, 33, 23) 64 testBatch := &batch.Batch{ 65 Vecs: []*vector.Vector{ 66 testutil.MakeInt64Vector([]int64{1, 2, 3}, nil), 67 testutil.MakeInt64Vector([]int64{11, 22, 33}, nil), 68 testutil.MakeInt64Vector([]int64{23, 23, 23}, nil), 69 }, 70 Cnt: 1, 71 } 72 testBatch.SetRowCount(3) 73 74 argument := Argument{ 75 PreInsertCtx: &plan.PreInsertUkCtx{ 76 Columns: []int32{1, 0}, 77 PkColumn: 0, 78 PkType: plan.Type{Id: int32(types.T_uint64), Width: types.T_int64.ToType().Width, Scale: -1}, 79 UkType: plan.Type{Id: int32(types.T_uint64), Width: types.T_int64.ToType().Width, Scale: -1}, 80 }, 81 OperatorBase: vm.OperatorBase{ 82 OperatorInfo: vm.OperatorInfo{ 83 Idx: 0, 84 IsFirst: false, 85 IsLast: false, 86 }, 87 }, 88 } 89 90 types.T_int64.ToType() 91 resetChildren(&argument, testBatch) 92 _, err := argument.Call(proc) 93 require.NoError(t, err) 94 } 95 96 func resetChildren(arg *Argument, bat *batch.Batch) { 97 arg.SetChildren( 98 []vm.Operator{ 99 &value_scan.Argument{ 100 Batchs: []*batch.Batch{bat}, 101 }, 102 }) 103 }