Skip to content

Commit

Permalink
Documents a footgun in the VariadicFunc::propagates_nulls function. (
Browse files Browse the repository at this point in the history
…MaterializeInc#10622)

I ran into this while adding a new variadic function. A casual read of the function makes it seem like the `match!` macro lists the VariadicFuncs that propagate nulls, but the opposite is true. The return expression is actually `!match!`, which is easy to miss. That means the listed VariadicFuncs are the ones that *don't* propagate nulls.

Also, this commit fixes a previously unreported bug:

I found several VariadicFuncs that returned true when `propagates_nulls()` was called, but don't actually propagate nulls: `Greatest`, `Least`, and `ErrorIfNull`. I wasn't able to find anything broken by this, because none of these funcs use the `eager!` macro during `eval()` and they handle null arguments themselves. I figure it's still worth fixing, though.
  • Loading branch information
TonyRippy authored Feb 14, 2022
1 parent 19ff5f8 commit 80e28b4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/expr/src/scalar/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5876,16 +5876,21 @@ impl VariadicFunc {

/// Whether the function output is NULL if any of its inputs are NULL.
pub fn propagates_nulls(&self) -> bool {
// NOTE: The following is a list of the variadic functions
// that **DO NOT** propagate nulls.
!matches!(
self,
VariadicFunc::Coalesce
| VariadicFunc::Greatest
| VariadicFunc::Least
| VariadicFunc::Concat
| VariadicFunc::JsonbBuildArray
| VariadicFunc::JsonbBuildObject
| VariadicFunc::ListCreate { .. }
| VariadicFunc::RecordCreate { .. }
| VariadicFunc::ArrayCreate { .. }
| VariadicFunc::ArrayToString { .. }
| VariadicFunc::ErrorIfNull
)
}
}
Expand Down

0 comments on commit 80e28b4

Please sign in to comment.