This commit is contained in:
Aliaksandr Valialkin 2024-05-10 16:18:41 +02:00
parent b4fd20f17a
commit a4b2806330
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
2 changed files with 11 additions and 2 deletions

View file

@ -369,11 +369,15 @@ func (sup *statsCountUniqProcessor) mergeState(sfp statsProcessor) {
func (sup *statsCountUniqProcessor) finalizeStats() string {
n := uint64(len(sup.m))
if limit := sup.su.limit; limit > 0 && n > limit {
n = limit
}
return strconv.FormatUint(n, 10)
}
func (sup *statsCountUniqProcessor) limitReached() bool {
return sup.su.limit > 0 && uint64(len(sup.m)) >= sup.su.limit
limit := sup.su.limit
return limit > 0 && uint64(len(sup.m)) >= limit
}
func parseStatsCountUniq(lex *lexer) (*statsCountUniq, error) {

View file

@ -209,6 +209,10 @@ func (sup *statsUniqValuesProcessor) finalizeStats() string {
}
slices.SortFunc(items, compareValues)
if limit := sup.su.limit; limit > 0 && uint64(len(items)) > limit {
items = items[:limit]
}
// Marshal items into JSON array.
// Pre-allocate buffer for serialized items.
@ -232,7 +236,8 @@ func (sup *statsUniqValuesProcessor) finalizeStats() string {
}
func (sup *statsUniqValuesProcessor) limitReached() bool {
return sup.su.limit > 0 && uint64(len(sup.m)) >= sup.su.limit
limit := sup.su.limit
return limit > 0 && uint64(len(sup.m)) >= limit
}
func compareValues(a, b string) int {