From f20da1953e263ff641dc66c6739ddfe7d8e16e31 Mon Sep 17 00:00:00 2001 From: cobyfrombrooklyn-bot Date: Sun, 19 Apr 2026 10:52:37 -0400 Subject: [PATCH] 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 --- pkg/transformers/stats1.go | 4 +++- test/cases/verb-stats1-regexed-field-names/0008/cmd | 1 + test/cases/verb-stats1-regexed-field-names/0008/experr | 0 test/cases/verb-stats1-regexed-field-names/0008/expout | 4 ++++ test/input/null-count-pipe.csv | 4 ++++ 5 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/cases/verb-stats1-regexed-field-names/0008/cmd create mode 100644 test/cases/verb-stats1-regexed-field-names/0008/experr create mode 100644 test/cases/verb-stats1-regexed-field-names/0008/expout create mode 100644 test/input/null-count-pipe.csv diff --git a/pkg/transformers/stats1.go b/pkg/transformers/stats1.go index 803a1255f..163c64f74 100644 --- a/pkg/transformers/stats1.go +++ b/pkg/transformers/stats1.go @@ -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) } diff --git a/test/cases/verb-stats1-regexed-field-names/0008/cmd b/test/cases/verb-stats1-regexed-field-names/0008/cmd new file mode 100644 index 000000000..b8e93a4b8 --- /dev/null +++ b/test/cases/verb-stats1-regexed-field-names/0008/cmd @@ -0,0 +1 @@ +mlr --icsv --ifs "|" --oxtab stats1 -a null_count --fr ".*" test/input/null-count-pipe.csv diff --git a/test/cases/verb-stats1-regexed-field-names/0008/experr b/test/cases/verb-stats1-regexed-field-names/0008/experr new file mode 100644 index 000000000..e69de29bb diff --git a/test/cases/verb-stats1-regexed-field-names/0008/expout b/test/cases/verb-stats1-regexed-field-names/0008/expout new file mode 100644 index 000000000..8b6366ef8 --- /dev/null +++ b/test/cases/verb-stats1-regexed-field-names/0008/expout @@ -0,0 +1,4 @@ +Id_null_count 0 +Type_null_count 3 +Other Type_null_count 1 +Number_null_count 0 diff --git a/test/input/null-count-pipe.csv b/test/input/null-count-pipe.csv new file mode 100644 index 000000000..23454ec51 --- /dev/null +++ b/test/input/null-count-pipe.csv @@ -0,0 +1,4 @@ +Id|Type|Other Type|Number +a||foo|1 +b||bar|2 +c|||1