fix: stats1 null_count with --fr regex gives wrong results (#1994)

When using --fr (regex field selector) with stats1 -a null_count, void
(empty) field values were unconditionally skipped in
ingestWithValueFieldRegexes, causing null_count to always report 0.

The non-regex path (ingestWithoutValueFieldRegexes) already had a special
case that allows void values through for null_count accumulators. This
commit adds the same exception to the regex path.

Fixes #1639

Co-authored-by: cobyfrombrooklyn-bot <cobyfrombrooklyn-bot@users.noreply.github.com>
This commit is contained in:
cobyfrombrooklyn-bot 2026-04-19 10:52:37 -04:00 committed by GitHub
parent 4c781739c0
commit f20da1953e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 12 additions and 1 deletions

View file

@ -578,7 +578,9 @@ func (tr *TransformerStats1) ingestWithValueFieldRegexes(
// The accumulator has been initialized with default values;
// continue here. (If we were to continue outside of this loop
// we would be failing to construct the accumulator.)
continue
if accumulatorName != "null_count" {
continue
}
}
namedAccumulator.Ingest(valueFieldValue)
}

View file

@ -0,0 +1 @@
mlr --icsv --ifs "|" --oxtab stats1 -a null_count --fr ".*" test/input/null-count-pipe.csv

View file

@ -0,0 +1,4 @@
Id_null_count 0
Type_null_count 3
Other Type_null_count 1
Number_null_count 0

View file

@ -0,0 +1,4 @@
Id|Type|Other Type|Number
a||foo|1
b||bar|2
c|||1
1 Id Type Other Type Number
2 a foo 1
3 b bar 2
4 c 1