RecordStream icon indicating copy to clipboard operation
RecordStream copied to clipboard

Doing an `collate -a avg,...` on an empty stream dies.

Open anall opened this issue 9 years ago • 6 comments

$ echo -n "" | recs collate -k foo -a avg,bar
Can't use an undefined value as an ARRAY reference at
    /home/anall/perl5/lib/perl5/App/RecordStream/Aggregator/Average.pm line 22.

anall avatar Jun 11 '15 23:06 anall

thanks for the report!

benbernard avatar Jun 11 '15 23:06 benbernard

The fix for avg is pretty simple, but it seems that many of the aggregators don't define their behaviour when processing an empty stream (although many do!). I'd like to fix them all at once, standardizing behaviour.

Before I delve into adding empty stream tests to all the aggs and then fixing whatever fails, I want to figure out what the desired behaviour should be. I can see both cases:

  1. Outputting an empty stream
  2. Outputting a single record (the aggregate) with some null/empty value. Part of this choice is choosing 0 vs. undef agg values when, say, using count on an empty stream.

Thoughts?

tsibley avatar Feb 26 '16 05:02 tsibley

Ideally, I think we should just define this behavior for all scripts... and I think it should just pass on nothing. I could also see erroring (but perhaps with a better error). Let me also see if @amling wants to weigh in on this

benbernard avatar Feb 26 '16 17:02 benbernard

Nothing matches with what I was expecting ( with a much more complex chain of things that legitimately filtered all records ) when I ran into this.

anall avatar Feb 26 '16 17:02 anall

yeah, agreed, given large chains of filters, it feels to me like nothing is the right answer

benbernard avatar Feb 26 '16 17:02 benbernard

That sounds good to me. Will do!

tsibley avatar Feb 28 '16 02:02 tsibley