This commit is contained in:
Aliaksandr Valialkin 2024-05-21 23:56:03 +02:00
parent c4b68956fe
commit 46bfdf6796
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
4 changed files with 30 additions and 14 deletions

View file

@ -27,8 +27,12 @@ func (sm *statsFieldsMax) String() string {
}
func (sm *statsFieldsMax) updateNeededFields(neededFields fieldsSet) {
neededFields.add(sm.srcField)
if len(sm.resultFields) == 0 {
neededFields.add("*")
} else {
neededFields.addFields(sm.resultFields)
}
neededFields.add(sm.srcField)
}
func (sm *statsFieldsMax) newStatsProcessor() (statsProcessor, int) {

View file

@ -27,8 +27,12 @@ func (sm *statsFieldsMin) String() string {
}
func (sm *statsFieldsMin) updateNeededFields(neededFields fieldsSet) {
neededFields.add(sm.srcField)
if len(sm.resultFields) == 0 {
neededFields.add("*")
} else {
neededFields.addFields(sm.resultFields)
}
neededFields.add(sm.srcField)
}
func (sm *statsFieldsMin) newStatsProcessor() (statsProcessor, int) {

View file

@ -12,10 +12,12 @@ import (
type statsMax struct {
fields []string
containsStar bool
}
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, "*"),
}
return sm, nil
}

View file

@ -12,10 +12,12 @@ import (
type statsMin struct {
fields []string
containsStar bool
}
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, "*"),
}
return sm, nil
}