This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 4275e15c0d refine: `substr` error (#7339)
4275e15c0d is described below

commit 4275e15c0ded0a37c7fc74f8aed574df87c5d765
Author: Alex Huang <[email protected]>
AuthorDate: Tue Aug 22 02:54:47 2023 +0800

    refine: `substr` error (#7339)
    
    * refine: substr error
    
    * fix format
    
    * Update datafusion/expr/src/built_in_function.rs
    
    Co-authored-by: jakevin <[email protected]>
    
    * Update datafusion/expr/src/built_in_function.rs
    
    Co-authored-by: jakevin <[email protected]>
    
    * add more tests
    
    ---------
    
    Co-authored-by: jakevin <[email protected]>
---
 datafusion/expr/src/built_in_function.rs         | 34 ++++++++++++------------
 datafusion/sqllogictest/test_files/functions.slt |  6 +++++
 2 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/datafusion/expr/src/built_in_function.rs 
b/datafusion/expr/src/built_in_function.rs
index 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.slt
index 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 T
 SELECT translate('12345', '143', 'ax')
 ----

Reply via email to