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/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 43d0bcf609 Fix panic on wrong number of arguments to substr (#12837)
43d0bcf609 is described below
commit 43d0bcf609744dc97d7b05fe93142a5e6059b82b
Author: Emil Ejbyfeldt <[email protected]>
AuthorDate: Thu Oct 10 14:39:50 2024 +0200
Fix panic on wrong number of arguments to substr (#12837)
---
datafusion/functions/src/unicode/substr.rs | 7 +++++++
datafusion/sqllogictest/test_files/errors.slt | 3 +++
2 files changed, 10 insertions(+)
diff --git a/datafusion/functions/src/unicode/substr.rs
b/datafusion/functions/src/unicode/substr.rs
index c253ef7e03..969969ef2f 100644
--- a/datafusion/functions/src/unicode/substr.rs
+++ b/datafusion/functions/src/unicode/substr.rs
@@ -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()),
diff --git a/datafusion/sqllogictest/test_files/errors.slt
b/datafusion/sqllogictest/test_files/errors.slt
index 7abf94932c..ce09475253 100644
--- a/datafusion/sqllogictest/test_files/errors.slt
+++ b/datafusion/sqllogictest/test_files/errors.slt
@@ -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('');
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]