You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#17982 Make nvl a thin wrapper for coalesce (#17991)
## Which issue does this PR close?
- Closes#17982
## Rationale for this change
By making `NVLFunc` a wrapper for `CoalesceFunc` with a more restrictive
signature the implementation automatically benefits from any
optimisation work related to `coalesce`.
## What changes are included in this PR?
- Make `NVLFunc` a thin wrapper of `CoalesceFunc`. This seemed like the
simplest way to reuse the coalesce logic, but keep the stricter
signature of `nvl`.
- Add `ScalarUDF::conditional_arguments` as a more precise complement to
`ScalarUDF::short_circuits`. By letting each function expose which
arguments are eager and which are lazy, we provide more precise
information to the optimizer which may enable better optimisation.
## Are these changes tested?
Assumed to be covered by sql logic tests.
Unit tests for the custom implementation were removed since those are no
longer relevant.
## Are there any user-facing changes?
The rewriting of `nvl` to `case when ... then ... else ... end` is
visible in the physical query plan.
---------
Co-authored-by: Andrew Lamb <[email protected]>
description = "Returns _expression2_ if _expression1_ is NULL otherwise it returns _expression1_.",
30
+
description = "Returns _expression2_ if _expression1_ is NULL otherwise it returns _expression1_ and _expression2_ is not evaluated. This function can be used to substitute a default value for NULL values.",
33
31
syntax_example = "nvl(expression1, expression2)",
34
32
sql_example = r#"```sql
35
33
> select nvl(null, 'a');
@@ -57,7 +55,7 @@ use std::sync::Arc;
57
55
)]
58
56
#[derive(Debug,PartialEq,Eq,Hash)]
59
57
pubstructNVLFunc{
60
-
signature:Signature,
58
+
coalesce:CoalesceFunc,
61
59
aliases:Vec<String>,
62
60
}
63
61
@@ -90,11 +88,13 @@ impl Default for NVLFunc {
90
88
implNVLFunc{
91
89
pubfnnew() -> Self{
92
90
Self{
93
-
signature:Signature::uniform(
94
-
2,
95
-
SUPPORTED_NVL_TYPES.to_vec(),
96
-
Volatility::Immutable,
97
-
),
91
+
coalesce:CoalesceFunc{
92
+
signature:Signature::uniform(
93
+
2,
94
+
SUPPORTED_NVL_TYPES.to_vec(),
95
+
Volatility::Immutable,
96
+
),
97
+
},
98
98
aliases:vec![String::from("ifnull")],
99
99
}
100
100
}
@@ -110,209 +110,45 @@ impl ScalarUDFImpl for NVLFunc {
0 commit comments