diff --git a/src/frontend/src/expr/type_inference/cast.rs b/src/frontend/src/expr/type_inference/cast.rs index cafa670a4ec5f..76ff7f307a573 100644 --- a/src/frontend/src/expr/type_inference/cast.rs +++ b/src/frontend/src/expr/type_inference/cast.rs @@ -27,7 +27,7 @@ use crate::expr::{Expr as _, ExprImpl}; /// /// If you also need to cast them to this type, and there are more than 2 exprs, check out /// [`align_types`]. -pub fn least_restrictive(lhs: DataType, rhs: DataType) -> Result { +pub fn least_restrictive(lhs: DataType, rhs: DataType) -> std::result::Result { if lhs == rhs { Ok(lhs) } else if cast_ok(&lhs, &rhs, CastContext::Implicit) { @@ -35,13 +35,18 @@ pub fn least_restrictive(lhs: DataType, rhs: DataType) -> Result { } else if cast_ok(&rhs, &lhs, CastContext::Implicit) { Ok(lhs) } else { - Err(ErrorCode::BindError(format!("types {:?} and {:?} cannot be matched", lhs, rhs)).into()) + Err(ErrorCode::BindError(format!( + "types {:?} and {:?} cannot be matched", + lhs, rhs + ))) } } /// Find the `least_restrictive` type over a list of `exprs`, and add implicit cast when necessary. /// Used by `VALUES`, `CASE`, `UNION`, etc. See [PG](https://www.postgresql.org/docs/current/typeconv-union-case.html). -pub fn align_types<'a>(exprs: impl Iterator) -> Result { +pub fn align_types<'a>( + exprs: impl Iterator, +) -> std::result::Result { use std::mem::swap; let exprs = exprs.collect_vec(); @@ -60,7 +65,8 @@ pub fn align_types<'a>(exprs: impl Iterator) -> Result< for e in exprs { let mut dummy = ExprImpl::literal_bool(false); swap(&mut dummy, e); - *e = dummy.cast_implicit(ret_type.clone())?; + // unwrap: cast to least_restrictive type always succeeds + *e = dummy.cast_implicit(ret_type.clone()).unwrap(); } Ok(ret_type) } diff --git a/src/frontend/src/expr/type_inference/func.rs b/src/frontend/src/expr/type_inference/func.rs index 65494e41afbf6..a9225ea0eaf49 100644 --- a/src/frontend/src/expr/type_inference/func.rs +++ b/src/frontend/src/expr/type_inference/func.rs @@ -118,6 +118,7 @@ fn infer_type_for_special( } })) .map(Some) + .map_err(Into::into) } ExprType::In => { align_types(inputs.iter_mut())?; @@ -125,7 +126,7 @@ fn infer_type_for_special( } ExprType::Coalesce => { ensure_arity!("coalesce", 1 <= | inputs |); - align_types(inputs.iter_mut()).map(Some) + align_types(inputs.iter_mut()).map(Some).map_err(Into::into) } ExprType::ConcatWs => { ensure_arity!("concat_ws", 2 <= | inputs |);