lib/logstorage: simplify the code for uniq_values stats function a bit

Move the repeated check for an empty value into statsUniqValuesProcessor.updateState() function.
This allow removing duplicate code for this check from statsUniqValuesProcessor.updateState() call sites.
This commit is contained in:
Aliaksandr Valialkin 2024-11-08 22:51:51 +01:00
parent 342f84c569
commit 9b766d3e32
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -65,24 +65,16 @@ func (sup *statsUniqValuesProcessor) updateStatsForAllRows(br *blockResult) int
} }
func (sup *statsUniqValuesProcessor) updateStatsForAllRowsColumn(c *blockResultColumn, br *blockResult) int { func (sup *statsUniqValuesProcessor) updateStatsForAllRowsColumn(c *blockResultColumn, br *blockResult) int {
stateSizeIncrease := 0
if c.isConst { if c.isConst {
// collect unique const values // collect unique const values
v := c.valuesEncoded[0] v := c.valuesEncoded[0]
if v == "" { return sup.updateState(v)
// skip empty values
return stateSizeIncrease
}
stateSizeIncrease += sup.updateState(v)
return stateSizeIncrease
} }
stateSizeIncrease := 0
if c.valueType == valueTypeDict { if c.valueType == valueTypeDict {
// collect unique non-zero c.dictValues // collect unique non-zero c.dictValues
for _, v := range c.dictValues { for _, v := range c.dictValues {
if v == "" {
// skip empty values
continue
}
stateSizeIncrease += sup.updateState(v) stateSizeIncrease += sup.updateState(v)
} }
return stateSizeIncrease return stateSizeIncrease
@ -91,10 +83,6 @@ func (sup *statsUniqValuesProcessor) updateStatsForAllRowsColumn(c *blockResultC
// slow path - collect unique values across all rows // slow path - collect unique values across all rows
values := c.getValues(br) values := c.getValues(br)
for i, v := range values { for i, v := range values {
if v == "" {
// skip empty values
continue
}
if i > 0 && values[i-1] == v { if i > 0 && values[i-1] == v {
// This value has been already counted. // This value has been already counted.
continue continue
@ -126,38 +114,23 @@ func (sup *statsUniqValuesProcessor) updateStatsForRow(br *blockResult, rowIdx i
} }
func (sup *statsUniqValuesProcessor) updateStatsForRowColumn(c *blockResultColumn, br *blockResult, rowIdx int) int { func (sup *statsUniqValuesProcessor) updateStatsForRowColumn(c *blockResultColumn, br *blockResult, rowIdx int) int {
stateSizeIncrease := 0
if c.isConst { if c.isConst {
// collect unique const values // collect unique const values
v := c.valuesEncoded[0] v := c.valuesEncoded[0]
if v == "" { return sup.updateState(v)
// skip empty values
return stateSizeIncrease
}
stateSizeIncrease += sup.updateState(v)
return stateSizeIncrease
} }
if c.valueType == valueTypeDict { if c.valueType == valueTypeDict {
// collect unique non-zero c.dictValues // collect unique non-zero c.dictValues
valuesEncoded := c.getValuesEncoded(br) valuesEncoded := c.getValuesEncoded(br)
dictIdx := valuesEncoded[rowIdx][0] dictIdx := valuesEncoded[rowIdx][0]
v := c.dictValues[dictIdx] v := c.dictValues[dictIdx]
if v == "" { return sup.updateState(v)
// skip empty values
return stateSizeIncrease
}
stateSizeIncrease += sup.updateState(v)
return stateSizeIncrease
} }
// collect unique values for the given rowIdx. // collect unique values for the given rowIdx.
v := c.getValueAtRow(br, rowIdx) v := c.getValueAtRow(br, rowIdx)
if v == "" { return sup.updateState(v)
// skip empty values
return stateSizeIncrease
}
stateSizeIncrease += sup.updateState(v)
return stateSizeIncrease
} }
func (sup *statsUniqValuesProcessor) mergeState(sfp statsProcessor) { func (sup *statsUniqValuesProcessor) mergeState(sfp statsProcessor) {
@ -204,6 +177,11 @@ func sortStrings(a []string) {
} }
func (sup *statsUniqValuesProcessor) updateState(v string) int { func (sup *statsUniqValuesProcessor) updateState(v string) int {
if v == "" {
// Skip empty values
return 0
}
stateSizeIncrease := 0 stateSizeIncrease := 0
if _, ok := sup.m[v]; !ok { if _, ok := sup.m[v]; !ok {
vCopy := strings.Clone(v) vCopy := strings.Clone(v)