You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve error message when string functions receive Binary types (#19819)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes#123` indicates that this PR will close issue #123.
-->
- Related to #19004 and #19809.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
Change internal error to user-facing error when function type coercion
fails. Add helpful hint when Binary types are used with string
functions.
Before:
```
Internal error: Expect TypeSignatureClass::Native(...) but received NativeType::Binary, DataType: Binary
```
After:
```
Error: Function 'split_part' requires String, but received Binary (DataType: Binary).
Hint: Binary types are not automatically coerced to String. Use CAST(column AS VARCHAR) to convert Binary data to String.
```
Copy file name to clipboardExpand all lines: datafusion/sqllogictest/test_files/arrow_typeof.slt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -95,7 +95,7 @@ SELECT arrow_cast('1', 'Int16')
95
95
query error
96
96
SELECT arrow_cast('1')
97
97
98
-
query error Expect TypeSignatureClass::Native\(LogicalType\(Native\(String\), String\)\) but received NativeType::Int64, DataType: Int64
98
+
query error DataFusion error: Error during planning: Function 'arrow_cast' requires TypeSignatureClass::Native\(LogicalType\(Native\(String\), String\)\), but received Int64 \(DataType: Int64\)
99
99
SELECT arrow_cast('1', 43)
100
100
101
101
query error DataFusion error: Execution error: arrow_cast requires its second argument to be a non\-empty constant string
Copy file name to clipboardExpand all lines: datafusion/sqllogictest/test_files/binary.slt
+10Lines changed: 10 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -311,3 +311,13 @@ Foo foo Foo foo
311
311
NULL NULL NULL NULL
312
312
Bar Bar Bar Bar
313
313
FooBar fooBar FooBar fooBar
314
+
315
+
# show helpful error msg when Binary type is used with string functions
316
+
query error DataFusion error: Error during planning: Function 'split_part' requires TypeSignatureClass::Native\(LogicalType\(Native\(String\), String\)\), but received Binary \(DataType: Binary\)\.\n\nHint: Binary types are not automatically coerced to String\. Use CAST\(column AS VARCHAR\) to convert Binary data to String\.
317
+
SELECT split_part(binary, '~', 2) FROM t WHERE binary IS NOT NULL LIMIT 1;
318
+
319
+
# ensure the suggested CAST workaround works
320
+
query T
321
+
SELECT split_part(CAST(binary AS VARCHAR), 'o', 2) FROM t WHERE binary = X'466f6f';
Copy file name to clipboardExpand all lines: datafusion/sqllogictest/test_files/datetime/timestamps.slt
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -3064,7 +3064,7 @@ NULL
3064
3064
query error DataFusion error: Error during planning: Function 'make_date' expects 3 arguments but received 1
3065
3065
select make_date(1);
3066
3066
3067
-
query error Expect TypeSignatureClass::Native\(LogicalType\(Native\(Int32\), Int32\)\) but received NativeType::Interval\(MonthDayNano\), DataType: Interval\(MonthDayNano\)
3067
+
query error DataFusion error: Error during planning: Function 'make_date' requires TypeSignatureClass::Native\(LogicalType\(Native\(Int32\), Int32\)\), but received Interval\(MonthDayNano\) \(DataType: Interval\(MonthDayNano\)\)
query error Cannot cast string '' to value of Int32 type
3338
3338
select make_time(22, 1, '');
3339
3339
3340
-
query error Expect TypeSignatureClass::Native\(LogicalType\(Native\(Int32\), Int32\)\) but received NativeType::Float64, DataType: Float64
3340
+
query error DataFusion error: Error during planning: Function 'make_time' requires TypeSignatureClass::Native\(LogicalType\(Native\(Int32\), Int32\)\), but received Float64 \(DataType: Float64\)
statement error DataFusion error: Error during planning: Internal error: Expect TypeSignatureClass::Timestamp but received NativeType::String, DataType: Utf8
3955
+
statement error DataFusion error: Error during planning: Function 'to_local_time' requires TypeSignatureClass::Timestamp, but received String \(DataType: Utf8\)
Copy file name to clipboardExpand all lines: datafusion/sqllogictest/test_files/encoding.slt
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -55,10 +55,10 @@ CREATE TABLE test(
55
55
;
56
56
57
57
# errors
58
-
query error DataFusion error: Error during planning: Internal error: Expect TypeSignatureClass::Binary but received NativeType::Int64, DataType: Int64
58
+
query error DataFusion error: Error during planning: Function 'encode' requires TypeSignatureClass::Binary, but received Int64 \(DataType: Int64\)
59
59
select encode(12, 'hex');
60
60
61
-
query error DataFusion error: Error during planning: Internal error: Expect TypeSignatureClass::Binary but received NativeType::Int64, DataType: Int64
61
+
query error DataFusion error: Error during planning: Function 'decode' requires TypeSignatureClass::Binary, but received Int64 \(DataType: Int64\)
62
62
select decode(12, 'hex');
63
63
64
64
query error DataFusion error: Error during planning: There is no built\-in encoding named 'non_encoding', currently supported encodings are: base64, hex
@@ -73,7 +73,7 @@ select decode('', null) from test;
73
73
query error DataFusion error: This feature is not implemented: Encoding must be a scalar; array specified encoding is not yet supported
74
74
select decode('', hex_field) from test;
75
75
76
-
query error DataFusion error: Error during planning: Internal error: Expect TypeSignatureClass::Integer but received NativeType::String, DataType: Utf8View
76
+
query error DataFusion error: Error during planning: Function 'to_hex' requires TypeSignatureClass::Integer, but received String \(DataType: Utf8View\)
77
77
select to_hex(hex_field) from test;
78
78
79
79
query error DataFusion error: Execution error: Failed to decode value using base64
query error DataFusion error: Error during planning: Internal error: Expect TypeSignatureClass::Native\(LogicalType\(Native\(Int64\), Int64\)\) but received NativeType::Float64, DataType: Float64
592
+
query error DataFusion error: Error during planning: Function 'repeat' requires TypeSignatureClass::Native\(LogicalType\(Native\(Int64\), Int64\)\), but received Float64 \(DataType: Float64\)
Copy file name to clipboardExpand all lines: datafusion/sqllogictest/test_files/scalar.slt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2069,7 +2069,7 @@ select position('' in '')
2069
2069
----
2070
2070
1
2071
2071
2072
-
query error DataFusion error: Error during planning: Internal error: Expect TypeSignatureClass::Native\(LogicalType\(Native\(String\), String\)\) but received NativeType::Int64, DataType: Int64
2072
+
query error DataFusion error: Error during planning: Function 'strpos' requires TypeSignatureClass::Native\(LogicalType\(Native\(String\), String\)\), but received Int64 \(DataType: Int64\)
0 commit comments