Skip to content

Commit a8177b8

Browse files
committed
test: fix OneOf error expectations in CI
Signed-off-by: yaommen <myanstu@163.com>
1 parent a40c2e9 commit a8177b8

File tree

7 files changed

+86
-40
lines changed

7 files changed

+86
-40
lines changed

datafusion/expr/src/type_coercion/functions.rs

Lines changed: 74 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ use datafusion_common::utils::{
2727
ListCoercion, base_type, coerced_fixed_size_list_to_list,
2828
};
2929
use datafusion_common::{
30-
Result, exec_err, internal_err, plan_err, types::NativeType, utils::list_ndims,
30+
DataFusionError, Result, exec_err, internal_err, plan_err, types::NativeType,
31+
utils::list_ndims,
3132
};
3233
use datafusion_expr_common::signature::ArrayFunctionArgument;
3334
use datafusion_expr_common::type_coercion::binary::type_union_resolution;
@@ -325,23 +326,30 @@ fn get_valid_types_with_udf<F: UDFCoercionExt>(
325326
},
326327
TypeSignature::OneOf(signatures) => {
327328
let mut res = vec![];
329+
let mut deferred_err = None;
328330
for sig in signatures {
329-
if let Ok(valid_types) =
330-
get_valid_types_with_udf(sig, current_types, func)
331-
{
332-
res.extend(valid_types);
331+
match get_valid_types_with_udf(sig, current_types, func) {
332+
Ok(valid_types) => res.extend(valid_types),
333+
Err(DataFusionError::Plan(_)) => {}
334+
Err(err) => {
335+
if deferred_err.is_none() {
336+
deferred_err = Some(err);
337+
}
338+
}
333339
}
334340
}
335341

336-
// Every signature failed, return a neutral planning error rather than
337-
// a branch-specific error that may not match the best overload.
338-
if res.is_empty() {
342+
if !res.is_empty() {
343+
res
344+
} else if let Some(err) = deferred_err {
345+
return Err(err);
346+
} else {
347+
// Every signature failed, return a neutral planning error rather than
348+
// a branch-specific error that may not match the best overload.
339349
return plan_err!(
340350
"Function '{}' failed to match any signature",
341351
func.name()
342352
);
343-
} else {
344-
res
345353
}
346354
}
347355
_ => get_valid_types(func.name(), signature, current_types)?,
@@ -1224,29 +1232,22 @@ mod tests {
12241232
let current_fields = vec![Arc::new(Field::new("t", DataType::Boolean, true))];
12251233
let signature = Signature::one_of(
12261234
vec![
1227-
Signature::coercible(
1228-
vec![Coercion::new_exact(TypeSignatureClass::Decimal)],
1229-
Volatility::Immutable,
1230-
)
1231-
.type_signature
1232-
.clone(),
1233-
Signature::coercible(
1234-
vec![Coercion::new_exact(TypeSignatureClass::Duration)],
1235-
Volatility::Immutable,
1236-
)
1237-
.type_signature
1238-
.clone(),
1235+
TypeSignature::Coercible(vec![Coercion::new_exact(
1236+
TypeSignatureClass::Decimal,
1237+
)]),
1238+
TypeSignature::Coercible(vec![Coercion::new_exact(
1239+
TypeSignatureClass::Duration,
1240+
)]),
12391241
],
12401242
Volatility::Immutable,
12411243
);
12421244

12431245
let err = fields_with_udf(&current_fields, &MockUdf(signature)).unwrap_err();
12441246
let err = err.to_string();
12451247

1246-
assert_eq!(
1247-
err,
1248+
assert!(err.starts_with(
12481249
"Error during planning: Function 'test' failed to match any signature"
1249-
);
1250+
));
12501251
assert!(!err.contains("Internal error"));
12511252
assert!(!err.contains("TypeSignatureClass"));
12521253
}
@@ -1262,13 +1263,58 @@ mod tests {
12621263
let err = fields_with_udf(&current_fields, &MockUdf(signature)).unwrap_err();
12631264
let err = err.to_string();
12641265

1265-
assert_eq!(
1266-
err,
1266+
assert!(err.starts_with(
12671267
"Error during planning: Function 'test' failed to match any signature"
1268-
);
1268+
));
12691269
assert!(!err.contains("Internal error"));
12701270
}
12711271

1272+
struct AlwaysExecErrUdf(Signature);
1273+
1274+
impl UDFCoercionExt for AlwaysExecErrUdf {
1275+
fn name(&self) -> &str {
1276+
"test"
1277+
}
1278+
1279+
fn signature(&self) -> &Signature {
1280+
&self.0
1281+
}
1282+
1283+
fn coerce_types(&self, _arg_types: &[DataType]) -> Result<Vec<DataType>> {
1284+
exec_err!("boom")
1285+
}
1286+
}
1287+
1288+
#[test]
1289+
fn test_one_of_propagates_non_plan_errors() {
1290+
let current_fields = vec![Arc::new(Field::new("t", DataType::Int32, true))];
1291+
let signature =
1292+
Signature::one_of(vec![TypeSignature::UserDefined], Volatility::Immutable);
1293+
1294+
let err =
1295+
fields_with_udf(&current_fields, &AlwaysExecErrUdf(signature)).unwrap_err();
1296+
1297+
assert_eq!(
1298+
err.to_string(),
1299+
"Execution error: Function 'test' user-defined coercion failed with: Execution error: boom"
1300+
);
1301+
}
1302+
1303+
#[test]
1304+
fn test_one_of_preserves_success_when_later_branch_errors() -> Result<()> {
1305+
let current_fields = vec![Arc::new(Field::new("t", DataType::Int32, true))];
1306+
let signature = Signature::one_of(
1307+
vec![TypeSignature::Exact(vec![DataType::Int32]), TypeSignature::UserDefined],
1308+
Volatility::Immutable,
1309+
);
1310+
1311+
let fields = fields_with_udf(&current_fields, &AlwaysExecErrUdf(signature))?;
1312+
1313+
assert_eq!(fields.len(), 1);
1314+
assert_eq!(fields[0].data_type(), &DataType::Int32);
1315+
Ok(())
1316+
}
1317+
12721318
#[test]
12731319
fn test_nested_wildcard_fixed_size_lists() -> Result<()> {
12741320
let type_into = DataType::FixedSizeList(

datafusion/sqllogictest/test_files/array.slt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7798,17 +7798,17 @@ select generate_series(arrow_cast('2021-01-01T00:00:00', 'Timestamp(Nanosecond,
77987798
[2021-01-01T00:00:00-05:00, 2021-01-01T01:29:54.500-05:00, 2021-01-01T02:59:49-05:00, 2021-01-01T04:29:43.500-05:00, 2021-01-01T05:59:38-05:00]
77997799

78007800
## mixing types for timestamps is not supported
7801-
query error DataFusion error: Error during planning: Function 'generate_series' failed to match any signature(.|\n)*generate_series\(Timestamp\(ns, "-05:00"\), Date32, Interval\(MonthDayNano\)\)(.|\n)*Candidate functions:
7801+
query error DataFusion error: Error during planning: Function 'generate_series' failed to match any signature
78027802
select generate_series(arrow_cast('2021-01-01T00:00:00', 'Timestamp(Nanosecond, Some("-05:00"))'), DATE '2021-01-02', INTERVAL '1' HOUR);
78037803

78047804
## mixing types not allowed even if an argument is null
7805-
query error DataFusion error: Error during planning: Function 'generate_series' failed to match any signature(.|\n)*generate_series\(Timestamp\(ns\), Date32, Null\)(.|\n)*Candidate functions:
7805+
query error DataFusion error: Error during planning: Function 'generate_series' failed to match any signature
78067806
select generate_series(TIMESTAMP '1992-09-01', DATE '1993-03-01', NULL);
78077807

7808-
query error DataFusion error: Error during planning: Function 'generate_series' failed to match any signature(.|\n)*generate_series\(Int64, Utf8, Utf8\)(.|\n)*Candidate functions:
7808+
query error DataFusion error: Error during planning: Function 'generate_series' failed to match any signature
78097809
select generate_series(1, '2024-01-01', '2025-01-02');
78107810

7811-
query error DataFusion error: Error during planning: Function 'generate_series' failed to match any signature(.|\n)*generate_series\(Timestamp\(ns\), Utf8, Interval\(MonthDayNano\)\)(.|\n)*Candidate functions:
7811+
query error DataFusion error: Error during planning: Function 'generate_series' failed to match any signature
78127812
select generate_series('2024-01-01'::timestamp, '2025-01-02', interval '1 day');
78137813

78147814
## should return NULL

datafusion/sqllogictest/test_files/errors.slt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ from aggregate_test_100
125125
order by c9
126126

127127
# WindowFunction wrong signature
128-
statement error DataFusion error: Error during planning: Function 'nth_value' failed to match any signature(.|\n)*nth_value\(Int32, Int64, Int64\)(.|\n)*Candidate functions:
128+
statement error DataFusion error: Error during planning: Function 'nth_value' failed to match any signature
129129
select
130130
c9,
131131
nth_value(c5, 2, 3) over (order by c9) as nv1
132132
from aggregate_test_100
133133
order by c9
134134

135-
query error DataFusion error: Error during planning: Function 'sum' failed to match any signature(.|\n)*sum\(Boolean\)(.|\n)*Candidate functions:
135+
query error DataFusion error: Error during planning: Function 'sum' failed to match any signature
136136
select sum(bool_col) from (values (true), (false), (null)) as t(bool_col);
137137

138138

datafusion/sqllogictest/test_files/functions.slt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ SELECT substr('alphabet', NULL, 2)
208208
----
209209
NULL
210210

211-
statement error DataFusion error: Error during planning: Function 'substr' failed to match any signature(.|\n)*Candidate functions:
211+
statement error DataFusion error: Error during planning: Function 'substr' failed to match any signature
212212
SELECT substr(1, 3)
213213

214-
statement error DataFusion error: Error during planning: Function 'substr' failed to match any signature(.|\n)*Candidate functions:
214+
statement error DataFusion error: Error during planning: Function 'substr' failed to match any signature
215215
SELECT substr(1, 3, 4)
216216

217217
query T

datafusion/sqllogictest/test_files/named_arguments.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ SELECT substr("STR" => 'hello world', "start_pos" => 7);
8686

8787
# Error: wrong number of arguments
8888
# This query provides only 1 argument but substr requires 2 or 3
89-
query error DataFusion error: Error during planning: Function 'substr' failed to match any signature(.|\n)*Candidate functions:
89+
query error DataFusion error: Error during planning: Function 'substr' failed to match any signature
9090
SELECT substr(str => 'hello world');
9191

9292
#############

datafusion/sqllogictest/test_files/spark/math/hex.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ SELECT hex(column1) FROM VALUES (arrow_cast('hello', 'LargeBinary')), (NULL), (a
5656
NULL
5757
776F726C64
5858

59-
statement error Function 'hex' expects 1 arguments but received 2
59+
statement error DataFusion error: Error during planning: Function 'hex' failed to match any signature
6060
SELECT hex(1, 2);
6161

6262
query T

datafusion/sqllogictest/test_files/string/string_literal.slt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ SELECT substr('Hello🌏世界', 5, 3)
132132
----
133133
o🌏世
134134

135-
statement error DataFusion error: Error during planning: Function 'substr' failed to match any signature(.|\n)*Candidate functions:
135+
statement error DataFusion error: Error during planning: Function 'substr' failed to match any signature
136136
SELECT substr(1, 3)
137137

138-
statement error DataFusion error: Error during planning: Function 'substr' failed to match any signature(.|\n)*Candidate functions:
138+
statement error DataFusion error: Error during planning: Function 'substr' failed to match any signature
139139
SELECT substr(1, 3, 4)
140140

141141
statement error Execution error: negative substring length not allowed

0 commit comments

Comments
 (0)