Skip to content

fix: accept LargeUtf8 and Utf8View patterns in SIMILAR TO planning#23735

Open
u70b3 wants to merge 2 commits into
apache:mainfrom
u70b3:similar-to-pattern-types
Open

fix: accept LargeUtf8 and Utf8View patterns in SIMILAR TO planning#23735
u70b3 wants to merge 2 commits into
apache:mainfrom
u70b3:similar-to-pattern-types

Conversation

@u70b3

@u70b3 u70b3 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Follow-up to #23704, which made the TypeCoercion analyzer coerce SIMILAR TO operands to a common string type. The SQL planner still rejects LargeUtf8 and Utf8View patterns before the analyzer ever runs:

SELECT s FROM test, patterns WHERE s SIMILAR TO arrow_cast(pat, 'Utf8View');
-- error: Invalid pattern in SIMILAR TO expression

Now that the analyzer coerces both operands, this planner restriction is unnecessary (and inconsistent with LIKE, whose planner path has no such check).

What changes are included in this PR?

The planner relaxation and tests were originally part of #22887; this PR lands the remaining piece of it.

Are these changes tested?

Yes — new sqllogictest cases in type_coercion.slt. The existing planner rejection of non-string patterns (SELECT 'a' SIMILAR TO 1) still errors as before.

Are there any user-facing changes?

Yes: SIMILAR TO queries with non-literal LargeUtf8 / Utf8View patterns that previously failed during SQL planning with Invalid pattern in SIMILAR TO expression now plan and execute successfully. No breaking API changes.

@codecov-commenter

codecov-commenter commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.71%. Comparing base (050046a) to head (7738741).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23735      +/-   ##
==========================================
- Coverage   80.71%   80.71%   -0.01%     
==========================================
  Files        1089     1089              
  Lines      368750   368751       +1     
  Branches   368750   368751       +1     
==========================================
- Hits       297631   297627       -4     
- Misses      53375    53376       +1     
- Partials    17744    17748       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@u70b3
u70b3 force-pushed the similar-to-pattern-types branch from f9061a3 to 69f531e Compare July 21, 2026 06:09
SELECT t.s NOT SIMILAR TO arrow_cast(p.pat, 'Utf8View') FROM t CROSS JOIN p;
----
false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add tests for teh null case?

@u70b3 u70b3 Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in add3f8d — added a literal NULL pattern in the table context and a non-scalar Null-typed pattern column (CREATE TABLE pn AS SELECT NULL AS pat), both evaluate to NULL.

u70b3 added 2 commits July 21, 2026 19:09
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).
@u70b3
u70b3 force-pushed the similar-to-pattern-types branch from add3f8d to 7738741 Compare July 21, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SIMILAR TO: SQL planner rejects non-literal LargeUtf8 / Utf8View patterns

3 participants