Skip to content

Commit ad60ffc

Browse files
Omega359alamb
andauthored
Improve error messages to include the function name. (#14511)
* Improve error messages to include the function name. * Apply suggestions from code review Words better this PR has. Co-authored-by: Andrew Lamb <[email protected]> * Updates and fixes from PR review. * Updated error messages to highlight the function name. --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent 55730dc commit ad60ffc

File tree

10 files changed

+141
-99
lines changed

10 files changed

+141
-99
lines changed

datafusion/expr/src/type_coercion/functions.rs

Lines changed: 116 additions & 74 deletions
Large diffs are not rendered by default.

datafusion/optimizer/src/analyzer/type_coercion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ mod test {
13721372

13731373
let err = Projection::try_new(vec![udaf], empty).err().unwrap();
13741374
assert!(
1375-
err.strip_backtrace().starts_with("Error during planning: Failed to coerce arguments to satisfy a call to MY_AVG function: coercion from [Utf8] to the signature Uniform(1, [Float64]) failed")
1375+
err.strip_backtrace().starts_with("Error during planning: Failed to coerce arguments to satisfy a call to 'MY_AVG' function: coercion from [Utf8] to the signature Uniform(1, [Float64]) failed")
13761376
);
13771377
Ok(())
13781378
}
@@ -1422,7 +1422,7 @@ mod test {
14221422
.err()
14231423
.unwrap()
14241424
.strip_backtrace();
1425-
assert!(err.starts_with("Error during planning: Failed to coerce arguments to satisfy a call to avg function: coercion from [Utf8] to the signature Uniform(1, [Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64]) failed."));
1425+
assert!(err.starts_with("Error during planning: Failed to coerce arguments to satisfy a call to 'avg' function: coercion from [Utf8] to the signature Uniform(1, [Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64]) failed"));
14261426
Ok(())
14271427
}
14281428

datafusion/sql/tests/sql_integration.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4518,7 +4518,7 @@ fn error_message_test(sql: &str, err_msg_starts_with: &str) {
45184518
fn test_error_message_invalid_scalar_function_signature() {
45194519
error_message_test(
45204520
"select sqrt()",
4521-
"Error during planning: sqrt does not support zero arguments",
4521+
"Error during planning: 'sqrt' does not support zero arguments",
45224522
);
45234523
error_message_test(
45244524
"select sqrt(1, 2)",
@@ -4530,29 +4530,29 @@ fn test_error_message_invalid_scalar_function_signature() {
45304530
fn test_error_message_invalid_aggregate_function_signature() {
45314531
error_message_test(
45324532
"select sum()",
4533-
"Error during planning: sum does not support zero arguments",
4533+
"Error during planning: 'sum' does not support zero arguments",
45344534
);
45354535
// We keep two different prefixes because they clarify each other.
45364536
// It might be incorrect, and we should consider keeping only one.
45374537
error_message_test(
45384538
"select max(9, 3)",
4539-
"Error during planning: Execution error: User-defined coercion failed",
4539+
"Error during planning: Execution error: Function 'max' user-defined coercion failed",
45404540
);
45414541
}
45424542

45434543
#[test]
45444544
fn test_error_message_invalid_window_function_signature() {
45454545
error_message_test(
45464546
"select rank(1) over()",
4547-
"Error during planning: The function expected zero argument but received 1",
4547+
"Error during planning: The function 'rank' expected zero argument but received 1",
45484548
);
45494549
}
45504550

45514551
#[test]
45524552
fn test_error_message_invalid_window_aggregate_function_signature() {
45534553
error_message_test(
45544554
"select sum() over()",
4555-
"Error during planning: sum does not support zero arguments",
4555+
"Error during planning: 'sum' does not support zero arguments",
45564556
);
45574557
}
45584558

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,26 @@ statement error DataFusion error: Schema error: Schema contains duplicate unqual
132132
SELECT approx_distinct(c9) count_c9, approx_distinct(cast(c9 as varchar)) count_c9_str FROM aggregate_test_100
133133

134134
# csv_query_approx_percentile_cont_with_weight
135-
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to approx_percentile_cont_with_weight function: coercion from \[Utf8, Int8, Float64\] to the signature OneOf(.*) failed(.|\n)*
135+
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to 'approx_percentile_cont_with_weight' function: coercion from \[Utf8, Int8, Float64\] to the signature OneOf(.*) failed(.|\n)*
136136
SELECT approx_percentile_cont_with_weight(c1, c2, 0.95) FROM aggregate_test_100
137137

138-
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to approx_percentile_cont_with_weight function: coercion from \[Int16, Utf8, Float64\] to the signature OneOf(.*) failed(.|\n)*
138+
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to 'approx_percentile_cont_with_weight' function: coercion from \[Int16, Utf8, Float64\] to the signature OneOf(.*) failed(.|\n)*
139139
SELECT approx_percentile_cont_with_weight(c3, c1, 0.95) FROM aggregate_test_100
140140

141-
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to approx_percentile_cont_with_weight function: coercion from \[Int16, Int8, Utf8\] to the signature OneOf(.*) failed(.|\n)*
141+
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to 'approx_percentile_cont_with_weight' function: coercion from \[Int16, Int8, Utf8\] to the signature OneOf(.*) failed(.|\n)*
142142
SELECT approx_percentile_cont_with_weight(c3, c2, c1) FROM aggregate_test_100
143143

144144
# csv_query_approx_percentile_cont_with_histogram_bins
145145
statement error DataFusion error: External error: This feature is not implemented: Tdigest max_size value for 'APPROX_PERCENTILE_CONT' must be UInt > 0 literal \(got data type Int64\)\.
146146
SELECT c1, approx_percentile_cont(c3, 0.95, -1000) AS c3_p95 FROM aggregate_test_100 GROUP BY 1 ORDER BY 1
147147

148-
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to approx_percentile_cont function: coercion from \[Int16, Float64, Utf8\] to the signature OneOf(.*) failed(.|\n)*
148+
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to 'approx_percentile_cont' function: coercion from \[Int16, Float64, Utf8\] to the signature OneOf(.*) failed(.|\n)*
149149
SELECT approx_percentile_cont(c3, 0.95, c1) FROM aggregate_test_100
150150

151-
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to approx_percentile_cont function: coercion from \[Int16, Float64, Float64\] to the signature OneOf(.*) failed(.|\n)*
151+
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to 'approx_percentile_cont' function: coercion from \[Int16, Float64, Float64\] to the signature OneOf(.*) failed(.|\n)*
152152
SELECT approx_percentile_cont(c3, 0.95, 111.1) FROM aggregate_test_100
153153

154-
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to approx_percentile_cont function: coercion from \[Float64, Float64, Float64\] to the signature OneOf(.*) failed(.|\n)*
154+
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to 'approx_percentile_cont' function: coercion from \[Float64, Float64, Float64\] to the signature OneOf(.*) failed(.|\n)*
155155
SELECT approx_percentile_cont(c12, 0.95, 111.1) FROM aggregate_test_100
156156

157157
statement error DataFusion error: This feature is not implemented: Percentile value for 'APPROX_PERCENTILE_CONT' must be a literal

datafusion/sqllogictest/test_files/array.slt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ from arrays_values_without_nulls;
11911191
## array_element (aliases: array_extract, list_extract, list_element)
11921192

11931193
# Testing with empty arguments should result in an error
1194-
query error DataFusion error: Error during planning: array_element does not support zero arguments
1194+
query error DataFusion error: Error during planning: 'array_element' does not support zero arguments
11951195
select array_element();
11961196

11971197
# array_element error
@@ -2074,7 +2074,7 @@ select array_slice(a, -1, 2, 1), array_slice(a, -1, 2),
20742074
[6.0] [6.0] [] []
20752075

20762076
# Testing with empty arguments should result in an error
2077-
query error DataFusion error: Error during planning: array_slice does not support zero arguments
2077+
query error DataFusion error: Error during planning: 'array_slice' does not support zero arguments
20782078
select array_slice();
20792079

20802080
query error Failed to coerce arguments

datafusion/sqllogictest/test_files/errors.slt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,19 @@ query error
108108
select avg(c1, c12) from aggregate_test_100;
109109

110110
# AggregateFunction with wrong argument type
111-
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to regr_slope function: coercion from
111+
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to 'regr_slope' function: coercion from
112112
select regr_slope(1, '2');
113113

114114
# WindowFunction using AggregateFunction wrong signature
115-
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to regr_slope function: coercion from
115+
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to 'regr_slope' function: coercion from
116116
select
117117
c9,
118118
regr_slope(c11, '2') over () as min1
119119
from aggregate_test_100
120120
order by c9
121121

122122
# WindowFunction wrong signature
123-
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to nth_value function: coercion from \[Int32, Int64, Int64\] to the signature OneOf\(\[Any\(0\), Any\(1\), Any\(2\)\]\) failed
123+
statement error DataFusion error: Error during planning: Failed to coerce arguments to satisfy a call to 'nth_value' function: coercion from \[Int32, Int64, Int64\] to the signature OneOf\(\[Any\(0\), Any\(1\), Any\(2\)\]\) failed
124124
select
125125
c9,
126126
nth_value(c5, 2, 3) over (order by c9) as nv1

datafusion/sqllogictest/test_files/expr.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ select repeat('-1.2', arrow_cast(3, 'Int32'));
571571
----
572572
-1.2-1.2-1.2
573573

574-
query error DataFusion error: Error during planning: Internal error: Expect TypeSignatureClass::Native\(LogicalType\(Native\(Int64\), Int64\)\) but received Float64
574+
query error DataFusion error: Error during planning: Internal error: Function 'repeat' expects TypeSignatureClass::Native\(LogicalType\(Native\(Int64\), Int64\)\) but received Float64
575575
select repeat('-1.2', 3.2);
576576

577577
query T

datafusion/sqllogictest/test_files/functions.slt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ SELECT greatest(-1, 1, 2.3, 123456789, 3 + 5, -(-4), abs(-9.0))
842842
123456789
843843

844844

845-
query error greatest does not support zero arguments
845+
query error 'greatest' does not support zero argument
846846
SELECT greatest()
847847

848848
query I
@@ -1040,7 +1040,7 @@ SELECT least(-1, 1, 2.3, 123456789, 3 + 5, -(-4), abs(-9.0))
10401040
-1
10411041

10421042

1043-
query error least does not support zero arguments
1043+
query error 'least' does not support zero arguments
10441044
SELECT least()
10451045

10461046
query I

datafusion/sqllogictest/test_files/math.slt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ statement error
126126
SELECT abs(1, 2);
127127

128128
# abs: unsupported argument type
129-
query error DataFusion error: Error during planning: The signature expected NativeType::Numeric but received NativeType::String
129+
query error DataFusion error: Error during planning: Function 'abs' expects NativeType::Numeric but received NativeType::String
130130
SELECT abs('foo');
131131

132132
# abs: numeric string
133133
# TODO: In Postgres, '-1.2' is unknown type and interpreted to float8 so they don't fail on this query
134-
query error DataFusion error: Error during planning: The signature expected NativeType::Numeric but received NativeType::String
134+
query error DataFusion error: Error during planning: Function 'abs' expects NativeType::Numeric but received NativeType::String
135135
select abs('-1.2');
136136

137-
query error DataFusion error: Error during planning: The signature expected NativeType::Numeric but received NativeType::String
137+
query error DataFusion error: Error during planning: Function 'abs' expects NativeType::Numeric but received NativeType::String
138138
select abs(arrow_cast('-1.2', 'Utf8'));
139139

140140
statement ok

datafusion/sqllogictest/test_files/scalar.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ select position('' in '')
19451945
----
19461946
1
19471947

1948-
query error DataFusion error: Error during planning: The signature expected NativeType::String but received NativeType::Int64
1948+
query error DataFusion error: Error during planning: Function 'strpos' expects NativeType::String but received NativeType::Int64
19491949
select position(1 in 1)
19501950

19511951
query I

0 commit comments

Comments
 (0)