diff --git a/datafusion/expr/src/built_in_function.rs b/datafusion/expr/src/built_in_function.rs index 54ffc312a3bb..e8b4654b97bd 100644 --- a/datafusion/expr/src/built_in_function.rs +++ b/datafusion/expr/src/built_in_function.rs @@ -1395,25 +1395,25 @@ macro_rules! make_utf8_to_return_type { DataType::LargeUtf8 => $largeUtf8Type, DataType::Utf8 => $utf8Type, DataType::Null => DataType::Null, - DataType::Dictionary(_, value_type) => { - match **value_type { - DataType::LargeUtf8 => $largeUtf8Type, - DataType::Utf8 => $utf8Type, - DataType::Null => DataType::Null, - _ => { - // this error is internal as `data_types` should have captured this. - return internal_err!( - "The {:?} function can only accept strings.", - name - ); - } + DataType::Dictionary(_, value_type) => match **value_type { + DataType::LargeUtf8 => $largeUtf8Type, + DataType::Utf8 => $utf8Type, + DataType::Null => DataType::Null, + _ => { + // this error is internal as `data_types` should have captured this. + return plan_err!( + "The {:?} function can only accept strings, but got {:?}.", + name, + **value_type + ); } - } - _ => { + }, + data_type => { // this error is internal as `data_types` should have captured this. - return internal_err!( - "The {:?} function can only accept strings.", - name + return plan_err!( + "The {:?} function can only accept strings, but got {:?}.", + name, + data_type ); } }) diff --git a/datafusion/sqllogictest/test_files/functions.slt b/datafusion/sqllogictest/test_files/functions.slt index f8dbf8a00d9d..fd3a28dfe06d 100644 --- a/datafusion/sqllogictest/test_files/functions.slt +++ b/datafusion/sqllogictest/test_files/functions.slt @@ -413,6 +413,12 @@ SELECT substr('alphabet', 3, CAST(NULL AS int)) ---- NULL +statement error The "substr" function can only accept strings, but got Int64. +SELECT substr(1, 3) + +statement error The "substr" function can only accept strings, but got Int64. +SELECT substr(1, 3, 4) + query T SELECT translate('12345', '143', 'ax') ----