Apache DataFusion SQL Query Engine
refine: `substr` error (#7339)
Alex Huang4275e15c0ded
diff --git a/datafusion/expr/src/built_in_function.rs b/datafusion/expr/src/built_in_function.rsindex 54ffc312a3..e8b4654b97 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.sltindex f8dbf8a00d..fd3a28dfe0 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 TSELECT translate('12345', '143', 'ax')----