Skip to content

Commit 6a2bfd4

Browse files
authored
fix: Throw coercion error for LIKE operations for nested types. (#20212)
## 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. --> - Closes #20210. ## Rationale for this change Throw coercion error for LIKE adjacent operations. This matches DuckDB behaviour, just makes it clearer to users that nested types are not supported for this comparison. Remove the list_coercion for LIKE comparisons ## Are these changes tested? SLT tests.
1 parent 9333f74 commit 6a2bfd4

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

datafusion/expr-common/src/type_coercion/binary.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1793,9 +1793,10 @@ fn binary_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType>
17931793

17941794
/// Coercion rules for like operations.
17951795
/// This is a union of string coercion rules, dictionary coercion rules, and REE coercion rules
1796+
/// Note: list_coercion is intentionally NOT included here because LIKE is a string pattern
1797+
/// matching operation and is not supported for nested types (List, Struct, etc.)
17961798
pub fn like_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
17971799
string_coercion(lhs_type, rhs_type)
1798-
.or_else(|| list_coercion(lhs_type, rhs_type))
17991800
.or_else(|| binary_to_string_coercion(lhs_type, rhs_type))
18001801
.or_else(|| dictionary_comparison_coercion(lhs_type, rhs_type, false))
18011802
.or_else(|| ree_comparison_coercion(lhs_type, rhs_type, false))

datafusion/sqllogictest/test_files/type_coercion.slt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,30 @@ DROP TABLE orders;
254254
########################################
255255
## Test type coercion with UNIONs end ##
256256
########################################
257+
258+
# https://github.com/apache/datafusion/issues/15661
259+
# LIKE is a string pattern matching operator and is not supported for nested types.
260+
261+
statement ok
262+
CREATE TABLE t0(v0 BIGINT, v1 STRING, v2 BOOLEAN);
263+
264+
statement ok
265+
INSERT INTO t0(v0, v2) VALUES (123, true);
266+
267+
query error There isn't a common type to coerce .* in .* expression
268+
SELECT true FROM t0 WHERE ((REGEXP_MATCH(t0.v1, t0.v1)) NOT LIKE (REGEXP_MATCH(t0.v1, t0.v1, 'jH')));
269+
270+
query error There isn't a common type to coerce .* in .* expression
271+
SELECT true FROM t0 WHERE (REGEXP_MATCH(t0.v1, t0.v1)) NOT LIKE [];
272+
273+
query error There isn't a common type to coerce .* in .* expression
274+
SELECT true FROM t0 WHERE (REGEXP_MATCH(t0.v1, t0.v1)) LIKE [];
275+
276+
query error There isn't a common type to coerce .* in .* expression
277+
SELECT true FROM t0 WHERE (REGEXP_MATCH(t0.v1, t0.v1)) ILIKE [];
278+
279+
query error There isn't a common type to coerce .* in .* expression
280+
SELECT true FROM t0 WHERE (REGEXP_MATCH(t0.v1, t0.v1)) NOT ILIKE [];
281+
282+
statement ok
283+
DROP TABLE t0;

0 commit comments

Comments
 (0)