Skip to content

Commit 43d0bcf

Browse files
authored
Fix panic on wrong number of arguments to substr (#12837)
1 parent 8945e7a commit 43d0bcf

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

datafusion/functions/src/unicode/substr.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ impl ScalarUDFImpl for SubstrFunc {
8484
}
8585

8686
fn coerce_types(&self, arg_types: &[DataType]) -> Result<Vec<DataType>> {
87+
if arg_types.len() < 2 || arg_types.len() > 3 {
88+
return plan_err!(
89+
"The {} function requires 2 or 3 arguments, but got {}.",
90+
self.name(),
91+
arg_types.len()
92+
);
93+
}
8794
let first_data_type = match &arg_types[0] {
8895
DataType::Null => Ok(DataType::Utf8),
8996
DataType::LargeUtf8 | DataType::Utf8View | DataType::Utf8 => Ok(arg_types[0].clone()),

datafusion/sqllogictest/test_files/errors.slt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,6 @@ order by c9
130130

131131
query error DataFusion error: Arrow error: Cast error: Cannot cast string 'foo' to value of Int64 type
132132
create table foo as values (1), ('foo');
133+
134+
query error No function matches
135+
select 1 group by substr('');

0 commit comments

Comments
 (0)