Skip to content

fix(agg/and+or): unwrap union values before bool aggregation#6899

Closed
SAY-5 wants to merge 1 commit into
brimdata:mainfrom
SAY-5:fix/agg-and-or-union-bool-6896
Closed

fix(agg/and+or): unwrap union values before bool aggregation#6899
SAY-5 wants to merge 1 commit into
brimdata:mainfrom
SAY-5:fix/agg-and-or-union-bool-6896

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 2, 2026

Closes #6896. Closes #6895.

And.Consume and Or.Consume checked super.TypeUnder(val.Type()) to allow union(bool|…) inputs but still read val.Bool() on the union-wrapped value. That decoded the union tag bytes rather than the underlying bool, so the sequential runtime collapsed mixed-union rows to null even when the vector runtime correctly returned the boolean OR/AND.

Repro from #6896

Before:

$ echo '
  false::(bool|null)
  true::(bool|int64)
' | super -sam -c "or(this)" -
null

After:

$ echo '
  false::(bool|null)
  true::(bool|int64)
' | super -sam -c "or(this)" -
true

The vector runtime already unwraps before evaluation (-vam returned true).

Patch

Unwrap with .Under() first, then guard on IsNull() / val.Type() != TypeBool against the unwrapped value, then read .Bool(). Same change applies to both And and Or. ConsumeAsPartial already routes through Consume, so partial aggregation paths are covered.

Tests:

go vet ./runtime/sam/expr/agg/
go test ./runtime/sam/expr/agg/... -count=1

Closes brimdata#6896. Closes brimdata#6895.

`And.Consume` and `Or.Consume` checked `super.TypeUnder(val.Type())`
to allow union(bool|...) inputs but still called `val.Bool()` on the
union-wrapped value, which decoded the union tag bytes instead of the
underlying bool. The result was that `or(this)` over rows like
`false::(bool|null)` and `true::(bool|int64)` returned null in the
sequential runtime even though the vector runtime returned `true`.

Unwrap with `.Under()` first, then validate the underlying type and
null-ness, then read `.Bool()`. Same change applies to both
aggregators.
@nwt nwt closed this May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants