Skip to content

Commit c9381c3

Browse files
committed
fix: accept LargeUtf8 and Utf8View patterns in SIMILAR TO planning
Closes apache#23732. Follow-up to apache#23704: now that the TypeCoercion analyzer coerces SIMILAR TO operands to a common string type, the SQL planner no longer needs to reject LargeUtf8/Utf8View patterns (consistent with LIKE, which has no such check).
1 parent 39e2f23 commit c9381c3

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎datafusion/sql/src/expr/mod.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,12 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
10091009
) -> Result<Expr> {
10101010
let pattern = self.sql_expr_to_logical_expr(pattern, schema, planner_context)?;
10111011
let pattern_type = pattern.get_type(schema)?;
1012-
if pattern_type != DataType::Utf8 && pattern_type != DataType::Null {
1012+
// The analyzer coerces both operands to a common string type, so any
1013+
// string-typed (or untyped NULL) pattern is accepted here.
1014+
if !matches!(
1015+
pattern_type,
1016+
DataType::Utf8 | DataType::LargeUtf8 | DataType::Utf8View | DataType::Null
1017+
) {
10131018
return plan_err!("Invalid pattern in SIMILAR TO expression");
10141019
}
10151020
let escape_char = match escape_char.map(|v| v.value) {

‎datafusion/sqllogictest/test_files/type_coercion.slt‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,23 @@ SELECT arrow_cast(t.s, 'Dictionary(Int32, Utf8)') SIMILAR TO p.pat FROM t CROSS
349349
----
350350
true
351351

352+
# non-scalar Utf8View / LargeUtf8 patterns are accepted by the SQL planner and
353+
# coerced by the analyzer (https://github.com/apache/datafusion/issues/23732)
354+
query B
355+
SELECT t.s SIMILAR TO arrow_cast(p.pat, 'Utf8View') FROM t CROSS JOIN p;
356+
----
357+
true
358+
359+
query B
360+
SELECT t.s SIMILAR TO arrow_cast(p.pat, 'LargeUtf8') FROM t CROSS JOIN p;
361+
----
362+
true
363+
364+
query B
365+
SELECT t.s NOT SIMILAR TO arrow_cast(p.pat, 'Utf8View') FROM t CROSS JOIN p;
366+
----
367+
false
368+
352369
statement ok
353370
DROP TABLE t;
354371

0 commit comments

Comments
 (0)