Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions pkg/transformers/stats1.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (tr *TransformerStats1) handleInputRecord(
if tr.doRegexGroupByFieldNames {
groupingKey, groupByFieldValues, ok = tr.getGroupByFieldNamesWithRegexes(inrec)
} else {
groupingKey, groupByFieldValues, ok = tr.getGroupByFieldNamesWithoutRegexes(inrec)
groupingKey, ok = tr.getGroupingKeyWithoutRegexes(inrec)
}
if !ok {
return
Expand All @@ -392,7 +392,15 @@ func (tr *TransformerStats1) handleInputRecord(
// E.g. if grouping by "color" and "shape", and the current record has
// color=blue, shape=circle, then groupByFieldValues is the map
// {"color": "blue", "shape": "circle"}.
if !tr.doRegexGroupByFieldNames {
groupByFieldValues, ok = tr.buildGroupByFieldValuesWithoutRegexes(inrec)
if !ok {
return
}
}
tr.groupingKeysToGroupByFieldValues[groupingKey] = groupByFieldValues
} else if tr.doIterativeStats && !tr.doRegexGroupByFieldNames {
groupByFieldValues = tr.groupingKeysToGroupByFieldValues[groupingKey]
}

if tr.doRegexValueFieldNames {
Expand All @@ -416,23 +424,30 @@ func (tr *TransformerStats1) handleInputRecord(
// b=blue, then groupingKey is the string "circle,blue". For grouping without
// regexed group-by field names, the group-by field names/values are the same
// on every record.
func (tr *TransformerStats1) getGroupByFieldNamesWithoutRegexes(
func (tr *TransformerStats1) getGroupingKeyWithoutRegexes(
inrec *mlrval.Mlrmap,
) (
groupingKey string,
ok bool,
) {
return inrec.GetSelectedValuesJoined(tr.groupByFieldNameList)
}

func (tr *TransformerStats1) buildGroupByFieldValuesWithoutRegexes(
inrec *mlrval.Mlrmap,
) (
groupByFieldValues *lib.OrderedMap[*mlrval.Mlrval], // OrderedMap[string]*mlrval.Mlrval,
ok bool,
) {
var groupByFieldValuesArray []*mlrval.Mlrval
groupingKey, groupByFieldValuesArray, ok = inrec.GetSelectedValuesAndJoined(tr.groupByFieldNameList)
groupByFieldValuesArray, ok := inrec.GetSelectedValues(tr.groupByFieldNameList)
if !ok {
return groupingKey, nil, false
return nil, false
}
groupByFieldValues = lib.NewOrderedMap[*mlrval.Mlrval]()
for i, groupByFieldValue := range groupByFieldValuesArray {
groupByFieldValues.Put(tr.groupByFieldNameList[i], groupByFieldValue)
}
return groupingKey, groupByFieldValues, ok
return groupByFieldValues, true
}

// E.g. if grouping by "a" and "b", and the current record has a=circle,
Expand Down
34 changes: 34 additions & 0 deletions pkg/types/slice_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package types

// List is a thin wrapper around a slice which functions as a list/queue. The Items attribute is
// exposed as public since I want iteration (at many, many callsites) to be easy.
type List[T any] struct {
Items []T
}

func NewList[T any](capacity int) *List[T] {
return &List[T]{
make([]T, 0, capacity),
}
}

// Front will panic if the list is empty
func (ell *List[T]) Front() T {
return ell.Items[0]
}

func (ell *List[T]) Len() int {
return len(ell.Items)
}

func (ell *List[T]) PushBack(e T) {
ell.Items = append(ell.Items, e)
}

func (ell *List[T]) PushBackMultiple(mell []T) {
ell.Items = append(ell.Items, mell...)
}

func (ell *List[T]) Clear() {
ell.Items = ell.Items[0:0:cap(ell.Items)]
}
Loading