2024-05-12 14:33:29 +00:00
|
|
|
package logstorage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
"slices"
|
2024-06-05 01:18:12 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2024-05-13 23:49:20 +00:00
|
|
|
"sync/atomic"
|
2024-05-12 14:33:29 +00:00
|
|
|
"time"
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/decimal"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/encoding"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fastnum"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
2024-05-13 23:49:20 +00:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/slicesutil"
|
2024-05-12 14:33:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// blockResult holds results for a single block of log entries.
|
|
|
|
//
|
|
|
|
// It is expected that its contents is accessed only from a single goroutine at a time.
|
|
|
|
type blockResult struct {
|
2024-09-25 14:16:53 +00:00
|
|
|
// rowsLen is the number of rows in the given blockResult.
|
|
|
|
rowsLen int
|
|
|
|
|
|
|
|
// bs is the associated blockSearch for the given blockResult.
|
|
|
|
//
|
|
|
|
// bs is nil for the blockResult constructed by pipes.
|
|
|
|
bs *blockSearch
|
|
|
|
|
|
|
|
// bm is the associated bitmap for the given blockResult.
|
|
|
|
//
|
|
|
|
// bm is nil for the blockResult constructed by pipes.
|
|
|
|
bm *bitmap
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
// a holds all the bytes behind the requested column values in the block.
|
|
|
|
a arena
|
2024-05-12 14:33:29 +00:00
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
// valuesBuf holds all the requested column values in the block.
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf []string
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
// timestampsBuf contains cached timestamps for the selected log entries in the block.
|
|
|
|
//
|
|
|
|
// timestamps must be obtained via blockResult.getTimestamps() call.
|
|
|
|
timestampsBuf []int64
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
// csBuf contains requested columns.
|
|
|
|
csBuf []blockResultColumn
|
|
|
|
|
2024-05-25 19:36:16 +00:00
|
|
|
// csEmpty contains non-existing columns, which were referenced via getColumnByName()
|
|
|
|
csEmpty []blockResultColumn
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
// cs contains cached pointers to requested columns returned from getColumns() if csInitialized=true.
|
|
|
|
cs []*blockResultColumn
|
|
|
|
|
|
|
|
// csInitialized is set to true if cs is properly initialized and can be returned from getColumns().
|
|
|
|
csInitialized bool
|
2024-05-25 19:36:16 +00:00
|
|
|
|
|
|
|
fvecs []filteredValuesEncodedCreator
|
|
|
|
svecs []searchValuesEncodedCreator
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (br *blockResult) reset() {
|
2024-09-25 14:16:53 +00:00
|
|
|
br.rowsLen = 0
|
|
|
|
|
|
|
|
br.cs = nil
|
|
|
|
br.bm = nil
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
br.a.reset()
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
clear(br.valuesBuf)
|
|
|
|
br.valuesBuf = br.valuesBuf[:0]
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
br.timestampsBuf = br.timestampsBuf[:0]
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
clear(br.csBuf)
|
|
|
|
br.csBuf = br.csBuf[:0]
|
|
|
|
|
2024-05-25 19:36:16 +00:00
|
|
|
clear(br.csEmpty)
|
|
|
|
br.csEmpty = br.csEmpty[:0]
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
clear(br.cs)
|
|
|
|
br.cs = br.cs[:0]
|
|
|
|
|
|
|
|
br.csInitialized = false
|
2024-05-25 19:36:16 +00:00
|
|
|
|
|
|
|
clear(br.fvecs)
|
|
|
|
br.fvecs = br.fvecs[:0]
|
|
|
|
|
|
|
|
clear(br.svecs)
|
|
|
|
br.svecs = br.svecs[:0]
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
// clone returns a clone of br, which owns its own data.
|
2024-05-12 14:33:29 +00:00
|
|
|
func (br *blockResult) clone() *blockResult {
|
|
|
|
brNew := &blockResult{}
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
brNew.rowsLen = br.rowsLen
|
|
|
|
|
|
|
|
// do not clone br.cs, since it may be updated at any time.
|
|
|
|
// do not clone br.bm, since it may be updated at any time.
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
cs := br.getColumns()
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
// Pre-populate values in every column in order to properly calculate the needed backing buffer size below.
|
|
|
|
for _, c := range cs {
|
|
|
|
_ = c.getValues(br)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the backing buffer size needed for cloning column values.
|
2024-05-12 14:33:29 +00:00
|
|
|
bufLen := 0
|
|
|
|
for _, c := range cs {
|
|
|
|
bufLen += c.neededBackingBufLen()
|
|
|
|
}
|
2024-05-20 02:08:30 +00:00
|
|
|
brNew.a.preallocate(bufLen)
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
valuesBufLen := 0
|
|
|
|
for _, c := range cs {
|
|
|
|
valuesBufLen += c.neededBackingValuesBufLen()
|
|
|
|
}
|
|
|
|
brNew.valuesBuf = make([]string, 0, valuesBufLen)
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
srcTimestamps := br.getTimestamps()
|
|
|
|
brNew.timestampsBuf = make([]int64, len(srcTimestamps))
|
|
|
|
copy(brNew.timestampsBuf, srcTimestamps)
|
|
|
|
brNew.checkTimestampsLen()
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
csNew := make([]blockResultColumn, len(cs))
|
|
|
|
for i, c := range cs {
|
|
|
|
csNew[i] = c.clone(brNew)
|
|
|
|
}
|
|
|
|
brNew.csBuf = csNew
|
|
|
|
|
2024-05-25 19:36:16 +00:00
|
|
|
// do not clone br.csEmpty - it will be populated by the caller via getColumnByName().
|
|
|
|
|
|
|
|
// do not clone br.fvecs and br.svecs, since they may point to external data.
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
return brNew
|
|
|
|
}
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
// initFromFilterAllColumns initializes br from brSrc by copying rows identified by set bits at bm.
|
2024-05-20 02:08:30 +00:00
|
|
|
//
|
|
|
|
// The br is valid until brSrc or bm is updated.
|
|
|
|
func (br *blockResult) initFromFilterAllColumns(brSrc *blockResult, bm *bitmap) {
|
|
|
|
br.reset()
|
2024-05-12 14:33:29 +00:00
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
srcTimestamps := brSrc.getTimestamps()
|
|
|
|
dstTimestamps := br.timestampsBuf[:0]
|
2024-05-20 02:08:30 +00:00
|
|
|
bm.forEachSetBitReadonly(func(idx int) {
|
|
|
|
dstTimestamps = append(dstTimestamps, srcTimestamps[idx])
|
|
|
|
})
|
2024-09-25 14:16:53 +00:00
|
|
|
br.timestampsBuf = dstTimestamps
|
|
|
|
br.rowsLen = len(br.timestampsBuf)
|
2024-05-20 02:08:30 +00:00
|
|
|
|
|
|
|
for _, cSrc := range brSrc.getColumns() {
|
|
|
|
br.appendFilteredColumn(brSrc, cSrc, bm)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-25 19:36:16 +00:00
|
|
|
// appendFilteredColumn adds cSrc with the given bm filter to br.
|
|
|
|
//
|
|
|
|
// the br is valid until brSrc, cSrc or bm is updated.
|
2024-05-20 02:08:30 +00:00
|
|
|
func (br *blockResult) appendFilteredColumn(brSrc *blockResult, cSrc *blockResultColumn, bm *bitmap) {
|
2024-09-25 14:16:53 +00:00
|
|
|
if br.rowsLen == 0 {
|
2024-05-20 02:08:30 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
cDst := blockResultColumn{
|
|
|
|
name: cSrc.name,
|
|
|
|
}
|
|
|
|
|
|
|
|
if cSrc.isConst {
|
|
|
|
cDst.isConst = true
|
|
|
|
cDst.valuesEncoded = cSrc.valuesEncoded
|
|
|
|
} else if cSrc.isTime {
|
|
|
|
cDst.isTime = true
|
|
|
|
} else {
|
|
|
|
cDst.valueType = cSrc.valueType
|
|
|
|
cDst.minValue = cSrc.minValue
|
|
|
|
cDst.maxValue = cSrc.maxValue
|
|
|
|
cDst.dictValues = cSrc.dictValues
|
2024-05-25 19:36:16 +00:00
|
|
|
br.fvecs = append(br.fvecs, filteredValuesEncodedCreator{
|
|
|
|
br: brSrc,
|
|
|
|
c: cSrc,
|
|
|
|
bm: bm,
|
|
|
|
})
|
|
|
|
cDst.valuesEncodedCreator = &br.fvecs[len(br.fvecs)-1]
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
br.csBuf = append(br.csBuf, cDst)
|
|
|
|
br.csInitialized = false
|
|
|
|
}
|
2024-05-12 14:33:29 +00:00
|
|
|
|
2024-05-25 19:36:16 +00:00
|
|
|
type filteredValuesEncodedCreator struct {
|
|
|
|
br *blockResult
|
|
|
|
c *blockResultColumn
|
|
|
|
bm *bitmap
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fvec *filteredValuesEncodedCreator) newValuesEncoded(br *blockResult) []string {
|
|
|
|
valuesEncodedSrc := fvec.c.getValuesEncoded(fvec.br)
|
|
|
|
|
|
|
|
valuesBuf := br.valuesBuf
|
|
|
|
valuesBufLen := len(valuesBuf)
|
|
|
|
fvec.bm.forEachSetBitReadonly(func(idx int) {
|
|
|
|
valuesBuf = append(valuesBuf, valuesEncodedSrc[idx])
|
|
|
|
})
|
|
|
|
br.valuesBuf = valuesBuf
|
|
|
|
|
|
|
|
return valuesBuf[valuesBufLen:]
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
// cloneValues clones the given values into br and returns the cloned values.
|
|
|
|
func (br *blockResult) cloneValues(values []string) []string {
|
|
|
|
if values == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
valuesBufLen := len(br.valuesBuf)
|
|
|
|
for _, v := range values {
|
|
|
|
br.addValue(v)
|
|
|
|
}
|
|
|
|
return br.valuesBuf[valuesBufLen:]
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func (br *blockResult) addValue(v string) {
|
|
|
|
valuesBuf := br.valuesBuf
|
|
|
|
if len(valuesBuf) > 0 && v == valuesBuf[len(valuesBuf)-1] {
|
|
|
|
v = valuesBuf[len(valuesBuf)-1]
|
|
|
|
} else {
|
|
|
|
v = br.a.copyString(v)
|
|
|
|
}
|
|
|
|
br.valuesBuf = append(br.valuesBuf, v)
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// sizeBytes returns the size of br in bytes.
|
|
|
|
func (br *blockResult) sizeBytes() int {
|
|
|
|
n := int(unsafe.Sizeof(*br))
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
n += br.a.sizeBytes()
|
2024-05-12 14:33:29 +00:00
|
|
|
n += cap(br.valuesBuf) * int(unsafe.Sizeof(br.valuesBuf[0]))
|
2024-09-25 14:16:53 +00:00
|
|
|
n += cap(br.timestampsBuf) * int(unsafe.Sizeof(br.timestampsBuf[0]))
|
2024-05-12 14:33:29 +00:00
|
|
|
n += cap(br.csBuf) * int(unsafe.Sizeof(br.csBuf[0]))
|
|
|
|
n += cap(br.cs) * int(unsafe.Sizeof(br.cs[0]))
|
|
|
|
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
// setResultColumns sets the given rcs as br columns.
|
|
|
|
//
|
2024-05-20 02:08:30 +00:00
|
|
|
// The br is valid only until rcs are modified.
|
2024-09-25 14:16:53 +00:00
|
|
|
func (br *blockResult) setResultColumns(rcs []resultColumn, rowsLen int) {
|
2024-05-12 14:33:29 +00:00
|
|
|
br.reset()
|
2024-05-20 02:08:30 +00:00
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
br.rowsLen = rowsLen
|
2024-05-12 14:33:29 +00:00
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
for i := range rcs {
|
|
|
|
br.addResultColumn(&rcs[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (br *blockResult) addResultColumn(rc *resultColumn) {
|
2024-09-25 14:16:53 +00:00
|
|
|
if len(rc.values) != br.rowsLen {
|
|
|
|
logger.Panicf("BUG: column %q must contain %d rows, but it contains %d rows", rc.name, br.rowsLen, len(rc.values))
|
2024-05-20 02:08:30 +00:00
|
|
|
}
|
|
|
|
if areConstValues(rc.values) {
|
|
|
|
// This optimization allows reducing memory usage after br cloning
|
|
|
|
br.csBuf = append(br.csBuf, blockResultColumn{
|
|
|
|
name: rc.name,
|
|
|
|
isConst: true,
|
|
|
|
valuesEncoded: rc.values[:1],
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
br.csBuf = append(br.csBuf, blockResultColumn{
|
|
|
|
name: rc.name,
|
|
|
|
valueType: valueTypeString,
|
|
|
|
valuesEncoded: rc.values,
|
|
|
|
})
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
br.csInitialized = false
|
|
|
|
}
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
// initAllColumns initializes all the columns in br.
|
|
|
|
func (br *blockResult) initAllColumns() {
|
|
|
|
unneededColumnNames := br.bs.bsw.so.unneededColumnNames
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
if !slices.Contains(unneededColumnNames, "_time") {
|
|
|
|
// Add _time column
|
|
|
|
br.addTimeColumn()
|
|
|
|
}
|
|
|
|
|
2024-06-20 01:08:07 +00:00
|
|
|
if !slices.Contains(unneededColumnNames, "_stream_id") {
|
|
|
|
// Add _stream_id column
|
2024-09-25 14:16:53 +00:00
|
|
|
br.addStreamIDColumn()
|
2024-06-20 01:08:07 +00:00
|
|
|
}
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
if !slices.Contains(unneededColumnNames, "_stream") {
|
|
|
|
// Add _stream column
|
2024-09-25 14:16:53 +00:00
|
|
|
if !br.addStreamColumn() {
|
2024-06-20 01:08:07 +00:00
|
|
|
// Skip the current block, since the associated stream tags are missing
|
2024-05-12 14:33:29 +00:00
|
|
|
br.reset()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !slices.Contains(unneededColumnNames, "_msg") {
|
|
|
|
// Add _msg column
|
2024-10-13 12:28:59 +00:00
|
|
|
v := br.bs.getConstColumnValue("_msg")
|
2024-05-12 14:33:29 +00:00
|
|
|
if v != "" {
|
|
|
|
br.addConstColumn("_msg", v)
|
2024-10-13 12:28:59 +00:00
|
|
|
} else if ch := br.bs.getColumnHeader("_msg"); ch != nil {
|
2024-09-25 14:16:53 +00:00
|
|
|
br.addColumn(ch)
|
2024-05-12 14:33:29 +00:00
|
|
|
} else {
|
|
|
|
br.addConstColumn("_msg", "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add other const columns
|
2024-10-17 22:21:20 +00:00
|
|
|
csh := br.bs.getColumnsHeader()
|
|
|
|
for _, cc := range csh.constColumns {
|
2024-10-13 12:28:59 +00:00
|
|
|
if cc.Name == "" {
|
2024-05-12 14:33:29 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !slices.Contains(unneededColumnNames, cc.Name) {
|
|
|
|
br.addConstColumn(cc.Name, cc.Value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add other non-const columns
|
2024-10-17 22:21:20 +00:00
|
|
|
chs := csh.columnHeaders
|
2024-05-12 14:33:29 +00:00
|
|
|
for i := range chs {
|
|
|
|
ch := &chs[i]
|
2024-10-13 12:28:59 +00:00
|
|
|
if ch.name == "" {
|
2024-05-12 14:33:29 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !slices.Contains(unneededColumnNames, ch.name) {
|
2024-09-25 14:16:53 +00:00
|
|
|
br.addColumn(ch)
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-25 19:36:16 +00:00
|
|
|
|
|
|
|
br.csInitFast()
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
// initRequestedColumns initialized only requested columns in br.
|
|
|
|
func (br *blockResult) initRequestedColumns() {
|
|
|
|
for _, columnName := range br.bs.bsw.so.neededColumnNames {
|
2024-05-12 14:33:29 +00:00
|
|
|
switch columnName {
|
2024-06-20 01:08:07 +00:00
|
|
|
case "_stream_id":
|
2024-09-25 14:16:53 +00:00
|
|
|
br.addStreamIDColumn()
|
2024-05-12 14:33:29 +00:00
|
|
|
case "_stream":
|
2024-09-25 14:16:53 +00:00
|
|
|
if !br.addStreamColumn() {
|
2024-05-12 14:33:29 +00:00
|
|
|
// Skip the current block, since the associated stream tags are missing.
|
|
|
|
br.reset()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
case "_time":
|
|
|
|
br.addTimeColumn()
|
|
|
|
default:
|
2024-10-13 12:28:59 +00:00
|
|
|
v := br.bs.getConstColumnValue(columnName)
|
2024-05-12 14:33:29 +00:00
|
|
|
if v != "" {
|
|
|
|
br.addConstColumn(columnName, v)
|
2024-10-13 12:28:59 +00:00
|
|
|
} else if ch := br.bs.getColumnHeader(columnName); ch != nil {
|
2024-09-25 14:16:53 +00:00
|
|
|
br.addColumn(ch)
|
2024-05-12 14:33:29 +00:00
|
|
|
} else {
|
|
|
|
br.addConstColumn(columnName, "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-05-25 19:36:16 +00:00
|
|
|
|
|
|
|
br.csInitFast()
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
// mustInit initializes br with the given bs and bm.
|
|
|
|
//
|
|
|
|
// br is valid until bs or bm changes.
|
2024-05-12 14:33:29 +00:00
|
|
|
func (br *blockResult) mustInit(bs *blockSearch, bm *bitmap) {
|
|
|
|
br.reset()
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
br.rowsLen = bm.onesCount()
|
|
|
|
if br.rowsLen == 0 {
|
2024-05-12 14:33:29 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
br.bs = bs
|
|
|
|
br.bm = bm
|
|
|
|
}
|
|
|
|
|
2024-09-26 20:22:21 +00:00
|
|
|
// intersectsTimeRange returns true if br timestamps intersect (minTimestamp .. maxTimestamp) time range.
|
|
|
|
func (br *blockResult) intersectsTimeRange(minTimestamp, maxTimestamp int64) bool {
|
|
|
|
return minTimestamp < br.getMaxTimestamp(minTimestamp) && maxTimestamp > br.getMinTimestamp(maxTimestamp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (br *blockResult) getMinTimestamp(minTimestamp int64) int64 {
|
|
|
|
if br.bs != nil {
|
|
|
|
bh := &br.bs.bsw.bh
|
|
|
|
if bh.rowsCount == uint64(br.rowsLen) {
|
|
|
|
return min(minTimestamp, bh.timestampsHeader.minTimestamp)
|
|
|
|
}
|
|
|
|
if minTimestamp <= bh.timestampsHeader.minTimestamp {
|
|
|
|
return minTimestamp
|
|
|
|
}
|
2024-09-25 14:16:53 +00:00
|
|
|
}
|
|
|
|
|
2024-09-26 20:22:21 +00:00
|
|
|
// Slow path - need to scan timestamps
|
2024-09-25 14:16:53 +00:00
|
|
|
timestamps := br.getTimestamps()
|
2024-09-26 20:22:21 +00:00
|
|
|
for _, timestamp := range timestamps {
|
|
|
|
if timestamp < minTimestamp {
|
|
|
|
minTimestamp = timestamp
|
2024-09-25 14:16:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return minTimestamp
|
|
|
|
}
|
|
|
|
|
2024-09-26 20:22:21 +00:00
|
|
|
func (br *blockResult) getMaxTimestamp(maxTimestamp int64) int64 {
|
|
|
|
if br.bs != nil {
|
|
|
|
bh := &br.bs.bsw.bh
|
|
|
|
if bh.rowsCount == uint64(br.rowsLen) {
|
|
|
|
return max(maxTimestamp, bh.timestampsHeader.maxTimestamp)
|
|
|
|
}
|
|
|
|
if maxTimestamp >= bh.timestampsHeader.maxTimestamp {
|
|
|
|
return maxTimestamp
|
|
|
|
}
|
2024-09-25 14:16:53 +00:00
|
|
|
}
|
|
|
|
|
2024-09-26 20:22:21 +00:00
|
|
|
// Slow path - need to scan timestamps
|
2024-09-25 14:16:53 +00:00
|
|
|
timestamps := br.getTimestamps()
|
2024-09-26 20:22:21 +00:00
|
|
|
for i := len(timestamps) - 1; i >= 0; i-- {
|
2024-09-25 14:16:53 +00:00
|
|
|
if timestamps[i] > maxTimestamp {
|
|
|
|
maxTimestamp = timestamps[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return maxTimestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (br *blockResult) getTimestamps() []int64 {
|
|
|
|
if br.rowsLen > 0 && len(br.timestampsBuf) == 0 {
|
|
|
|
br.initTimestamps()
|
|
|
|
}
|
|
|
|
return br.timestampsBuf
|
|
|
|
}
|
|
|
|
|
|
|
|
func (br *blockResult) initTimestamps() {
|
|
|
|
if br.bs == nil {
|
|
|
|
br.timestampsBuf = fastnum.AppendInt64Zeros(br.timestampsBuf[:0], br.rowsLen)
|
2024-05-13 23:49:20 +00:00
|
|
|
return
|
|
|
|
}
|
2024-05-12 14:33:29 +00:00
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
srcTimestamps := br.bs.getTimestamps()
|
|
|
|
if br.bm.areAllBitsSet() {
|
2024-05-12 14:33:29 +00:00
|
|
|
// Fast path - all the rows in the block are selected, so copy all the timestamps without any filtering.
|
2024-09-25 14:16:53 +00:00
|
|
|
br.timestampsBuf = append(br.timestampsBuf[:0], srcTimestamps...)
|
|
|
|
br.checkTimestampsLen()
|
2024-05-12 14:33:29 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slow path - copy only the needed timestamps to br according to filter results.
|
2024-09-25 14:16:53 +00:00
|
|
|
dstTimestamps := br.timestampsBuf[:0]
|
|
|
|
br.bm.forEachSetBitReadonly(func(idx int) {
|
2024-05-12 14:33:29 +00:00
|
|
|
ts := srcTimestamps[idx]
|
|
|
|
dstTimestamps = append(dstTimestamps, ts)
|
|
|
|
})
|
2024-09-25 14:16:53 +00:00
|
|
|
br.timestampsBuf = dstTimestamps
|
|
|
|
br.checkTimestampsLen()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (br *blockResult) checkTimestampsLen() {
|
|
|
|
if len(br.timestampsBuf) != br.rowsLen {
|
|
|
|
logger.Panicf("BUG: unexpected number of timestamps; got %d; want %d", len(br.timestampsBuf), br.rowsLen)
|
|
|
|
}
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func (br *blockResult) newValuesEncodedFromColumnHeader(bs *blockSearch, bm *bitmap, ch *columnHeader) []string {
|
|
|
|
valuesBufLen := len(br.valuesBuf)
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
switch ch.valueType {
|
|
|
|
case valueTypeString:
|
2024-05-20 02:08:30 +00:00
|
|
|
visitValuesReadonly(bs, ch, bm, br.addValue)
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeDict:
|
2024-05-20 02:08:30 +00:00
|
|
|
visitValuesReadonly(bs, ch, bm, func(v string) {
|
2024-05-12 14:33:29 +00:00
|
|
|
if len(v) != 1 {
|
|
|
|
logger.Panicf("FATAL: %s: unexpected dict value size for column %q; got %d bytes; want 1 byte", bs.partPath(), ch.name, len(v))
|
|
|
|
}
|
|
|
|
dictIdx := v[0]
|
2024-05-20 02:08:30 +00:00
|
|
|
if int(dictIdx) >= len(ch.valuesDict.values) {
|
|
|
|
logger.Panicf("FATAL: %s: too big dict index for column %q: %d; should be smaller than %d", bs.partPath(), ch.name, dictIdx, len(ch.valuesDict.values))
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
2024-05-20 02:08:30 +00:00
|
|
|
br.addValue(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
})
|
|
|
|
case valueTypeUint8:
|
2024-05-20 02:08:30 +00:00
|
|
|
visitValuesReadonly(bs, ch, bm, func(v string) {
|
2024-05-12 14:33:29 +00:00
|
|
|
if len(v) != 1 {
|
|
|
|
logger.Panicf("FATAL: %s: unexpected size for uint8 column %q; got %d bytes; want 1 byte", bs.partPath(), ch.name, len(v))
|
|
|
|
}
|
2024-05-20 02:08:30 +00:00
|
|
|
br.addValue(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
})
|
|
|
|
case valueTypeUint16:
|
2024-05-20 02:08:30 +00:00
|
|
|
visitValuesReadonly(bs, ch, bm, func(v string) {
|
2024-05-12 14:33:29 +00:00
|
|
|
if len(v) != 2 {
|
|
|
|
logger.Panicf("FATAL: %s: unexpected size for uint16 column %q; got %d bytes; want 2 bytes", bs.partPath(), ch.name, len(v))
|
|
|
|
}
|
2024-05-20 02:08:30 +00:00
|
|
|
br.addValue(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
})
|
|
|
|
case valueTypeUint32:
|
2024-05-20 02:08:30 +00:00
|
|
|
visitValuesReadonly(bs, ch, bm, func(v string) {
|
2024-05-12 14:33:29 +00:00
|
|
|
if len(v) != 4 {
|
|
|
|
logger.Panicf("FATAL: %s: unexpected size for uint32 column %q; got %d bytes; want 4 bytes", bs.partPath(), ch.name, len(v))
|
|
|
|
}
|
2024-05-20 02:08:30 +00:00
|
|
|
br.addValue(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
})
|
|
|
|
case valueTypeUint64:
|
2024-05-20 02:08:30 +00:00
|
|
|
visitValuesReadonly(bs, ch, bm, func(v string) {
|
2024-05-12 14:33:29 +00:00
|
|
|
if len(v) != 8 {
|
|
|
|
logger.Panicf("FATAL: %s: unexpected size for uint64 column %q; got %d bytes; want 8 bytes", bs.partPath(), ch.name, len(v))
|
|
|
|
}
|
2024-05-20 02:08:30 +00:00
|
|
|
br.addValue(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
})
|
|
|
|
case valueTypeFloat64:
|
2024-05-20 02:08:30 +00:00
|
|
|
visitValuesReadonly(bs, ch, bm, func(v string) {
|
2024-05-12 14:33:29 +00:00
|
|
|
if len(v) != 8 {
|
|
|
|
logger.Panicf("FATAL: %s: unexpected size for float64 column %q; got %d bytes; want 8 bytes", bs.partPath(), ch.name, len(v))
|
|
|
|
}
|
2024-05-20 02:08:30 +00:00
|
|
|
br.addValue(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
})
|
|
|
|
case valueTypeIPv4:
|
2024-05-20 02:08:30 +00:00
|
|
|
visitValuesReadonly(bs, ch, bm, func(v string) {
|
2024-05-12 14:33:29 +00:00
|
|
|
if len(v) != 4 {
|
|
|
|
logger.Panicf("FATAL: %s: unexpected size for ipv4 column %q; got %d bytes; want 4 bytes", bs.partPath(), ch.name, len(v))
|
|
|
|
}
|
2024-05-20 02:08:30 +00:00
|
|
|
br.addValue(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
})
|
|
|
|
case valueTypeTimestampISO8601:
|
2024-05-20 02:08:30 +00:00
|
|
|
visitValuesReadonly(bs, ch, bm, func(v string) {
|
2024-05-12 14:33:29 +00:00
|
|
|
if len(v) != 8 {
|
|
|
|
logger.Panicf("FATAL: %s: unexpected size for timestmap column %q; got %d bytes; want 8 bytes", bs.partPath(), ch.name, len(v))
|
|
|
|
}
|
2024-05-20 02:08:30 +00:00
|
|
|
br.addValue(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
})
|
|
|
|
default:
|
|
|
|
logger.Panicf("FATAL: %s: unknown valueType=%d for column %q", bs.partPath(), ch.valueType, ch.name)
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
return br.valuesBuf[valuesBufLen:]
|
|
|
|
}
|
2024-05-12 14:33:29 +00:00
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
// addColumn adds column for the given ch to br.
|
|
|
|
//
|
2024-09-25 14:16:53 +00:00
|
|
|
// The added column is valid until ch is changed.
|
|
|
|
func (br *blockResult) addColumn(ch *columnHeader) {
|
2024-05-12 14:33:29 +00:00
|
|
|
br.csBuf = append(br.csBuf, blockResultColumn{
|
2024-05-20 02:08:30 +00:00
|
|
|
name: getCanonicalColumnName(ch.name),
|
|
|
|
valueType: ch.valueType,
|
|
|
|
minValue: ch.minValue,
|
|
|
|
maxValue: ch.maxValue,
|
|
|
|
dictValues: ch.valuesDict.values,
|
2024-05-12 14:33:29 +00:00
|
|
|
})
|
2024-05-25 19:36:16 +00:00
|
|
|
c := &br.csBuf[len(br.csBuf)-1]
|
|
|
|
|
|
|
|
br.svecs = append(br.svecs, searchValuesEncodedCreator{
|
2024-09-25 14:16:53 +00:00
|
|
|
bs: br.bs,
|
|
|
|
bm: br.bm,
|
2024-05-25 19:36:16 +00:00
|
|
|
ch: ch,
|
|
|
|
})
|
|
|
|
c.valuesEncodedCreator = &br.svecs[len(br.svecs)-1]
|
2024-05-12 14:33:29 +00:00
|
|
|
br.csInitialized = false
|
|
|
|
}
|
|
|
|
|
2024-05-25 19:36:16 +00:00
|
|
|
type searchValuesEncodedCreator struct {
|
|
|
|
bs *blockSearch
|
|
|
|
bm *bitmap
|
|
|
|
ch *columnHeader
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svec *searchValuesEncodedCreator) newValuesEncoded(br *blockResult) []string {
|
|
|
|
return br.newValuesEncodedFromColumnHeader(svec.bs, svec.bm, svec.ch)
|
|
|
|
}
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
func (br *blockResult) addTimeColumn() {
|
|
|
|
br.csBuf = append(br.csBuf, blockResultColumn{
|
|
|
|
name: "_time",
|
|
|
|
isTime: true,
|
|
|
|
})
|
|
|
|
br.csInitialized = false
|
|
|
|
}
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
func (br *blockResult) addStreamIDColumn() {
|
2024-06-20 01:08:07 +00:00
|
|
|
bb := bbPool.Get()
|
2024-09-25 14:16:53 +00:00
|
|
|
bb.B = br.bs.bsw.bh.streamID.marshalString(bb.B)
|
2024-06-20 01:08:07 +00:00
|
|
|
br.addConstColumn("_stream_id", bytesutil.ToUnsafeString(bb.B))
|
|
|
|
bbPool.Put(bb)
|
|
|
|
}
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
func (br *blockResult) addStreamColumn() bool {
|
|
|
|
streamStr := br.bs.getStreamStr()
|
2024-09-24 18:51:13 +00:00
|
|
|
if streamStr == "" {
|
2024-06-11 15:50:32 +00:00
|
|
|
return false
|
|
|
|
}
|
2024-09-24 18:51:13 +00:00
|
|
|
br.addConstColumn("_stream", streamStr)
|
2024-05-12 14:33:29 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (br *blockResult) addConstColumn(name, value string) {
|
2024-05-20 02:08:30 +00:00
|
|
|
nameCopy := br.a.copyString(name)
|
2024-05-12 14:33:29 +00:00
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
valuesBufLen := len(br.valuesBuf)
|
|
|
|
br.addValue(value)
|
|
|
|
valuesEncoded := br.valuesBuf[valuesBufLen:]
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
br.csBuf = append(br.csBuf, blockResultColumn{
|
2024-05-20 02:08:30 +00:00
|
|
|
name: nameCopy,
|
2024-05-12 14:33:29 +00:00
|
|
|
isConst: true,
|
2024-05-20 02:08:30 +00:00
|
|
|
valuesEncoded: valuesEncoded,
|
2024-05-12 14:33:29 +00:00
|
|
|
})
|
|
|
|
br.csInitialized = false
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func (br *blockResult) newValuesBucketedForColumn(c *blockResultColumn, bf *byStatsField) []string {
|
2024-05-12 14:33:29 +00:00
|
|
|
if c.isConst {
|
2024-05-20 02:08:30 +00:00
|
|
|
v := c.valuesEncoded[0]
|
|
|
|
return br.getBucketedConstValues(v, bf)
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
if c.isTime {
|
|
|
|
return br.getBucketedTimestampValues(bf)
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
valuesEncoded := c.getValuesEncoded(br)
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
switch c.valueType {
|
|
|
|
case valueTypeString:
|
2024-05-20 02:08:30 +00:00
|
|
|
return br.getBucketedStringValues(valuesEncoded, bf)
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeDict:
|
2024-05-20 02:08:30 +00:00
|
|
|
return br.getBucketedDictValues(valuesEncoded, c.dictValues, bf)
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeUint8:
|
2024-05-20 02:08:30 +00:00
|
|
|
return br.getBucketedUint8Values(valuesEncoded, bf)
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeUint16:
|
2024-05-20 02:08:30 +00:00
|
|
|
return br.getBucketedUint16Values(valuesEncoded, bf)
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeUint32:
|
2024-05-20 02:08:30 +00:00
|
|
|
return br.getBucketedUint32Values(valuesEncoded, bf)
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeUint64:
|
2024-05-20 02:08:30 +00:00
|
|
|
return br.getBucketedUint64Values(valuesEncoded, bf)
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeFloat64:
|
2024-05-20 02:08:30 +00:00
|
|
|
return br.getBucketedFloat64Values(valuesEncoded, bf)
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeIPv4:
|
2024-05-20 02:08:30 +00:00
|
|
|
return br.getBucketedIPv4Values(valuesEncoded, bf)
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeTimestampISO8601:
|
2024-05-20 02:08:30 +00:00
|
|
|
return br.getBucketedTimestampISO8601Values(valuesEncoded, bf)
|
2024-05-12 14:33:29 +00:00
|
|
|
default:
|
|
|
|
logger.Panicf("BUG: unknown valueType=%d", c.valueType)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (br *blockResult) getBucketedConstValues(v string, bf *byStatsField) []string {
|
|
|
|
if v == "" {
|
|
|
|
// Fast path - return a slice of empty strings without constructing the slice.
|
2024-09-25 14:16:53 +00:00
|
|
|
return getEmptyStrings(br.rowsLen)
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
// Slower path - construct slice of identical values with the length equal to br.rowsLen
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
valuesBuf := br.valuesBuf
|
|
|
|
valuesBufLen := len(valuesBuf)
|
|
|
|
|
|
|
|
v = br.getBucketedValue(v, bf)
|
2024-09-25 14:16:53 +00:00
|
|
|
for i := 0; i < br.rowsLen; i++ {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
br.valuesBuf = valuesBuf
|
|
|
|
|
|
|
|
return valuesBuf[valuesBufLen:]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (br *blockResult) getBucketedTimestampValues(bf *byStatsField) []string {
|
2024-05-20 02:08:30 +00:00
|
|
|
buf := br.a.b
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf := br.valuesBuf
|
|
|
|
valuesBufLen := len(valuesBuf)
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
timestamps := br.getTimestamps()
|
2024-05-12 14:33:29 +00:00
|
|
|
var s string
|
|
|
|
|
|
|
|
if !bf.hasBucketConfig() {
|
|
|
|
for i := range timestamps {
|
|
|
|
if i > 0 && timestamps[i-1] == timestamps[i] {
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalTimestampRFC3339NanoString(buf, timestamps[i])
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bucketSizeInt := int64(bf.bucketSize)
|
|
|
|
if bucketSizeInt <= 0 {
|
|
|
|
bucketSizeInt = 1
|
|
|
|
}
|
|
|
|
bucketOffsetInt := int64(bf.bucketOffset)
|
|
|
|
|
|
|
|
timestampPrev := int64(0)
|
|
|
|
for i := range timestamps {
|
|
|
|
if i > 0 && timestamps[i-1] == timestamps[i] {
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
timestamp := timestamps[i]
|
|
|
|
timestamp -= bucketOffsetInt
|
|
|
|
if bf.bucketSizeStr == "month" {
|
|
|
|
timestamp = truncateTimestampToMonth(timestamp)
|
|
|
|
} else if bf.bucketSizeStr == "year" {
|
|
|
|
timestamp = truncateTimestampToYear(timestamp)
|
|
|
|
} else {
|
|
|
|
timestamp -= timestamp % bucketSizeInt
|
|
|
|
}
|
|
|
|
timestamp += bucketOffsetInt
|
|
|
|
|
|
|
|
if i > 0 && timestampPrev == timestamp {
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
timestampPrev = timestamp
|
|
|
|
|
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalTimestampRFC3339NanoString(buf, timestamp)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
br.a.b = buf
|
2024-05-12 14:33:29 +00:00
|
|
|
br.valuesBuf = valuesBuf
|
|
|
|
|
|
|
|
return valuesBuf[valuesBufLen:]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (br *blockResult) getBucketedStringValues(values []string, bf *byStatsField) []string {
|
|
|
|
if !bf.hasBucketConfig() {
|
|
|
|
return values
|
|
|
|
}
|
|
|
|
|
|
|
|
valuesBuf := br.valuesBuf
|
|
|
|
valuesBufLen := len(valuesBuf)
|
|
|
|
|
|
|
|
var s string
|
|
|
|
for i := range values {
|
|
|
|
if i > 0 && values[i-1] == values[i] {
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
s = br.getBucketedValue(values[i], bf)
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
br.valuesBuf = valuesBuf
|
|
|
|
|
|
|
|
return valuesBuf[valuesBufLen:]
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func (br *blockResult) getBucketedDictValues(valuesEncoded, dictValues []string, bf *byStatsField) []string {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf := br.valuesBuf
|
|
|
|
valuesBufLen := len(valuesBuf)
|
|
|
|
|
|
|
|
dictValues = br.getBucketedStringValues(dictValues, bf)
|
2024-05-20 02:08:30 +00:00
|
|
|
for _, v := range valuesEncoded {
|
2024-05-12 14:33:29 +00:00
|
|
|
dictIdx := v[0]
|
|
|
|
valuesBuf = append(valuesBuf, dictValues[dictIdx])
|
|
|
|
}
|
|
|
|
|
|
|
|
br.valuesBuf = valuesBuf
|
|
|
|
|
|
|
|
return valuesBuf[valuesBufLen:]
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func (br *blockResult) getBucketedUint8Values(valuesEncoded []string, bf *byStatsField) []string {
|
|
|
|
buf := br.a.b
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf := br.valuesBuf
|
|
|
|
valuesBufLen := len(valuesBuf)
|
|
|
|
|
|
|
|
var s string
|
|
|
|
|
|
|
|
if !bf.hasBucketConfig() {
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range valuesEncoded {
|
|
|
|
if i > 0 && valuesEncoded[i-1] == valuesEncoded[i] {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
n := unmarshalUint8(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalUint8String(buf, n)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bucketSizeInt := uint64(bf.bucketSize)
|
|
|
|
if bucketSizeInt <= 0 {
|
|
|
|
bucketSizeInt = 1
|
|
|
|
}
|
|
|
|
bucketOffsetInt := uint64(int64(bf.bucketOffset))
|
|
|
|
|
|
|
|
nPrev := uint64(0)
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range valuesEncoded {
|
|
|
|
if i > 0 && valuesEncoded[i-1] == valuesEncoded[i] {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
n := uint64(unmarshalUint8(v))
|
2024-05-12 14:33:29 +00:00
|
|
|
n -= bucketOffsetInt
|
|
|
|
n -= n % bucketSizeInt
|
|
|
|
n += bucketOffsetInt
|
|
|
|
|
|
|
|
if i > 0 && nPrev == n {
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
nPrev = n
|
|
|
|
|
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalUint64String(buf, n)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
br.valuesBuf = valuesBuf
|
2024-05-20 02:08:30 +00:00
|
|
|
br.a.b = buf
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
return br.valuesBuf[valuesBufLen:]
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func (br *blockResult) getBucketedUint16Values(valuesEncoded []string, bf *byStatsField) []string {
|
|
|
|
buf := br.a.b
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf := br.valuesBuf
|
|
|
|
valuesBufLen := len(valuesBuf)
|
|
|
|
|
|
|
|
var s string
|
|
|
|
|
|
|
|
if !bf.hasBucketConfig() {
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range valuesEncoded {
|
|
|
|
if i > 0 && valuesEncoded[i-1] == valuesEncoded[i] {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
n := unmarshalUint16(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalUint16String(buf, n)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bucketSizeInt := uint64(bf.bucketSize)
|
|
|
|
if bucketSizeInt <= 0 {
|
|
|
|
bucketSizeInt = 1
|
|
|
|
}
|
|
|
|
bucketOffsetInt := uint64(int64(bf.bucketOffset))
|
|
|
|
|
|
|
|
nPrev := uint64(0)
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range valuesEncoded {
|
|
|
|
if i > 0 && valuesEncoded[i-1] == valuesEncoded[i] {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
n := uint64(unmarshalUint16(v))
|
2024-05-12 14:33:29 +00:00
|
|
|
n -= bucketOffsetInt
|
|
|
|
n -= n % bucketSizeInt
|
|
|
|
n += bucketOffsetInt
|
|
|
|
|
|
|
|
if i > 0 && nPrev == n {
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
nPrev = n
|
|
|
|
|
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalUint64String(buf, n)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
br.valuesBuf = valuesBuf
|
2024-05-20 02:08:30 +00:00
|
|
|
br.a.b = buf
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
return br.valuesBuf[valuesBufLen:]
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func (br *blockResult) getBucketedUint32Values(valuesEncoded []string, bf *byStatsField) []string {
|
|
|
|
buf := br.a.b
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf := br.valuesBuf
|
|
|
|
valuesBufLen := len(valuesBuf)
|
|
|
|
|
|
|
|
var s string
|
|
|
|
|
|
|
|
if !bf.hasBucketConfig() {
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range valuesEncoded {
|
|
|
|
if i > 0 && valuesEncoded[i-1] == valuesEncoded[i] {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
n := unmarshalUint32(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalUint32String(buf, n)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bucketSizeInt := uint64(bf.bucketSize)
|
|
|
|
if bucketSizeInt <= 0 {
|
|
|
|
bucketSizeInt = 1
|
|
|
|
}
|
|
|
|
bucketOffsetInt := uint64(int64(bf.bucketOffset))
|
|
|
|
|
|
|
|
nPrev := uint64(0)
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range valuesEncoded {
|
|
|
|
if i > 0 && valuesEncoded[i-1] == valuesEncoded[i] {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
n := uint64(unmarshalUint32(v))
|
2024-05-12 14:33:29 +00:00
|
|
|
n -= bucketOffsetInt
|
|
|
|
n -= n % bucketSizeInt
|
|
|
|
n += bucketOffsetInt
|
|
|
|
|
|
|
|
if i > 0 && nPrev == n {
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
nPrev = n
|
|
|
|
|
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalUint64String(buf, n)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
br.valuesBuf = valuesBuf
|
2024-05-20 02:08:30 +00:00
|
|
|
br.a.b = buf
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
return br.valuesBuf[valuesBufLen:]
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func (br *blockResult) getBucketedUint64Values(valuesEncoded []string, bf *byStatsField) []string {
|
|
|
|
buf := br.a.b
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf := br.valuesBuf
|
|
|
|
valuesBufLen := len(valuesBuf)
|
|
|
|
|
|
|
|
var s string
|
|
|
|
|
|
|
|
if !bf.hasBucketConfig() {
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range valuesEncoded {
|
|
|
|
if i > 0 && valuesEncoded[i-1] == valuesEncoded[i] {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
n := unmarshalUint64(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalUint64String(buf, n)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bucketSizeInt := uint64(bf.bucketSize)
|
|
|
|
if bucketSizeInt <= 0 {
|
|
|
|
bucketSizeInt = 1
|
|
|
|
}
|
|
|
|
bucketOffsetInt := uint64(int64(bf.bucketOffset))
|
|
|
|
|
|
|
|
nPrev := uint64(0)
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range valuesEncoded {
|
|
|
|
if i > 0 && valuesEncoded[i-1] == valuesEncoded[i] {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
n := unmarshalUint64(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
n -= bucketOffsetInt
|
|
|
|
n -= n % bucketSizeInt
|
|
|
|
n += bucketOffsetInt
|
|
|
|
|
|
|
|
if i > 0 && nPrev == n {
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
nPrev = n
|
|
|
|
|
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalUint64String(buf, n)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
br.valuesBuf = valuesBuf
|
2024-05-20 02:08:30 +00:00
|
|
|
br.a.b = buf
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
return br.valuesBuf[valuesBufLen:]
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func (br *blockResult) getBucketedFloat64Values(valuesEncoded []string, bf *byStatsField) []string {
|
|
|
|
buf := br.a.b
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf := br.valuesBuf
|
|
|
|
valuesBufLen := len(valuesBuf)
|
|
|
|
|
|
|
|
var s string
|
|
|
|
|
|
|
|
if !bf.hasBucketConfig() {
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range valuesEncoded {
|
|
|
|
if i > 0 && valuesEncoded[i-1] == valuesEncoded[i] {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
f := unmarshalFloat64(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalFloat64String(buf, f)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bucketSize := bf.bucketSize
|
|
|
|
if bucketSize <= 0 {
|
|
|
|
bucketSize = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
_, e := decimal.FromFloat(bucketSize)
|
|
|
|
p10 := math.Pow10(int(-e))
|
|
|
|
bucketSizeP10 := int64(bucketSize * p10)
|
|
|
|
|
|
|
|
fPrev := float64(0)
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range valuesEncoded {
|
|
|
|
if i > 0 && valuesEncoded[i-1] == valuesEncoded[i] {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
f := unmarshalFloat64(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
f -= bf.bucketOffset
|
|
|
|
|
|
|
|
// emulate f % bucketSize for float64 values
|
|
|
|
fP10 := int64(f * p10)
|
|
|
|
fP10 -= fP10 % bucketSizeP10
|
|
|
|
f = float64(fP10) / p10
|
|
|
|
|
|
|
|
f += bf.bucketOffset
|
|
|
|
|
|
|
|
if fPrev == f {
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fPrev = f
|
|
|
|
|
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalFloat64String(buf, f)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
br.valuesBuf = valuesBuf
|
2024-05-20 02:08:30 +00:00
|
|
|
br.a.b = buf
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
return br.valuesBuf[valuesBufLen:]
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func (br *blockResult) getBucketedIPv4Values(valuesEncoded []string, bf *byStatsField) []string {
|
|
|
|
buf := br.a.b
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf := br.valuesBuf
|
|
|
|
valuesBufLen := len(valuesBuf)
|
|
|
|
|
|
|
|
var s string
|
|
|
|
|
|
|
|
if !bf.hasBucketConfig() {
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range valuesEncoded {
|
|
|
|
if i > 0 && valuesEncoded[i-1] == valuesEncoded[i] {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
ip := unmarshalIPv4(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalIPv4String(buf, ip)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bucketSizeInt := uint32(bf.bucketSize)
|
|
|
|
if bucketSizeInt <= 0 {
|
|
|
|
bucketSizeInt = 1
|
|
|
|
}
|
|
|
|
bucketOffsetInt := uint32(int32(bf.bucketOffset))
|
|
|
|
|
|
|
|
nPrev := uint32(0)
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range valuesEncoded {
|
|
|
|
if i > 0 && valuesEncoded[i-1] == valuesEncoded[i] {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
n := unmarshalIPv4(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
n -= bucketOffsetInt
|
|
|
|
n -= n % bucketSizeInt
|
|
|
|
n += bucketOffsetInt
|
|
|
|
|
|
|
|
if i > 0 && nPrev == n {
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
nPrev = n
|
|
|
|
|
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalIPv4String(buf, n)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
br.valuesBuf = valuesBuf
|
2024-05-20 02:08:30 +00:00
|
|
|
br.a.b = buf
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
return valuesBuf[valuesBufLen:]
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func (br *blockResult) getBucketedTimestampISO8601Values(valuesEncoded []string, bf *byStatsField) []string {
|
|
|
|
buf := br.a.b
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf := br.valuesBuf
|
|
|
|
valuesBufLen := len(valuesBuf)
|
|
|
|
|
|
|
|
var s string
|
|
|
|
|
|
|
|
if !bf.hasBucketConfig() {
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range valuesEncoded {
|
|
|
|
if i > 0 && valuesEncoded[i-1] == valuesEncoded[i] {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
n := unmarshalTimestampISO8601(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalTimestampISO8601String(buf, n)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bucketSizeInt := int64(bf.bucketSize)
|
|
|
|
if bucketSizeInt <= 0 {
|
|
|
|
bucketSizeInt = 1
|
|
|
|
}
|
|
|
|
bucketOffsetInt := int64(bf.bucketOffset)
|
|
|
|
|
|
|
|
timestampPrev := int64(0)
|
|
|
|
bb := bbPool.Get()
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range valuesEncoded {
|
|
|
|
if i > 0 && valuesEncoded[i-1] == valuesEncoded[i] {
|
2024-05-12 14:33:29 +00:00
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
timestamp := unmarshalTimestampISO8601(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
timestamp -= bucketOffsetInt
|
|
|
|
if bf.bucketSizeStr == "month" {
|
|
|
|
timestamp = truncateTimestampToMonth(timestamp)
|
|
|
|
} else if bf.bucketSizeStr == "year" {
|
|
|
|
timestamp = truncateTimestampToYear(timestamp)
|
|
|
|
} else {
|
|
|
|
timestamp -= timestamp % bucketSizeInt
|
|
|
|
}
|
|
|
|
timestamp -= timestamp % bucketSizeInt
|
|
|
|
timestamp += bucketOffsetInt
|
|
|
|
|
|
|
|
if timestampPrev == timestamp {
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
timestampPrev = timestamp
|
|
|
|
|
|
|
|
bufLen := len(buf)
|
2024-05-20 02:08:30 +00:00
|
|
|
buf = marshalTimestampISO8601String(buf, timestamp)
|
2024-05-12 14:33:29 +00:00
|
|
|
s = bytesutil.ToUnsafeString(buf[bufLen:])
|
|
|
|
valuesBuf = append(valuesBuf, s)
|
|
|
|
}
|
|
|
|
bbPool.Put(bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
br.valuesBuf = valuesBuf
|
2024-05-20 02:08:30 +00:00
|
|
|
br.a.b = buf
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
return valuesBuf[valuesBufLen:]
|
|
|
|
}
|
|
|
|
|
|
|
|
// getBucketedValue returns bucketed s according to the given bf
|
|
|
|
func (br *blockResult) getBucketedValue(s string, bf *byStatsField) string {
|
|
|
|
if !bf.hasBucketConfig() {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
if len(s) == 0 {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
c := s[0]
|
|
|
|
if (c < '0' || c > '9') && c != '-' {
|
|
|
|
// Fast path - the value cannot be bucketed, since it starts with unexpected chars.
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
if f, ok := tryParseFloat64(s); ok {
|
|
|
|
bucketSize := bf.bucketSize
|
|
|
|
if bucketSize <= 0 {
|
|
|
|
bucketSize = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
f -= bf.bucketOffset
|
|
|
|
|
|
|
|
// emulate f % bucketSize for float64 values
|
|
|
|
_, e := decimal.FromFloat(bucketSize)
|
|
|
|
p10 := math.Pow10(int(-e))
|
|
|
|
fP10 := int64(f * p10)
|
|
|
|
fP10 -= fP10 % int64(bucketSize*p10)
|
|
|
|
f = float64(fP10) / p10
|
|
|
|
|
|
|
|
f += bf.bucketOffset
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
buf := br.a.b
|
|
|
|
bufLen := len(buf)
|
|
|
|
buf = marshalFloat64String(buf, f)
|
|
|
|
br.a.b = buf
|
|
|
|
return bytesutil.ToUnsafeString(buf[bufLen:])
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
2024-06-25 12:08:01 +00:00
|
|
|
// There is no need in calling tryParseTimestampISO8601 here, since TryParseTimestampRFC3339Nano
|
|
|
|
// should successfully parse ISO8601 timestamps.
|
2024-06-17 10:13:18 +00:00
|
|
|
if timestamp, ok := TryParseTimestampRFC3339Nano(s); ok {
|
2024-05-12 14:33:29 +00:00
|
|
|
bucketSizeInt := int64(bf.bucketSize)
|
|
|
|
if bucketSizeInt <= 0 {
|
|
|
|
bucketSizeInt = 1
|
|
|
|
}
|
|
|
|
bucketOffset := int64(bf.bucketOffset)
|
|
|
|
|
|
|
|
timestamp -= bucketOffset
|
|
|
|
if bf.bucketSizeStr == "month" {
|
|
|
|
timestamp = truncateTimestampToMonth(timestamp)
|
|
|
|
} else if bf.bucketSizeStr == "year" {
|
|
|
|
timestamp = truncateTimestampToYear(timestamp)
|
|
|
|
} else {
|
|
|
|
timestamp -= timestamp % bucketSizeInt
|
|
|
|
}
|
|
|
|
timestamp += bucketOffset
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
buf := br.a.b
|
|
|
|
bufLen := len(buf)
|
|
|
|
buf = marshalTimestampRFC3339NanoString(buf, timestamp)
|
|
|
|
br.a.b = buf
|
|
|
|
return bytesutil.ToUnsafeString(buf[bufLen:])
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if n, ok := tryParseIPv4(s); ok {
|
|
|
|
bucketSizeInt := uint32(bf.bucketSize)
|
|
|
|
if bucketSizeInt <= 0 {
|
|
|
|
bucketSizeInt = 1
|
|
|
|
}
|
|
|
|
bucketOffset := uint32(int32(bf.bucketOffset))
|
|
|
|
|
|
|
|
n -= bucketOffset
|
|
|
|
n -= n % bucketSizeInt
|
|
|
|
n += bucketOffset
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
buf := br.a.b
|
|
|
|
bufLen := len(buf)
|
|
|
|
buf = marshalIPv4String(buf, n)
|
|
|
|
br.a.b = buf
|
|
|
|
return bytesutil.ToUnsafeString(buf[bufLen:])
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if nsecs, ok := tryParseDuration(s); ok {
|
|
|
|
bucketSizeInt := int64(bf.bucketSize)
|
|
|
|
if bucketSizeInt <= 0 {
|
|
|
|
bucketSizeInt = 1
|
|
|
|
}
|
|
|
|
bucketOffset := int64(bf.bucketOffset)
|
|
|
|
|
|
|
|
nsecs -= bucketOffset
|
|
|
|
nsecs -= nsecs % bucketSizeInt
|
|
|
|
nsecs += bucketOffset
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
buf := br.a.b
|
|
|
|
bufLen := len(buf)
|
2024-06-03 22:59:25 +00:00
|
|
|
buf = marshalDurationString(buf, nsecs)
|
2024-05-20 02:08:30 +00:00
|
|
|
br.a.b = buf
|
|
|
|
return bytesutil.ToUnsafeString(buf[bufLen:])
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Couldn't parse s, so return it as is.
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
// copyColumns copies columns from srcColumnNames to dstColumnNames.
|
|
|
|
func (br *blockResult) copyColumns(srcColumnNames, dstColumnNames []string) {
|
2024-05-22 19:01:20 +00:00
|
|
|
for i, srcName := range srcColumnNames {
|
|
|
|
br.copySingleColumn(srcName, dstColumnNames[i])
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
2024-05-22 19:01:20 +00:00
|
|
|
}
|
2024-05-12 14:33:29 +00:00
|
|
|
|
2024-05-22 19:01:20 +00:00
|
|
|
func (br *blockResult) copySingleColumn(srcName, dstName string) {
|
|
|
|
found := false
|
|
|
|
cs := br.getColumns()
|
|
|
|
csBufLen := len(br.csBuf)
|
|
|
|
for _, c := range cs {
|
|
|
|
if c.name != dstName {
|
|
|
|
br.csBuf = append(br.csBuf, *c)
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
2024-05-22 19:01:20 +00:00
|
|
|
if c.name == srcName {
|
|
|
|
cCopy := *c
|
|
|
|
cCopy.name = dstName
|
|
|
|
br.csBuf = append(br.csBuf, cCopy)
|
|
|
|
found = true
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-22 19:01:20 +00:00
|
|
|
if !found {
|
|
|
|
br.addConstColumn(dstName, "")
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
2024-05-22 19:01:20 +00:00
|
|
|
br.csBuf = append(br.csBuf[:0], br.csBuf[csBufLen:]...)
|
|
|
|
br.csInitialized = false
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// renameColumns renames columns from srcColumnNames to dstColumnNames.
|
|
|
|
func (br *blockResult) renameColumns(srcColumnNames, dstColumnNames []string) {
|
2024-05-22 19:01:20 +00:00
|
|
|
for i, srcName := range srcColumnNames {
|
|
|
|
br.renameSingleColumn(srcName, dstColumnNames[i])
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
2024-05-22 19:01:20 +00:00
|
|
|
}
|
2024-05-12 14:33:29 +00:00
|
|
|
|
2024-05-22 19:01:20 +00:00
|
|
|
func (br *blockResult) renameSingleColumn(srcName, dstName string) {
|
|
|
|
found := false
|
|
|
|
cs := br.getColumns()
|
|
|
|
csBufLen := len(br.csBuf)
|
|
|
|
for _, c := range cs {
|
|
|
|
if c.name == srcName {
|
|
|
|
cCopy := *c
|
|
|
|
cCopy.name = dstName
|
|
|
|
br.csBuf = append(br.csBuf, cCopy)
|
|
|
|
found = true
|
|
|
|
} else if c.name != dstName {
|
|
|
|
br.csBuf = append(br.csBuf, *c)
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-22 19:01:20 +00:00
|
|
|
if !found {
|
|
|
|
br.addConstColumn(dstName, "")
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
2024-05-22 19:01:20 +00:00
|
|
|
br.csBuf = append(br.csBuf[:0], br.csBuf[csBufLen:]...)
|
|
|
|
br.csInitialized = false
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// deleteColumns deletes columns with the given columnNames.
|
|
|
|
func (br *blockResult) deleteColumns(columnNames []string) {
|
|
|
|
if len(columnNames) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-05-22 19:01:20 +00:00
|
|
|
cs := br.getColumns()
|
|
|
|
csBufLen := len(br.csBuf)
|
|
|
|
for _, c := range cs {
|
2024-05-12 14:33:29 +00:00
|
|
|
if !slices.Contains(columnNames, c.name) {
|
2024-05-22 19:01:20 +00:00
|
|
|
br.csBuf = append(br.csBuf, *c)
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-22 19:01:20 +00:00
|
|
|
|
|
|
|
br.csBuf = append(br.csBuf[:0], br.csBuf[csBufLen:]...)
|
2024-05-12 14:33:29 +00:00
|
|
|
br.csInitialized = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// setColumns sets the resulting columns to the given columnNames.
|
|
|
|
func (br *blockResult) setColumns(columnNames []string) {
|
|
|
|
if br.areSameColumns(columnNames) {
|
|
|
|
// Fast path - nothing to change.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slow path - construct the requested columns
|
2024-05-22 19:01:20 +00:00
|
|
|
cs := br.getColumns()
|
|
|
|
csBufLen := len(br.csBuf)
|
|
|
|
for _, c := range cs {
|
|
|
|
if slices.Contains(columnNames, c.name) {
|
|
|
|
br.csBuf = append(br.csBuf, *c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
for _, columnName := range columnNames {
|
2024-05-22 19:01:20 +00:00
|
|
|
if idx := getBlockResultColumnIdxByName(cs, columnName); idx < 0 {
|
|
|
|
br.addConstColumn(columnName, "")
|
|
|
|
}
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
2024-05-22 19:01:20 +00:00
|
|
|
|
|
|
|
br.csBuf = append(br.csBuf[:0], br.csBuf[csBufLen:]...)
|
2024-05-12 14:33:29 +00:00
|
|
|
br.csInitialized = false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (br *blockResult) areSameColumns(columnNames []string) bool {
|
|
|
|
cs := br.getColumns()
|
|
|
|
if len(cs) != len(columnNames) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i, c := range cs {
|
|
|
|
if c.name != columnNames[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (br *blockResult) getColumnByName(columnName string) *blockResultColumn {
|
2024-05-20 02:08:30 +00:00
|
|
|
if columnName == "" {
|
|
|
|
columnName = "_msg"
|
|
|
|
}
|
|
|
|
cs := br.getColumns()
|
|
|
|
|
|
|
|
idx := getBlockResultColumnIdxByName(cs, columnName)
|
|
|
|
if idx >= 0 {
|
|
|
|
return cs[idx]
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
2024-05-25 19:36:16 +00:00
|
|
|
// Search for empty column with the given name
|
|
|
|
csEmpty := br.csEmpty
|
|
|
|
for i := range csEmpty {
|
|
|
|
if csEmpty[i].name == columnName {
|
|
|
|
return &csEmpty[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create missing empty column
|
|
|
|
br.csEmpty = append(br.csEmpty, blockResultColumn{
|
|
|
|
name: br.a.copyString(columnName),
|
|
|
|
isConst: true,
|
|
|
|
valuesEncoded: getEmptyStrings(1),
|
|
|
|
})
|
|
|
|
return &br.csEmpty[len(br.csEmpty)-1]
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (br *blockResult) getColumns() []*blockResultColumn {
|
2024-05-25 19:36:16 +00:00
|
|
|
if !br.csInitialized {
|
|
|
|
br.csInit()
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
2024-05-25 19:36:16 +00:00
|
|
|
return br.cs
|
|
|
|
}
|
2024-05-12 14:33:29 +00:00
|
|
|
|
2024-05-25 19:36:16 +00:00
|
|
|
func (br *blockResult) csInit() {
|
2024-05-22 19:01:20 +00:00
|
|
|
csBuf := br.csBuf
|
2024-05-12 14:33:29 +00:00
|
|
|
clear(br.cs)
|
|
|
|
cs := br.cs[:0]
|
|
|
|
for i := range csBuf {
|
2024-05-20 02:08:30 +00:00
|
|
|
c := &csBuf[i]
|
|
|
|
idx := getBlockResultColumnIdxByName(cs, c.name)
|
|
|
|
if idx >= 0 {
|
|
|
|
cs[idx] = c
|
|
|
|
} else {
|
|
|
|
cs = append(cs, c)
|
|
|
|
}
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
br.cs = cs
|
|
|
|
br.csInitialized = true
|
2024-05-25 19:36:16 +00:00
|
|
|
}
|
2024-05-12 14:33:29 +00:00
|
|
|
|
2024-05-25 19:36:16 +00:00
|
|
|
func (br *blockResult) csInitFast() {
|
|
|
|
csBuf := br.csBuf
|
|
|
|
clear(br.cs)
|
|
|
|
cs := slicesutil.SetLength(br.cs, len(csBuf))
|
|
|
|
for i := range csBuf {
|
|
|
|
cs[i] = &csBuf[i]
|
|
|
|
}
|
|
|
|
br.cs = cs
|
|
|
|
br.csInitialized = true
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func getBlockResultColumnIdxByName(cs []*blockResultColumn, name string) int {
|
|
|
|
for i, c := range cs {
|
|
|
|
if c.name == name {
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
func (br *blockResult) skipRows(skipRows int) {
|
2024-09-25 14:16:53 +00:00
|
|
|
timestamps := br.getTimestamps()
|
|
|
|
br.timestampsBuf = append(br.timestampsBuf[:0], timestamps[skipRows:]...)
|
|
|
|
br.rowsLen -= skipRows
|
|
|
|
br.checkTimestampsLen()
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
for _, c := range br.getColumns() {
|
|
|
|
if c.values != nil {
|
|
|
|
c.values = append(c.values[:0], c.values[skipRows:]...)
|
|
|
|
}
|
|
|
|
if c.isConst {
|
|
|
|
continue
|
|
|
|
}
|
2024-05-20 02:08:30 +00:00
|
|
|
|
|
|
|
valuesEncoded := c.getValuesEncoded(br)
|
|
|
|
if valuesEncoded != nil {
|
|
|
|
c.valuesEncoded = append(valuesEncoded[:0], valuesEncoded[skipRows:]...)
|
|
|
|
}
|
|
|
|
if c.valuesBucketed != nil {
|
|
|
|
c.valuesBucketed = append(c.valuesBucketed[:0], c.valuesBucketed[skipRows:]...)
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (br *blockResult) truncateRows(keepRows int) {
|
2024-09-25 14:16:53 +00:00
|
|
|
timestamps := br.getTimestamps()
|
|
|
|
br.timestampsBuf = append(br.timestampsBuf[:0], timestamps[:keepRows]...)
|
|
|
|
br.rowsLen = keepRows
|
|
|
|
br.checkTimestampsLen()
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
for _, c := range br.getColumns() {
|
|
|
|
if c.values != nil {
|
|
|
|
c.values = c.values[:keepRows]
|
|
|
|
}
|
|
|
|
if c.isConst {
|
|
|
|
continue
|
|
|
|
}
|
2024-05-20 02:08:30 +00:00
|
|
|
|
|
|
|
valuesEncoded := c.getValuesEncoded(br)
|
|
|
|
if valuesEncoded != nil {
|
|
|
|
c.valuesEncoded = valuesEncoded[:keepRows]
|
|
|
|
}
|
|
|
|
if c.valuesBucketed != nil {
|
|
|
|
c.valuesBucketed = append(c.valuesBucketed[:0], c.valuesBucketed[keepRows:]...)
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// blockResultColumn represents named column from blockResult.
|
|
|
|
//
|
|
|
|
// blockResultColumn doesn't own any referred data - all the referred data must be owned by blockResult.
|
|
|
|
// This simplifies copying, resetting and re-using of the struct.
|
|
|
|
type blockResultColumn struct {
|
2024-05-20 02:08:30 +00:00
|
|
|
// name is column name
|
2024-05-12 14:33:29 +00:00
|
|
|
name string
|
|
|
|
|
|
|
|
// isConst is set to true if the column is const.
|
|
|
|
//
|
2024-05-20 02:08:30 +00:00
|
|
|
// The column value is stored in valuesEncoded[0]
|
2024-05-12 14:33:29 +00:00
|
|
|
isConst bool
|
|
|
|
|
|
|
|
// isTime is set to true if the column contains _time values.
|
|
|
|
//
|
2024-05-20 02:08:30 +00:00
|
|
|
// The column values are stored in blockResult.timestamps, while valuesEncoded is nil.
|
2024-05-12 14:33:29 +00:00
|
|
|
isTime bool
|
|
|
|
|
|
|
|
// valueType is the type of non-cost value
|
|
|
|
valueType valueType
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
// minValue is the minimum encoded value for uint*, ipv4, timestamp and float64 value
|
|
|
|
//
|
|
|
|
// It is used for fast detection of whether the given column contains values in the given range
|
|
|
|
minValue uint64
|
|
|
|
|
|
|
|
// maxValue is the maximum encoded value for uint*, ipv4, timestamp and float64 value
|
|
|
|
//
|
|
|
|
// It is used for fast detection of whether the given column contains values in the given range
|
|
|
|
maxValue uint64
|
|
|
|
|
|
|
|
// dictValues contains dict values for valueType=valueTypeDict.
|
2024-05-12 14:33:29 +00:00
|
|
|
dictValues []string
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
// valuesEncoded contains encoded values for non-const and non-time column after getValuesEncoded() call
|
|
|
|
valuesEncoded []string
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
// values contains decoded values after getValues() call
|
|
|
|
values []string
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
// valuesBucketed contains values after getValuesBucketed() call
|
|
|
|
valuesBucketed []string
|
2024-05-12 14:33:29 +00:00
|
|
|
|
2024-05-25 19:36:16 +00:00
|
|
|
// valuesEncodedCreator must return valuesEncoded.
|
2024-05-20 02:08:30 +00:00
|
|
|
//
|
2024-05-25 19:36:16 +00:00
|
|
|
// This interface must be set for non-const and non-time columns if valuesEncoded field isn't set.
|
|
|
|
valuesEncodedCreator columnValuesEncodedCreator
|
2024-05-20 02:08:30 +00:00
|
|
|
|
|
|
|
// bucketSizeStr contains bucketSizeStr for valuesBucketed
|
2024-05-12 14:33:29 +00:00
|
|
|
bucketSizeStr string
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
// bucketOffsetStr contains bucketOffset for valuesBucketed
|
2024-05-12 14:33:29 +00:00
|
|
|
bucketOffsetStr string
|
|
|
|
}
|
|
|
|
|
2024-05-25 19:36:16 +00:00
|
|
|
// columnValuesEncodedCreator must return encoded values for the current column.
|
|
|
|
type columnValuesEncodedCreator interface {
|
|
|
|
newValuesEncoded(br *blockResult) []string
|
|
|
|
}
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
// clone returns a clone of c backed by data from br.
|
2024-05-20 02:08:30 +00:00
|
|
|
//
|
|
|
|
// It is expected that c.valuesEncoded is already initialized for non-time column.
|
|
|
|
//
|
|
|
|
// The clone is valid until br is reset.
|
2024-05-12 14:33:29 +00:00
|
|
|
func (c *blockResultColumn) clone(br *blockResult) blockResultColumn {
|
|
|
|
var cNew blockResultColumn
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
cNew.name = br.a.copyString(c.name)
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
cNew.isConst = c.isConst
|
|
|
|
cNew.isTime = c.isTime
|
|
|
|
cNew.valueType = c.valueType
|
2024-05-20 02:08:30 +00:00
|
|
|
cNew.minValue = c.minValue
|
|
|
|
cNew.maxValue = c.maxValue
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
cNew.dictValues = br.cloneValues(c.dictValues)
|
2024-05-20 02:08:30 +00:00
|
|
|
|
|
|
|
if !c.isTime && c.valuesEncoded == nil {
|
|
|
|
logger.Panicf("BUG: valuesEncoded must be non-nil for non-time column %q; isConst=%v; valueType=%d", c.name, c.isConst, c.valueType)
|
|
|
|
}
|
|
|
|
cNew.valuesEncoded = br.cloneValues(c.valuesEncoded)
|
|
|
|
|
|
|
|
if c.valueType != valueTypeString {
|
|
|
|
cNew.values = br.cloneValues(c.values)
|
|
|
|
}
|
|
|
|
cNew.valuesBucketed = br.cloneValues(c.valuesBucketed)
|
|
|
|
|
2024-05-25 19:36:16 +00:00
|
|
|
// Do not copy c.valuesEncodedCreator, since it may refer to data, which may change over time.
|
|
|
|
// We already copied c.valuesEncoded, so cNew.valuesEncodedCreator must be nil.
|
2024-05-20 02:08:30 +00:00
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
cNew.bucketSizeStr = c.bucketSizeStr
|
|
|
|
cNew.bucketOffsetStr = c.bucketOffsetStr
|
|
|
|
|
|
|
|
return cNew
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *blockResultColumn) neededBackingBufLen() int {
|
2024-05-20 02:08:30 +00:00
|
|
|
n := len(c.name)
|
2024-05-12 14:33:29 +00:00
|
|
|
n += valuesSizeBytes(c.dictValues)
|
2024-05-20 02:08:30 +00:00
|
|
|
n += valuesSizeBytes(c.valuesEncoded)
|
|
|
|
if c.valueType != valueTypeString {
|
|
|
|
n += valuesSizeBytes(c.values)
|
|
|
|
}
|
|
|
|
n += valuesSizeBytes(c.valuesBucketed)
|
2024-05-12 14:33:29 +00:00
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *blockResultColumn) neededBackingValuesBufLen() int {
|
|
|
|
n := 0
|
|
|
|
n += len(c.dictValues)
|
2024-05-20 02:08:30 +00:00
|
|
|
n += len(c.valuesEncoded)
|
|
|
|
if c.valueType != valueTypeString {
|
|
|
|
n += len(c.values)
|
|
|
|
}
|
|
|
|
n += len(c.valuesBucketed)
|
2024-05-12 14:33:29 +00:00
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
func valuesSizeBytes(values []string) int {
|
|
|
|
n := 0
|
|
|
|
for _, v := range values {
|
|
|
|
n += len(v)
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
// getValueAtRow returns value for the value at the given rowIdx.
|
|
|
|
//
|
|
|
|
// The returned value is valid until br.reset() is called.
|
|
|
|
func (c *blockResultColumn) getValueAtRow(br *blockResult, rowIdx int) string {
|
|
|
|
if c.isConst {
|
|
|
|
// Fast path for const column.
|
2024-05-20 02:08:30 +00:00
|
|
|
return c.valuesEncoded[0]
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
if c.values != nil {
|
|
|
|
// Fast path, which avoids call overhead for getValues().
|
|
|
|
return c.values[rowIdx]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slow path - decode all the values and return the given value.
|
|
|
|
values := c.getValues(br)
|
|
|
|
return values[rowIdx]
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
// getValuesBucketed returns values for the given column, bucketed according to bf.
|
2024-05-12 14:33:29 +00:00
|
|
|
//
|
|
|
|
// The returned values are valid until br.reset() is called.
|
2024-05-20 02:08:30 +00:00
|
|
|
func (c *blockResultColumn) getValuesBucketed(br *blockResult, bf *byStatsField) []string {
|
2024-05-12 14:33:29 +00:00
|
|
|
if !bf.hasBucketConfig() {
|
|
|
|
return c.getValues(br)
|
|
|
|
}
|
2024-05-20 02:08:30 +00:00
|
|
|
if values := c.valuesBucketed; values != nil && c.bucketSizeStr == bf.bucketSizeStr && c.bucketOffsetStr == bf.bucketOffsetStr {
|
2024-05-12 14:33:29 +00:00
|
|
|
return values
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
c.valuesBucketed = br.newValuesBucketedForColumn(c, bf)
|
2024-05-12 14:33:29 +00:00
|
|
|
c.bucketSizeStr = bf.bucketSizeStr
|
|
|
|
c.bucketOffsetStr = bf.bucketOffsetStr
|
2024-05-20 02:08:30 +00:00
|
|
|
return c.valuesBucketed
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// getValues returns values for the given column.
|
|
|
|
//
|
|
|
|
// The returned values are valid until br.reset() is called.
|
|
|
|
func (c *blockResultColumn) getValues(br *blockResult) []string {
|
|
|
|
if values := c.values; values != nil {
|
|
|
|
return values
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
c.values = br.newValuesBucketedForColumn(c, zeroByStatsField)
|
2024-05-12 14:33:29 +00:00
|
|
|
return c.values
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
// getValuesEncoded returns encoded values for the given column.
|
|
|
|
//
|
|
|
|
// The returned values are valid until br.reset() is called.
|
|
|
|
func (c *blockResultColumn) getValuesEncoded(br *blockResult) []string {
|
2024-05-12 14:33:29 +00:00
|
|
|
if c.isTime {
|
2024-05-20 02:08:30 +00:00
|
|
|
return nil
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
if c.valuesEncoded == nil {
|
2024-05-25 19:36:16 +00:00
|
|
|
c.valuesEncoded = c.valuesEncodedCreator.newValuesEncoded(br)
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
2024-05-20 02:08:30 +00:00
|
|
|
return c.valuesEncoded
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
2024-11-08 22:17:38 +00:00
|
|
|
// forEachDictValue calls f for every matching value in the column dictionary.
|
|
|
|
//
|
|
|
|
// It properly skips non-matching dict values.
|
2024-10-01 11:29:07 +00:00
|
|
|
func (c *blockResultColumn) forEachDictValue(br *blockResult, f func(v string)) {
|
|
|
|
if c.valueType != valueTypeDict {
|
|
|
|
logger.Panicf("BUG: unexpected column valueType=%d; want %d", c.valueType, valueTypeDict)
|
|
|
|
}
|
2024-10-12 18:49:34 +00:00
|
|
|
if br.bs != nil && uint64(br.rowsLen) == br.bs.bsw.bh.rowsCount {
|
2024-10-01 11:29:07 +00:00
|
|
|
// Fast path - there is no need in reading encoded values
|
|
|
|
for _, v := range c.dictValues {
|
|
|
|
f(v)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slow path - need to read encoded values in order filter not referenced columns.
|
|
|
|
a := encoding.GetUint64s(len(c.dictValues))
|
|
|
|
hits := a.A
|
|
|
|
clear(hits)
|
|
|
|
valuesEncoded := c.getValuesEncoded(br)
|
|
|
|
for _, v := range valuesEncoded {
|
|
|
|
idx := unmarshalUint8(v)
|
|
|
|
hits[idx]++
|
|
|
|
}
|
|
|
|
for i, v := range c.dictValues {
|
|
|
|
if h := hits[i]; h > 0 {
|
|
|
|
f(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
encoding.PutUint64s(a)
|
|
|
|
}
|
|
|
|
|
2024-11-08 22:17:38 +00:00
|
|
|
// forEachDictValueWithHits calls f for every matching value in the column dictionary.
|
|
|
|
//
|
|
|
|
// It properly skips non-matching dict values.
|
2024-10-01 11:29:07 +00:00
|
|
|
//
|
|
|
|
// hits is the number of rows with the given value v in the column.
|
|
|
|
func (c *blockResultColumn) forEachDictValueWithHits(br *blockResult, f func(v string, hits uint64)) {
|
|
|
|
if c.valueType != valueTypeDict {
|
|
|
|
logger.Panicf("BUG: unexpected column valueType=%d; want %d", c.valueType, valueTypeDict)
|
|
|
|
}
|
|
|
|
|
|
|
|
a := encoding.GetUint64s(len(c.dictValues))
|
|
|
|
hits := a.A
|
|
|
|
clear(hits)
|
|
|
|
valuesEncoded := c.getValuesEncoded(br)
|
|
|
|
for _, v := range valuesEncoded {
|
|
|
|
idx := unmarshalUint8(v)
|
|
|
|
hits[idx]++
|
|
|
|
}
|
|
|
|
for i, v := range c.dictValues {
|
|
|
|
if h := hits[i]; h > 0 {
|
|
|
|
f(v, h)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
encoding.PutUint64s(a)
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func (c *blockResultColumn) getFloatValueAtRow(br *blockResult, rowIdx int) (float64, bool) {
|
2024-05-12 14:33:29 +00:00
|
|
|
if c.isConst {
|
2024-05-20 02:08:30 +00:00
|
|
|
v := c.valuesEncoded[0]
|
|
|
|
return tryParseFloat64(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
if c.isTime {
|
2024-05-20 02:08:30 +00:00
|
|
|
return 0, false
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
valuesEncoded := c.getValuesEncoded(br)
|
2024-05-12 14:33:29 +00:00
|
|
|
|
|
|
|
switch c.valueType {
|
|
|
|
case valueTypeString:
|
2024-05-20 02:08:30 +00:00
|
|
|
v := valuesEncoded[rowIdx]
|
|
|
|
return tryParseFloat64(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeDict:
|
2024-05-20 02:08:30 +00:00
|
|
|
dictIdx := valuesEncoded[rowIdx][0]
|
|
|
|
v := c.dictValues[dictIdx]
|
|
|
|
return tryParseFloat64(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeUint8:
|
2024-05-20 02:08:30 +00:00
|
|
|
v := valuesEncoded[rowIdx]
|
|
|
|
return float64(unmarshalUint8(v)), true
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeUint16:
|
2024-05-20 02:08:30 +00:00
|
|
|
v := valuesEncoded[rowIdx]
|
|
|
|
return float64(unmarshalUint16(v)), true
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeUint32:
|
2024-05-20 02:08:30 +00:00
|
|
|
v := valuesEncoded[rowIdx]
|
|
|
|
return float64(unmarshalUint32(v)), true
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeUint64:
|
2024-05-20 02:08:30 +00:00
|
|
|
v := valuesEncoded[rowIdx]
|
|
|
|
return float64(unmarshalUint64(v)), true
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeFloat64:
|
2024-05-20 02:08:30 +00:00
|
|
|
v := valuesEncoded[rowIdx]
|
|
|
|
f := unmarshalFloat64(v)
|
|
|
|
return f, !math.IsNaN(f)
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeIPv4:
|
2024-05-20 02:08:30 +00:00
|
|
|
return 0, false
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeTimestampISO8601:
|
2024-05-20 02:08:30 +00:00
|
|
|
return 0, false
|
2024-05-12 14:33:29 +00:00
|
|
|
default:
|
|
|
|
logger.Panicf("BUG: unknown valueType=%d", c.valueType)
|
2024-05-20 02:08:30 +00:00
|
|
|
return 0, false
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-15 02:55:44 +00:00
|
|
|
func (c *blockResultColumn) sumLenValues(br *blockResult) uint64 {
|
|
|
|
if c.isConst {
|
2024-05-20 02:08:30 +00:00
|
|
|
v := c.valuesEncoded[0]
|
2024-09-25 14:16:53 +00:00
|
|
|
return uint64(len(v)) * uint64(br.rowsLen)
|
2024-05-15 02:55:44 +00:00
|
|
|
}
|
|
|
|
if c.isTime {
|
2024-09-25 14:16:53 +00:00
|
|
|
return uint64(len(time.RFC3339Nano)) * uint64(br.rowsLen)
|
2024-05-15 02:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch c.valueType {
|
|
|
|
case valueTypeString:
|
|
|
|
return c.sumLenStringValues(br)
|
|
|
|
case valueTypeDict:
|
|
|
|
n := uint64(0)
|
|
|
|
dictValues := c.dictValues
|
2024-05-20 02:08:30 +00:00
|
|
|
for _, v := range c.getValuesEncoded(br) {
|
2024-05-15 02:55:44 +00:00
|
|
|
idx := v[0]
|
|
|
|
v := dictValues[idx]
|
|
|
|
n += uint64(len(v))
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
case valueTypeUint8:
|
|
|
|
return c.sumLenStringValues(br)
|
|
|
|
case valueTypeUint16:
|
|
|
|
return c.sumLenStringValues(br)
|
|
|
|
case valueTypeUint32:
|
|
|
|
return c.sumLenStringValues(br)
|
|
|
|
case valueTypeUint64:
|
|
|
|
return c.sumLenStringValues(br)
|
|
|
|
case valueTypeFloat64:
|
|
|
|
return c.sumLenStringValues(br)
|
|
|
|
case valueTypeIPv4:
|
|
|
|
return c.sumLenStringValues(br)
|
|
|
|
case valueTypeTimestampISO8601:
|
2024-09-25 14:16:53 +00:00
|
|
|
return uint64(len(iso8601Timestamp)) * uint64(br.rowsLen)
|
2024-05-15 02:55:44 +00:00
|
|
|
default:
|
|
|
|
logger.Panicf("BUG: unknown valueType=%d", c.valueType)
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *blockResultColumn) sumLenStringValues(br *blockResult) uint64 {
|
|
|
|
n := uint64(0)
|
|
|
|
for _, v := range c.getValues(br) {
|
|
|
|
n += uint64(len(v))
|
|
|
|
}
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
func (c *blockResultColumn) sumValues(br *blockResult) (float64, int) {
|
|
|
|
if c.isConst {
|
2024-05-20 02:08:30 +00:00
|
|
|
v := c.valuesEncoded[0]
|
2024-05-12 14:33:29 +00:00
|
|
|
f, ok := tryParseFloat64(v)
|
|
|
|
if !ok {
|
|
|
|
return 0, 0
|
|
|
|
}
|
2024-09-25 14:16:53 +00:00
|
|
|
return f * float64(br.rowsLen), br.rowsLen
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
if c.isTime {
|
|
|
|
return 0, 0
|
|
|
|
}
|
|
|
|
|
|
|
|
switch c.valueType {
|
|
|
|
case valueTypeString:
|
|
|
|
sum := float64(0)
|
|
|
|
count := 0
|
|
|
|
f := float64(0)
|
|
|
|
ok := false
|
2024-05-20 02:08:30 +00:00
|
|
|
values := c.getValuesEncoded(br)
|
2024-05-12 14:33:29 +00:00
|
|
|
for i := range values {
|
|
|
|
if i == 0 || values[i-1] != values[i] {
|
2024-05-24 22:30:58 +00:00
|
|
|
f, ok = tryParseNumber(values[i])
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
if ok {
|
|
|
|
sum += f
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sum, count
|
|
|
|
case valueTypeDict:
|
2024-05-20 02:08:30 +00:00
|
|
|
dictValues := c.dictValues
|
|
|
|
a := encoding.GetFloat64s(len(dictValues))
|
2024-05-12 14:33:29 +00:00
|
|
|
dictValuesFloat := a.A
|
2024-05-20 02:08:30 +00:00
|
|
|
for i, v := range dictValues {
|
2024-05-24 22:30:58 +00:00
|
|
|
f, ok := tryParseNumber(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
if !ok {
|
|
|
|
f = nan
|
|
|
|
}
|
|
|
|
dictValuesFloat[i] = f
|
|
|
|
}
|
|
|
|
sum := float64(0)
|
|
|
|
count := 0
|
2024-05-20 02:08:30 +00:00
|
|
|
for _, v := range c.getValuesEncoded(br) {
|
2024-05-12 14:33:29 +00:00
|
|
|
dictIdx := v[0]
|
|
|
|
f := dictValuesFloat[dictIdx]
|
|
|
|
if !math.IsNaN(f) {
|
|
|
|
sum += f
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
encoding.PutFloat64s(a)
|
|
|
|
return sum, count
|
|
|
|
case valueTypeUint8:
|
|
|
|
sum := uint64(0)
|
2024-05-20 02:08:30 +00:00
|
|
|
for _, v := range c.getValuesEncoded(br) {
|
|
|
|
sum += uint64(unmarshalUint8(v))
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
2024-09-25 14:16:53 +00:00
|
|
|
return float64(sum), br.rowsLen
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeUint16:
|
|
|
|
sum := uint64(0)
|
2024-05-20 02:08:30 +00:00
|
|
|
for _, v := range c.getValuesEncoded(br) {
|
|
|
|
sum += uint64(unmarshalUint16(v))
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
2024-09-25 14:16:53 +00:00
|
|
|
return float64(sum), br.rowsLen
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeUint32:
|
|
|
|
sum := uint64(0)
|
2024-05-20 02:08:30 +00:00
|
|
|
for _, v := range c.getValuesEncoded(br) {
|
|
|
|
sum += uint64(unmarshalUint32(v))
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
2024-09-25 14:16:53 +00:00
|
|
|
return float64(sum), br.rowsLen
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeUint64:
|
|
|
|
sum := float64(0)
|
2024-05-20 02:08:30 +00:00
|
|
|
for _, v := range c.getValuesEncoded(br) {
|
|
|
|
sum += float64(unmarshalUint64(v))
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
2024-09-25 14:16:53 +00:00
|
|
|
return sum, br.rowsLen
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeFloat64:
|
|
|
|
sum := float64(0)
|
2024-05-20 02:08:30 +00:00
|
|
|
for _, v := range c.getValuesEncoded(br) {
|
|
|
|
f := unmarshalFloat64(v)
|
2024-05-12 14:33:29 +00:00
|
|
|
if !math.IsNaN(f) {
|
|
|
|
sum += f
|
|
|
|
}
|
|
|
|
}
|
2024-09-25 14:16:53 +00:00
|
|
|
return sum, br.rowsLen
|
2024-05-12 14:33:29 +00:00
|
|
|
case valueTypeIPv4:
|
|
|
|
return 0, 0
|
|
|
|
case valueTypeTimestampISO8601:
|
|
|
|
return 0, 0
|
|
|
|
default:
|
|
|
|
logger.Panicf("BUG: unknown valueType=%d", c.valueType)
|
|
|
|
return 0, 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
// resultColumn represents a column with result values.
|
|
|
|
//
|
|
|
|
// It doesn't own the result values.
|
2024-05-12 14:33:29 +00:00
|
|
|
type resultColumn struct {
|
|
|
|
// name is column name.
|
|
|
|
name string
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
// values is the result values.
|
2024-05-12 14:33:29 +00:00
|
|
|
values []string
|
|
|
|
}
|
|
|
|
|
2024-05-22 19:01:20 +00:00
|
|
|
func (rc *resultColumn) reset() {
|
|
|
|
rc.name = ""
|
|
|
|
rc.resetValues()
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func (rc *resultColumn) resetValues() {
|
2024-05-12 14:33:29 +00:00
|
|
|
clear(rc.values)
|
|
|
|
rc.values = rc.values[:0]
|
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func appendResultColumnWithName(dst []resultColumn, name string) []resultColumn {
|
|
|
|
dst = slicesutil.SetLength(dst, len(dst)+1)
|
|
|
|
rc := &dst[len(dst)-1]
|
|
|
|
rc.name = name
|
2024-05-22 19:01:20 +00:00
|
|
|
rc.resetValues()
|
2024-05-20 02:08:30 +00:00
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
// addValue adds the given values v to rc.
|
2024-05-24 01:06:55 +00:00
|
|
|
//
|
|
|
|
// rc is valid until v is modified.
|
2024-05-12 14:33:29 +00:00
|
|
|
func (rc *resultColumn) addValue(v string) {
|
2024-05-20 02:08:30 +00:00
|
|
|
rc.values = append(rc.values, v)
|
2024-05-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func truncateTimestampToMonth(timestamp int64) int64 {
|
|
|
|
t := time.Unix(0, timestamp).UTC()
|
|
|
|
return time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, time.UTC).UnixNano()
|
|
|
|
}
|
|
|
|
|
|
|
|
func truncateTimestampToYear(timestamp int64) int64 {
|
|
|
|
t := time.Unix(0, timestamp).UTC()
|
|
|
|
return time.Date(t.Year(), time.January, 1, 0, 0, 0, 0, time.UTC).UnixNano()
|
|
|
|
}
|
|
|
|
|
2024-09-25 14:16:53 +00:00
|
|
|
func getEmptyStrings(rowsLen int) []string {
|
2024-05-13 23:49:20 +00:00
|
|
|
p := emptyStrings.Load()
|
|
|
|
if p == nil {
|
2024-09-25 14:16:53 +00:00
|
|
|
values := make([]string, rowsLen)
|
2024-05-13 23:49:20 +00:00
|
|
|
emptyStrings.Store(&values)
|
|
|
|
return values
|
|
|
|
}
|
|
|
|
values := *p
|
2024-09-25 14:16:53 +00:00
|
|
|
return slicesutil.SetLength(values, rowsLen)
|
2024-05-13 23:49:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var emptyStrings atomic.Pointer[[]string]
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func visitValuesReadonly(bs *blockSearch, ch *columnHeader, bm *bitmap, f func(value string)) {
|
|
|
|
if bm.isZero() {
|
|
|
|
// Fast path - nothing to visit
|
|
|
|
return
|
|
|
|
}
|
|
|
|
values := bs.getValuesForColumn(ch)
|
|
|
|
bm.forEachSetBitReadonly(func(idx int) {
|
|
|
|
f(values[idx])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-05-22 19:01:20 +00:00
|
|
|
func getCanonicalColumnName(columnName string) string {
|
|
|
|
if columnName == "" {
|
|
|
|
return "_msg"
|
|
|
|
}
|
|
|
|
return columnName
|
|
|
|
}
|
|
|
|
|
2024-06-05 01:18:12 +00:00
|
|
|
func tryParseNumber(s string) (float64, bool) {
|
|
|
|
if len(s) == 0 {
|
|
|
|
return 0, false
|
|
|
|
}
|
|
|
|
f, ok := tryParseFloat64(s)
|
|
|
|
if ok {
|
|
|
|
return f, true
|
|
|
|
}
|
|
|
|
nsecs, ok := tryParseDuration(s)
|
|
|
|
if ok {
|
|
|
|
return float64(nsecs), true
|
|
|
|
}
|
|
|
|
bytes, ok := tryParseBytes(s)
|
|
|
|
if ok {
|
|
|
|
return float64(bytes), true
|
|
|
|
}
|
|
|
|
if isLikelyNumber(s) {
|
|
|
|
f, err := strconv.ParseFloat(s, 64)
|
|
|
|
if err == nil {
|
|
|
|
return f, true
|
|
|
|
}
|
|
|
|
n, err := strconv.ParseInt(s, 0, 64)
|
|
|
|
if err == nil {
|
|
|
|
return float64(n), true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0, false
|
|
|
|
}
|
|
|
|
|
|
|
|
func isLikelyNumber(s string) bool {
|
|
|
|
if !isNumberPrefix(s) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if strings.Count(s, ".") > 1 {
|
|
|
|
// This is likely IP address
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if strings.IndexByte(s, ':') >= 0 || strings.Count(s, "-") > 2 {
|
|
|
|
// This is likely a timestamp
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-05-12 14:33:29 +00:00
|
|
|
var nan = math.NaN()
|
|
|
|
var inf = math.Inf(1)
|