Skip to content

Commit

Permalink
refine: substr error (apache#7339)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
Weijun-H and jackwener authored Aug 21, 2023
1 parent 25e6c7d commit 4275e15
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
34 changes: 17 additions & 17 deletions datafusion/expr/src/built_in_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
})
Expand Down
6 changes: 6 additions & 0 deletions datafusion/sqllogictest/test_files/functions.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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')
----
Expand Down

0 comments on commit 4275e15

Please sign in to comment.