Skip to content

Commit

Permalink
fix panic in fillStrhashmap (#19970)
Browse files Browse the repository at this point in the history
fix panic in fillStrhashmap

Approved by: @aunjgr
  • Loading branch information
badboynt1 authored Nov 12, 2024
1 parent 2f86fea commit 11f0305
Showing 1 changed file with 47 additions and 10 deletions.
57 changes: 47 additions & 10 deletions pkg/common/hashmap/strhashmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,39 +100,76 @@ func (itr *strHashmapIterator) encodeHashKeys(vecs []*vector.Vector, start, coun
}
}

func fillStringGroupStrForConstVec(itr *strHashmapIterator, vec *vector.Vector, n int, start int) {
keys := itr.keys
bytes := vec.GetBytesAt(start)
length := uint16(len(bytes))
// can't be const null
if itr.mp.hasNull {
gsp := vec.GetGrouping()
for i := 0; i < n; i++ {
hasGrouping := gsp.Contains(uint64(i + start))
if hasGrouping {
keys[i] = append(keys[i], byte(2))
continue
}
// for "a","bc" and "ab","c", we need to distinct
// this is not null value
keys[i] = append(keys[i], 0)
// give the length
keys[i] = append(keys[i], util.UnsafeToBytes(&length)...)
// append the pure value bytes
keys[i] = append(keys[i], bytes...)
}
} else {
for i := 0; i < n; i++ {
// for "a","bc" and "ab","c", we need to distinct
// give the length
keys[i] = append(keys[i], util.UnsafeToBytes(&length)...)
// append the pure value bytes
keys[i] = append(keys[i], bytes...)
}
}
}

// A NULL C
// 01A101C 9 bytes
// for non-NULL value, give 3 bytes, the first byte is always 0, the last two bytes are the length
// of this value,and then append the true bytes of the value
// for NULL value, just only one byte, give one byte(1)
// these are the rules of multi-cols
// for one col, just give the value bytes
func fillStringGroupStr(itr *strHashmapIterator, vec *vector.Vector, n int, start int, lenCols int) {
func fillStringGroupStr(itr *strHashmapIterator, vec *vector.Vector, lenV int, start int, lenCols int) {
keys := itr.keys
if vec.IsGrouping() {
for i := 0; i < n; i++ {
for i := 0; i < lenV; i++ {
keys[i] = append(keys[i], byte(2))
}
return
}
if vec.IsConstNull() {
if itr.mp.hasNull {
for i := 0; i < n; i++ {
for i := 0; i < lenV; i++ {
keys[i] = append(keys[i], byte(1))
}
} else {
for i := 0; i < n; i++ {
for i := 0; i < lenV; i++ {
itr.zValues[i] = 0
}
}
return
}
if vec.IsConst() {
fillStringGroupStrForConstVec(itr, vec, lenV, start)
return
}

if !vec.GetNulls().Any() {
if itr.mp.hasNull {
gsp := vec.GetGrouping()
va, area := vector.MustVarlenaRawData(vec)
if area == nil {
for i := 0; i < n; i++ {
for i := 0; i < lenV; i++ {
bytes := va[i+start].ByteSlice()
hasGrouping := gsp.Contains(uint64(i + start))
if hasGrouping {
Expand All @@ -149,7 +186,7 @@ func fillStringGroupStr(itr *strHashmapIterator, vec *vector.Vector, n int, star
keys[i] = append(keys[i], bytes...)
}
} else {
for i := 0; i < n; i++ {
for i := 0; i < lenV; i++ {
bytes := va[i+start].GetByteSlice(area)
hasGrouping := gsp.Contains(uint64(i + start))
if hasGrouping {
Expand All @@ -169,7 +206,7 @@ func fillStringGroupStr(itr *strHashmapIterator, vec *vector.Vector, n int, star
} else {
va, area := vector.MustVarlenaRawData(vec)
if area == nil {
for i := 0; i < n; i++ {
for i := 0; i < lenV; i++ {
bytes := va[i+start].ByteSlice()
// for "a","bc" and "ab","c", we need to distinct
// give the length
Expand All @@ -179,7 +216,7 @@ func fillStringGroupStr(itr *strHashmapIterator, vec *vector.Vector, n int, star
keys[i] = append(keys[i], bytes...)
}
} else {
for i := 0; i < n; i++ {
for i := 0; i < lenV; i++ {
bytes := va[i+start].GetByteSlice(area)
// for "a","bc" and "ab","c", we need to distinct
// give the length
Expand All @@ -195,7 +232,7 @@ func fillStringGroupStr(itr *strHashmapIterator, vec *vector.Vector, n int, star
rsp := vec.GetGrouping()
va, area := vector.MustVarlenaRawData(vec)
if area == nil {
for i := 0; i < n; i++ {
for i := 0; i < lenV; i++ {
hasNull := nsp.Contains(uint64(i + start))
hasGrouping := rsp.Contains(uint64(i + start))
if itr.mp.hasNull {
Expand Down Expand Up @@ -229,7 +266,7 @@ func fillStringGroupStr(itr *strHashmapIterator, vec *vector.Vector, n int, star
}
}
} else {
for i := 0; i < n; i++ {
for i := 0; i < lenV; i++ {
hasNull := nsp.Contains(uint64(i + start))
hasGrouping := rsp.Contains(uint64(i + start))
if itr.mp.hasNull {
Expand Down

0 comments on commit 11f0305

Please sign in to comment.