Skip to content
Snippets Groups Projects
Unverified Commit 22ea6761 authored by chenmingsong's avatar chenmingsong Committed by GitHub
Browse files

add ut for intHashMap and fix intHashMap bugs (#4155)

parent 35848d72
No related branches found
No related tags found
No related merge requests found
...@@ -27,8 +27,11 @@ var wrongUseOfIntHashTable = errors.New(errno.InternalError, "wrong use of IntHa ...@@ -27,8 +27,11 @@ var wrongUseOfIntHashTable = errors.New(errno.InternalError, "wrong use of IntHa
var zeroUint64 []uint64 var zeroUint64 []uint64
var zeroUint32 []uint32
func init() { func init() {
zeroUint64 = make([]uint64, UnitLimit) zeroUint64 = make([]uint64, UnitLimit)
zeroUint32 = make([]uint32, UnitLimit)
} }
// IntHashMap key is int64, value is an uint64 (start from 1) // IntHashMap key is int64, value is an uint64 (start from 1)
......
// Copyright 2021 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package hashmap
import (
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/testutil"
"github.com/matrixorigin/matrixone/pkg/vm/mheap"
"github.com/matrixorigin/matrixone/pkg/vm/mmu/guest"
"github.com/matrixorigin/matrixone/pkg/vm/mmu/host"
"github.com/stretchr/testify/require"
"testing"
)
func TestIntHashMap_Iterator(t *testing.T) {
mp := NewIntHashMap(false)
m := mheap.New(guest.New(1<<30, host.New(1<<30)))
rowCount := 10
bat := &batch.Batch{
Cnt: 1,
Vecs: []*vector.Vector{
testutil.NewVector(rowCount, types.T_int32.ToType(), m, false, []int32{
-1, -1, -1, 2, 2, 2, 3, 3, 3, 4,
}),
testutil.NewVector(rowCount, types.T_uint32.ToType(), m, false, []uint32{
1, 1, 1, 2, 2, 2, 3, 3, 3, 4,
}),
},
Zs: testutil.MakeBatchZs(rowCount, false),
}
itr := mp.NewIterator()
vs, _ := itr.Insert(0, rowCount, bat.Vecs, make([]int32, rowCount))
require.Equal(t, []uint64{1, 1, 1, 2, 2, 2, 3, 3, 3, 4}, vs)
vs, _ = itr.Find(0, rowCount, bat.Vecs, make([]int32, rowCount))
require.Equal(t, []uint64{1, 1, 1, 2, 2, 2, 3, 3, 3, 4}, vs)
bat.Clean(m)
require.Equal(t, int64(0), mheap.Size(m))
}
...@@ -52,6 +52,7 @@ func (itr *intHashMapIterator) Find(start, count int, vecs []*vector.Vector, _ [ ...@@ -52,6 +52,7 @@ func (itr *intHashMapIterator) Find(start, count int, vecs []*vector.Vector, _ [
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
itr.mp.keys[i] = 0 itr.mp.keys[i] = 0
} }
copy(itr.mp.keyOffs[:count], zeroUint32)
}() }()
if err := itr.mp.encodeHashKeys(vecs, start, count); err != nil { if err := itr.mp.encodeHashKeys(vecs, start, count); err != nil {
panic(err) panic(err)
...@@ -66,9 +67,10 @@ func (itr *intHashMapIterator) Insert(start, count int, vecs []*vector.Vector, _ ...@@ -66,9 +67,10 @@ func (itr *intHashMapIterator) Insert(start, count int, vecs []*vector.Vector, _
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
itr.mp.keys[i] = 0 itr.mp.keys[i] = 0
} }
copy(itr.mp.keyOffs[:count], zeroUint32)
}() }()
if itr.mp.hasNull { if !itr.mp.hasNull {
copy(itr.mp.zValues[:count], OneInt64s[:count]) copy(itr.mp.zValues[:count], OneInt64s[:count])
} }
if err := itr.mp.encodeHashKeys(vecs, start, count); err != nil { if err := itr.mp.encodeHashKeys(vecs, start, count); err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment