MCPcopy
hub / github.com/uber/aresdb / Slice

Method Slice

memstore/vector_party.go:312–369  ·  view source on GitHub ↗

Slice slice the vector party into the interval of [startRow, startRow+numRows)

(startRow int, numRows int)

Source from the content-addressed store, hash-verified

310
311// Slice slice the vector party into the interval of [startRow, startRow+numRows)
312func (vp *cVectorParty) Slice(startRow int, numRows int) (vector common.SlicedVector) {
313 beginIndex := startRow
314 // size is the number of entries in the vector,
315 // size != numRows when compressed,
316 // although here size is initialized as if vector is uncompressed.
317 size := vp.length - beginIndex
318 if size < 0 {
319 size = 0
320 }
321 if size > numRows {
322 size = numRows
323 }
324
325 mode := vp.GetMode()
326 if mode == common.AllValuesDefault && size > 0 {
327 size = 1
328 } else if mode == common.HasCountVector {
329 // find the indexes [beginIndex, endIndex) based on [startRow, startRow + numRows)
330 lowerCount := uint32(startRow)
331 upperCount := uint32(startRow + numRows)
332 beginIndex = vp.counts.UpperBound(0, vp.counts.Size, unsafe.Pointer(&lowerCount)) - 1
333 endIndex := vp.counts.LowerBound(beginIndex, vp.counts.Size, unsafe.Pointer(&upperCount))
334 // subtract endIndex by 1 when endIndex points to vp.length+1
335 if endIndex == vp.counts.Size {
336 endIndex -= 1
337 }
338 size = endIndex - beginIndex
339 }
340
341 vector = common.SlicedVector{
342 Values: make([]interface{}, size),
343 Counts: make([]int, size),
344 }
345
346 for i := 0; i < size; i++ {
347 if mode == common.AllValuesDefault {
348 vector.Values[i] = vp.defaultValue.ConvertToHumanReadable(vp.dataType)
349 vector.Counts[i] = numRows
350 if vector.Counts[i] > vp.length {
351 vector.Counts[i] = vp.length
352 }
353 } else if mode == common.HasCountVector {
354 // compressed
355 vector.Values[i] = vp.GetDataValue(beginIndex + i).ConvertToHumanReadable(vp.dataType)
356 count := int(*(*uint32)(vp.counts.GetValue(beginIndex + i + 1))) - startRow
357 if count > numRows {
358 count = numRows
359 }
360 vector.Counts[i] = count
361 } else {
362 // uncompressed
363 vector.Values[i] = vp.GetDataValue(beginIndex + i).ConvertToHumanReadable(vp.dataType)
364 vector.Counts[i] = i + 1
365 }
366 }
367
368 return vector
369}

Callers

nothing calls this directly

Calls 6

GetModeMethod · 0.95
GetDataValueMethod · 0.95
UpperBoundMethod · 0.80
LowerBoundMethod · 0.80
GetValueMethod · 0.65

Tested by

no test coverage detected