Skip to content

Commit ec2daa6

Browse files
authored
minor: fix error message function naming (#9168)
* minor: fix error message function naming * fix
1 parent bb5330f commit ec2daa6

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

datafusion/expr/src/built_in_function.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ impl BuiltinScalarFunction {
719719
utf8_to_str_type(&input_expr_types[0], "initcap")
720720
}
721721
BuiltinScalarFunction::InStr => {
722-
utf8_to_int_type(&input_expr_types[0], "instr")
722+
utf8_to_int_type(&input_expr_types[0], "instr/position")
723723
}
724724
BuiltinScalarFunction::Left => utf8_to_str_type(&input_expr_types[0], "left"),
725725
BuiltinScalarFunction::Lower => {
@@ -822,22 +822,22 @@ impl BuiltinScalarFunction {
822822
BuiltinScalarFunction::Upper => {
823823
utf8_to_str_type(&input_expr_types[0], "upper")
824824
}
825-
BuiltinScalarFunction::RegexpLike => Ok(match input_expr_types[0] {
825+
BuiltinScalarFunction::RegexpLike => Ok(match &input_expr_types[0] {
826826
LargeUtf8 | Utf8 => Boolean,
827827
Null => Null,
828-
_ => {
828+
other => {
829829
return plan_err!(
830-
"The regexp_like function can only accept strings."
830+
"The regexp_like function can only accept strings. Got {other}"
831831
);
832832
}
833833
}),
834-
BuiltinScalarFunction::RegexpMatch => Ok(match input_expr_types[0] {
834+
BuiltinScalarFunction::RegexpMatch => Ok(match &input_expr_types[0] {
835835
LargeUtf8 => List(Arc::new(Field::new("item", LargeUtf8, true))),
836836
Utf8 => List(Arc::new(Field::new("item", Utf8, true))),
837837
Null => Null,
838-
_ => {
838+
other => {
839839
return plan_err!(
840-
"The regexp_match function can only accept strings."
840+
"The regexp_match function can only accept strings. Got {other}"
841841
);
842842
}
843843
}),
@@ -1644,54 +1644,51 @@ impl FromStr for BuiltinScalarFunction {
16441644
}
16451645
}
16461646

1647-
/// Creates a function that returns the return type of a string function given
1647+
/// Creates a function to identify the optimal return type of a string function given
16481648
/// the type of its first argument.
16491649
///
16501650
/// If the input type is `LargeUtf8` or `LargeBinary` the return type is
16511651
/// `$largeUtf8Type`,
16521652
///
16531653
/// If the input type is `Utf8` or `Binary` the return type is `$utf8Type`,
1654-
macro_rules! make_utf8_to_return_type {
1654+
macro_rules! get_optimal_return_type {
16551655
($FUNC:ident, $largeUtf8Type:expr, $utf8Type:expr) => {
16561656
fn $FUNC(arg_type: &DataType, name: &str) -> Result<DataType> {
16571657
Ok(match arg_type {
1658-
DataType::LargeUtf8 => $largeUtf8Type,
16591658
// LargeBinary inputs are automatically coerced to Utf8
1660-
DataType::LargeBinary => $largeUtf8Type,
1661-
DataType::Utf8 => $utf8Type,
1659+
DataType::LargeUtf8 | DataType::LargeBinary => $largeUtf8Type,
16621660
// Binary inputs are automatically coerced to Utf8
1663-
DataType::Binary => $utf8Type,
1661+
DataType::Utf8 | DataType::Binary => $utf8Type,
16641662
DataType::Null => DataType::Null,
16651663
DataType::Dictionary(_, value_type) => match **value_type {
1666-
DataType::LargeUtf8 => $largeUtf8Type,
1667-
DataType::LargeBinary => $largeUtf8Type,
1668-
DataType::Utf8 => $utf8Type,
1669-
DataType::Binary => $utf8Type,
1664+
DataType::LargeUtf8 | DataType::LargeBinary => $largeUtf8Type,
1665+
DataType::Utf8 | DataType::Binary => $utf8Type,
16701666
DataType::Null => DataType::Null,
16711667
_ => {
16721668
return plan_err!(
1673-
"The {:?} function can only accept strings, but got {:?}.",
1674-
name,
1669+
"The {} function can only accept strings, but got {:?}.",
1670+
name.to_uppercase(),
16751671
**value_type
16761672
);
16771673
}
16781674
},
16791675
data_type => {
16801676
return plan_err!(
1681-
"The {:?} function can only accept strings, but got {:?}.",
1682-
name,
1677+
"The {} function can only accept strings, but got {:?}.",
1678+
name.to_uppercase(),
16831679
data_type
16841680
);
16851681
}
16861682
})
16871683
}
16881684
};
16891685
}
1686+
16901687
// `utf8_to_str_type`: returns either a Utf8 or LargeUtf8 based on the input type size.
1691-
make_utf8_to_return_type!(utf8_to_str_type, DataType::LargeUtf8, DataType::Utf8);
1688+
get_optimal_return_type!(utf8_to_str_type, DataType::LargeUtf8, DataType::Utf8);
16921689

16931690
// `utf8_to_int_type`: returns either a Int32 or Int64 based on the input type size.
1694-
make_utf8_to_return_type!(utf8_to_int_type, DataType::Int64, DataType::Int32);
1691+
get_optimal_return_type!(utf8_to_int_type, DataType::Int64, DataType::Int32);
16951692

16961693
fn utf8_or_binary_to_binary_type(arg_type: &DataType, name: &str) -> Result<DataType> {
16971694
Ok(match arg_type {

datafusion/sqllogictest/test_files/functions.slt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,10 @@ SELECT substr('alphabet', 3, CAST(NULL AS int))
413413
----
414414
NULL
415415

416-
statement error The "substr" function can only accept strings, but got Int64.
416+
statement error The SUBSTR function can only accept strings, but got Int64.
417417
SELECT substr(1, 3)
418418

419-
statement error The "substr" function can only accept strings, but got Int64.
419+
statement error The SUBSTR function can only accept strings, but got Int64.
420420
SELECT substr(1, 3, 4)
421421

422422
query T

datafusion/sqllogictest/test_files/scalar.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1994,5 +1994,5 @@ select position('' in '')
19941994
1
19951995

19961996

1997-
query error DataFusion error: Error during planning: The "instr" function can only accept strings, but got Int64\.
1997+
query error DataFusion error: Error during planning: The INSTR/POSITION function can only accept strings, but got Int64.
19981998
select position(1 in 1)

0 commit comments

Comments
 (0)