This is an automated email from the ASF dual-hosted git repository.
comphead 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 ec2daa6e73 minor: fix error message function naming (#9168)
ec2daa6e73 is described below
commit ec2daa6e730ed8959a2f984af077a1622634885e
Author: comphead <[email protected]>
AuthorDate: Fri Feb 9 10:08:40 2024 -0800
minor: fix error message function naming (#9168)
* minor: fix error message function naming
* fix
---
datafusion/expr/src/built_in_function.rs | 43 +++++++++++-------------
datafusion/sqllogictest/test_files/functions.slt | 4 +--
datafusion/sqllogictest/test_files/scalar.slt | 2 +-
3 files changed, 23 insertions(+), 26 deletions(-)
diff --git a/datafusion/expr/src/built_in_function.rs
b/datafusion/expr/src/built_in_function.rs
index 9f0d5d7762..81c600b976 100644
--- a/datafusion/expr/src/built_in_function.rs
+++ b/datafusion/expr/src/built_in_function.rs
@@ -719,7 +719,7 @@ impl BuiltinScalarFunction {
utf8_to_str_type(&input_expr_types[0], "initcap")
}
BuiltinScalarFunction::InStr => {
- utf8_to_int_type(&input_expr_types[0], "instr")
+ utf8_to_int_type(&input_expr_types[0], "instr/position")
}
BuiltinScalarFunction::Left =>
utf8_to_str_type(&input_expr_types[0], "left"),
BuiltinScalarFunction::Lower => {
@@ -822,22 +822,22 @@ impl BuiltinScalarFunction {
BuiltinScalarFunction::Upper => {
utf8_to_str_type(&input_expr_types[0], "upper")
}
- BuiltinScalarFunction::RegexpLike => Ok(match input_expr_types[0] {
+ BuiltinScalarFunction::RegexpLike => Ok(match &input_expr_types[0]
{
LargeUtf8 | Utf8 => Boolean,
Null => Null,
- _ => {
+ other => {
return plan_err!(
- "The regexp_like function can only accept strings."
+ "The regexp_like function can only accept strings. Got
{other}"
);
}
}),
- BuiltinScalarFunction::RegexpMatch => Ok(match input_expr_types[0]
{
+ BuiltinScalarFunction::RegexpMatch => Ok(match
&input_expr_types[0] {
LargeUtf8 => List(Arc::new(Field::new("item", LargeUtf8,
true))),
Utf8 => List(Arc::new(Field::new("item", Utf8, true))),
Null => Null,
- _ => {
+ other => {
return plan_err!(
- "The regexp_match function can only accept strings."
+ "The regexp_match function can only accept strings.
Got {other}"
);
}
}),
@@ -1644,42 +1644,38 @@ impl FromStr for BuiltinScalarFunction {
}
}
-/// Creates a function that returns the return type of a string function given
+/// Creates a function to identify the optimal return type of a string
function given
/// the type of its first argument.
///
/// If the input type is `LargeUtf8` or `LargeBinary` the return type is
/// `$largeUtf8Type`,
///
/// If the input type is `Utf8` or `Binary` the return type is `$utf8Type`,
-macro_rules! make_utf8_to_return_type {
+macro_rules! get_optimal_return_type {
($FUNC:ident, $largeUtf8Type:expr, $utf8Type:expr) => {
fn $FUNC(arg_type: &DataType, name: &str) -> Result<DataType> {
Ok(match arg_type {
- DataType::LargeUtf8 => $largeUtf8Type,
// LargeBinary inputs are automatically coerced to Utf8
- DataType::LargeBinary => $largeUtf8Type,
- DataType::Utf8 => $utf8Type,
+ DataType::LargeUtf8 | DataType::LargeBinary => $largeUtf8Type,
// Binary inputs are automatically coerced to Utf8
- DataType::Binary => $utf8Type,
+ DataType::Utf8 | DataType::Binary => $utf8Type,
DataType::Null => DataType::Null,
DataType::Dictionary(_, value_type) => match **value_type {
- DataType::LargeUtf8 => $largeUtf8Type,
- DataType::LargeBinary => $largeUtf8Type,
- DataType::Utf8 => $utf8Type,
- DataType::Binary => $utf8Type,
+ DataType::LargeUtf8 | DataType::LargeBinary =>
$largeUtf8Type,
+ DataType::Utf8 | DataType::Binary => $utf8Type,
DataType::Null => DataType::Null,
_ => {
return plan_err!(
- "The {:?} function can only accept strings, but
got {:?}.",
- name,
+ "The {} function can only accept strings, but got
{:?}.",
+ name.to_uppercase(),
**value_type
);
}
},
data_type => {
return plan_err!(
- "The {:?} function can only accept strings, but got
{:?}.",
- name,
+ "The {} function can only accept strings, but got
{:?}.",
+ name.to_uppercase(),
data_type
);
}
@@ -1687,11 +1683,12 @@ macro_rules! make_utf8_to_return_type {
}
};
}
+
// `utf8_to_str_type`: returns either a Utf8 or LargeUtf8 based on the input
type size.
-make_utf8_to_return_type!(utf8_to_str_type, DataType::LargeUtf8,
DataType::Utf8);
+get_optimal_return_type!(utf8_to_str_type, DataType::LargeUtf8,
DataType::Utf8);
// `utf8_to_int_type`: returns either a Int32 or Int64 based on the input type
size.
-make_utf8_to_return_type!(utf8_to_int_type, DataType::Int64, DataType::Int32);
+get_optimal_return_type!(utf8_to_int_type, DataType::Int64, DataType::Int32);
fn utf8_or_binary_to_binary_type(arg_type: &DataType, name: &str) ->
Result<DataType> {
Ok(match arg_type {
diff --git a/datafusion/sqllogictest/test_files/functions.slt
b/datafusion/sqllogictest/test_files/functions.slt
index 7a4d7ef197..dc5e96d2d0 100644
--- a/datafusion/sqllogictest/test_files/functions.slt
+++ b/datafusion/sqllogictest/test_files/functions.slt
@@ -413,10 +413,10 @@ SELECT substr('alphabet', 3, CAST(NULL AS int))
----
NULL
-statement error The "substr" function can only accept strings, but got Int64.
+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.
+statement error The SUBSTR function can only accept strings, but got Int64.
SELECT substr(1, 3, 4)
query T
diff --git a/datafusion/sqllogictest/test_files/scalar.slt
b/datafusion/sqllogictest/test_files/scalar.slt
index cfc0caa900..129eb6508b 100644
--- a/datafusion/sqllogictest/test_files/scalar.slt
+++ b/datafusion/sqllogictest/test_files/scalar.slt
@@ -1994,5 +1994,5 @@ select position('' in '')
1
-query error DataFusion error: Error during planning: The "instr" function can
only accept strings, but got Int64\.
+query error DataFusion error: Error during planning: The INSTR/POSITION
function can only accept strings, but got Int64.
select position(1 in 1)