diff --git a/lib/logstorage/stats_fields_max.go b/lib/logstorage/stats_fields_max.go index 309152abc..98d290260 100644 --- a/lib/logstorage/stats_fields_max.go +++ b/lib/logstorage/stats_fields_max.go @@ -27,8 +27,12 @@ func (sm *statsFieldsMax) String() string { } func (sm *statsFieldsMax) updateNeededFields(neededFields fieldsSet) { + if len(sm.resultFields) == 0 { + neededFields.add("*") + } else { + neededFields.addFields(sm.resultFields) + } neededFields.add(sm.srcField) - neededFields.addFields(sm.resultFields) } func (sm *statsFieldsMax) newStatsProcessor() (statsProcessor, int) { diff --git a/lib/logstorage/stats_fields_min.go b/lib/logstorage/stats_fields_min.go index 79ce9cada..25ae60ede 100644 --- a/lib/logstorage/stats_fields_min.go +++ b/lib/logstorage/stats_fields_min.go @@ -27,8 +27,12 @@ func (sm *statsFieldsMin) String() string { } func (sm *statsFieldsMin) updateNeededFields(neededFields fieldsSet) { + if len(sm.resultFields) == 0 { + neededFields.add("*") + } else { + neededFields.addFields(sm.resultFields) + } neededFields.add(sm.srcField) - neededFields.addFields(sm.resultFields) } func (sm *statsFieldsMin) newStatsProcessor() (statsProcessor, int) { diff --git a/lib/logstorage/stats_max.go b/lib/logstorage/stats_max.go index 290641c05..b77082325 100644 --- a/lib/logstorage/stats_max.go +++ b/lib/logstorage/stats_max.go @@ -11,11 +11,13 @@ import ( ) type statsMax struct { - fields []string - containsStar bool + fields []string } func (sm *statsMax) String() string { + if len(sm.fields) == 0 { + return "max(*)" + } return "max(" + fieldNamesString(sm.fields) + ")" } @@ -39,7 +41,7 @@ type statsMaxProcessor struct { func (smp *statsMaxProcessor) updateStatsForAllRows(br *blockResult) int { maxLen := len(smp.max) - if smp.sm.containsStar { + if len(smp.sm.fields) == 0 { // Find the minimum value across all the columns for _, c := range br.getColumns() { smp.updateStateForColumn(br, c) @@ -58,7 +60,7 @@ func (smp *statsMaxProcessor) updateStatsForAllRows(br *blockResult) int { func (smp *statsMaxProcessor) updateStatsForRow(br *blockResult, rowIdx int) int { maxLen := len(smp.max) - if smp.sm.containsStar { + if len(smp.sm.fields) == 0 { // Find the minimum value across all the fields for the given row for _, c := range br.getColumns() { v := c.getValueAtRow(br, rowIdx) @@ -170,9 +172,11 @@ func parseStatsMax(lex *lexer) (*statsMax, error) { if err != nil { return nil, err } + if slices.Contains(fields, "*") { + fields = nil + } sm := &statsMax{ - fields: fields, - containsStar: slices.Contains(fields, "*"), + fields: fields, } return sm, nil } diff --git a/lib/logstorage/stats_min.go b/lib/logstorage/stats_min.go index 4711a43ce..4ddb0929d 100644 --- a/lib/logstorage/stats_min.go +++ b/lib/logstorage/stats_min.go @@ -11,11 +11,13 @@ import ( ) type statsMin struct { - fields []string - containsStar bool + fields []string } func (sm *statsMin) String() string { + if len(sm.fields) == 0 { + return "min(*)" + } return "min(" + fieldNamesString(sm.fields) + ")" } @@ -39,7 +41,7 @@ type statsMinProcessor struct { func (smp *statsMinProcessor) updateStatsForAllRows(br *blockResult) int { minLen := len(smp.min) - if smp.sm.containsStar { + if len(smp.sm.fields) == 0 { // Find the minimum value across all the columns for _, c := range br.getColumns() { smp.updateStateForColumn(br, c) @@ -58,7 +60,7 @@ func (smp *statsMinProcessor) updateStatsForAllRows(br *blockResult) int { func (smp *statsMinProcessor) updateStatsForRow(br *blockResult, rowIdx int) int { minLen := len(smp.min) - if smp.sm.containsStar { + if len(smp.sm.fields) == 0 { // Find the minimum value across all the fields for the given row for _, c := range br.getColumns() { v := c.getValueAtRow(br, rowIdx) @@ -170,9 +172,11 @@ func parseStatsMin(lex *lexer) (*statsMin, error) { if err != nil { return nil, err } + if slices.Contains(fields, "*") { + fields = nil + } sm := &statsMin{ - fields: fields, - containsStar: slices.Contains(fields, "*"), + fields: fields, } return sm, nil }