Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion datafusion/expr-common/src/type_coercion/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1793,9 +1793,10 @@ fn binary_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType>

/// Coercion rules for like operations.
/// This is a union of string coercion rules, dictionary coercion rules, and REE coercion rules
/// Note: list_coercion is intentionally NOT included here because LIKE is a string pattern
/// matching operation and is not supported for nested types (List, Struct, etc.)
pub fn like_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataType> {
string_coercion(lhs_type, rhs_type)
.or_else(|| list_coercion(lhs_type, rhs_type))
.or_else(|| binary_to_string_coercion(lhs_type, rhs_type))
.or_else(|| dictionary_comparison_coercion(lhs_type, rhs_type, false))
.or_else(|| ree_comparison_coercion(lhs_type, rhs_type, false))
Expand Down
27 changes: 27 additions & 0 deletions datafusion/sqllogictest/test_files/type_coercion.slt
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,30 @@ DROP TABLE orders;
########################################
## Test type coercion with UNIONs end ##
########################################

# https://github.com/apache/datafusion/issues/15661
# LIKE is a string pattern matching operator and is not supported for nested types.

statement ok
CREATE TABLE t0(v0 BIGINT, v1 STRING, v2 BOOLEAN);

statement ok
INSERT INTO t0(v0, v2) VALUES (123, true);

query error There isn't a common type to coerce .* in .* expression
SELECT true FROM t0 WHERE ((REGEXP_MATCH(t0.v1, t0.v1)) NOT LIKE (REGEXP_MATCH(t0.v1, t0.v1, 'jH')));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would these be easier to read by replacing the second regexp_match with just an array literal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes good point, i made the changes for the others but kept this specific line:

SELECT true FROM t0 WHERE ((REGEXP_MATCH(t0.v1, t0.v1)) NOT LIKE (REGEXP_MATCH(t0.v1, t0.v1, 'jH')));

To just show replication of the query in the issue


query error There isn't a common type to coerce .* in .* expression
SELECT true FROM t0 WHERE (REGEXP_MATCH(t0.v1, t0.v1)) NOT LIKE [];

query error There isn't a common type to coerce .* in .* expression
SELECT true FROM t0 WHERE (REGEXP_MATCH(t0.v1, t0.v1)) LIKE [];

query error There isn't a common type to coerce .* in .* expression
SELECT true FROM t0 WHERE (REGEXP_MATCH(t0.v1, t0.v1)) ILIKE [];

query error There isn't a common type to coerce .* in .* expression
SELECT true FROM t0 WHERE (REGEXP_MATCH(t0.v1, t0.v1)) NOT ILIKE [];

statement ok
DROP TABLE t0;