Skip to content

Commit

Permalink
Fix panic on wrong number of arguments to substr (#12837)
Browse files Browse the repository at this point in the history
  • Loading branch information
eejbyfeldt authored Oct 10, 2024
1 parent 8945e7a commit 43d0bcf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions datafusion/functions/src/unicode/substr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ impl ScalarUDFImpl for SubstrFunc {
}

fn coerce_types(&self, arg_types: &[DataType]) -> Result<Vec<DataType>> {
if arg_types.len() < 2 || arg_types.len() > 3 {
return plan_err!(
"The {} function requires 2 or 3 arguments, but got {}.",
self.name(),
arg_types.len()
);
}
let first_data_type = match &arg_types[0] {
DataType::Null => Ok(DataType::Utf8),
DataType::LargeUtf8 | DataType::Utf8View | DataType::Utf8 => Ok(arg_types[0].clone()),
Expand Down
3 changes: 3 additions & 0 deletions datafusion/sqllogictest/test_files/errors.slt
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,6 @@ order by c9

query error DataFusion error: Arrow error: Cast error: Cannot cast string 'foo' to value of Int64 type
create table foo as values (1), ('foo');

query error No function matches
select 1 group by substr('');

0 comments on commit 43d0bcf

Please sign in to comment.