neilconway commented on code in PR #20306:
URL: https://github.com/apache/datafusion/pull/20306#discussion_r2804703038
##########
datafusion/optimizer/src/analyzer/type_coercion.rs:
##########
@@ -744,18 +744,47 @@ impl TreeNodeRewriter for TypeCoercionRewriter<'_> {
});
Ok(Transformed::yes(new_expr))
}
+ // IS NULL / IS NOT NULL / SIMILAR TO / CAST / TRY_CAST validate
+ // their inner expressions during type coercion (previously they
were in
+ // the catch-all branch and skipped validation, which caused
panics at
+ // runtime for invalid inner expressions like zero-argument
function calls).
+ // Detail: <https://github.com/apache/datafusion/issues/20201>
+ //
+ // TODO: reject the invalid cases at planning.
+ Expr::IsNotNull(ref inner_expr) | Expr::IsNull(ref inner_expr) => {
+ let _check_type = inner_expr.get_type(self.schema)?;
+ Ok(Transformed::no(expr))
+ }
+ Expr::SimilarTo(Like {
Review Comment:
I wasn't thinking about optimizations; my concern was more whether the type
coercion that is done for `LIKE` should also be done for `IS SIMILAR TO` for
correctness reasons. Some digging suggests this might be the case:
```
-- works
SELECT CAST('hello' AS BYTEA) LIKE 'hello%';
-- fails ("Cannot infer common argument type for regex operation Binary ~
Utf8")
SELECT CAST('hello' AS BYTEA) SIMILAR TO 'hello%';
-- works
SELECT arrow_cast('hello', 'Dictionary(Int32, Utf8)') LIKE 'hello%';
-- fails ("Data type Dictionary(Int32, Utf8) not supported for
regex_match_dyn")
SELECT arrow_cast('hello', 'Dictionary(Int32, Utf8)') SIMILAR TO 'hello%';
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]