Commit e76f0ee
fix: IS NULL panic with invalid function without input arguments (#20306)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Closes #20201 .
## Rationale for this change
Unlike `Projection`, expressions within a `Filter` node do not always
have their types resolved during the initial LogicalPlan generation.
Validation is often deferred until the type_coercion phase. When
invoking f_up on the expression tree to perform type coercion, the check
is bypassed for function nodes with empty arguments, leading to a panic
during subsequent execution.
For example, all statements below cause a panic:
```
SELECT * FROM (SELECT 1) WHERE (STARTS_WITH() IS NULL);
SELECT * FROM (SELECT 1) WHERE (STARTS_WITH() IS NOT NULL);
SELECT * FROM (SELECT 'a') WHERE (STARTS_WITH() SIMILAR TO 'abc%');
SELECT * FROM (SELECT 1) WHERE CAST(STARTS_WITH() AS STRING) = 'x';
SELECT * FROM (SELECT 1) WHERE TRY_CAST(STARTS_WITH() AS INT) IS NULL;
```
This pr aims to stop panic. It would be better if reject these invalid
cases at planning.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
```diff
fn coerce_arguments_for_signature<F: UDFCoercionExt>(
schema: &DFSchema,
func: &F,
) -> Result<Vec<Expr>> {
- if expressions.is_empty() {
- return Ok(expressions);
- }
```
Deleted the early return. Thanks to @neilconway .
## Are these changes tested?
All original tests passed. Added some unit tests and sqllogictests.
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
No.
---------
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>1 parent d6fb360 commit e76f0ee
2 files changed
Lines changed: 21 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
954 | 954 | | |
955 | 955 | | |
956 | 956 | | |
957 | | - | |
958 | | - | |
959 | | - | |
960 | | - | |
961 | 957 | | |
962 | 958 | | |
963 | 959 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
0 commit comments