github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/common/hack_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 common
    16  
    17  import (
    18  	"testing"
    19  	"time"
    20  
    21  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/testutils"
    22  	"github.com/stretchr/testify/assert"
    23  )
    24  
    25  type testGenerator struct {
    26  	rows []int
    27  	idx  int
    28  }
    29  
    30  func (g *testGenerator) HasNext() bool {
    31  	return g.idx < len(g.rows)
    32  }
    33  
    34  func (g *testGenerator) Next() uint32 {
    35  	row := g.rows[g.idx]
    36  	g.idx++
    37  	return uint32(row)
    38  }
    39  
    40  func TestDeleteRows(t *testing.T) {
    41  	defer testutils.AfterTest(t)()
    42  	cnt := 10000000
    43  	rows := make([]int, 0)
    44  	deleteCnt := 1
    45  	for i := 0; i < deleteCnt; i++ {
    46  		rows = append(rows, cnt/2-i*2-1)
    47  	}
    48  	generator := new(testGenerator)
    49  	generator.rows = rows
    50  
    51  	buf := make([]int32, cnt)
    52  	for i := range buf {
    53  		buf[i] = int32(i)
    54  	}
    55  
    56  	now := time.Now()
    57  	buf = InplaceDeleteRows(buf, generator).([]int32)
    58  	t.Log(time.Since(now))
    59  	t.Log(len(buf))
    60  	assert.Equal(t, cnt, deleteCnt+len(buf))
    61  }