Repository navigation
Incorrect LIKE and ILIKE result for NULL input, `%', and '%%' pattern #12637
Description
Activity
I'm not really sure if the behavior of StringView is expected 🤔 but I think their behavior should be consistent.
When the input value is NULL, string type will return NULL but string view will return false. (Something is interesting about the ILIKE operation is different between ASCII-only and Unicode StringView 🤔 )
I think if the input is null, the string view should also return null
Reacted by Jax LiuI think if the input is null, the string view should also return null
Thanks! I updated the expected behavior 👍
Reacted by Andrew LambConcise repro. This should return NULL
> select arrow_cast(null, 'Utf8') LIKE '%'; +----------------------------------------------+ | arrow_cast(NULL,Utf8("Utf8")) LIKE Utf8("%") | +----------------------------------------------+ | true | +----------------------------------------------+@goldmedal can you please change issue title to something like
Incorrect LIKE and ILIKE result for NULL input and `%` pattern?Reacted by Jax Liu- changed the title
[-]The LIKE and ILIKE behavior for NULL handling in StringView differs from other string types[/-][+]Incorrect LIKE and ILIKE result for NULL input and `%` pattern[/+]on Oct 31, 2024 @goldmedal can you please change issue title to something like
Incorrect LIKE and ILIKE result for NULL input and `%` pattern?Thanks for the suggestion 👍
LIKE -- apache/arrow-rs#6662
Reacted by Andrew Lambtake
I plan to take care of ILIKE as well, once the above is accepted.
Reacted by Jax Liu- added a commit that references this issue
on Nov 5, 2024 For cases when pattern is static (majority), we can partially fix this issue by fixing a bug in the simplifier, and thus avoiding buggy execution path: #13259
- added 2 commits that reference this issue
on Nov 5, 2024 @goldmedal can you maybe edit issue title once again to cover
%%patterns too?
%static patterns are being fixed in #13259
%%test cases in #13259 are commented out pointing at this issue(i will see maybe i can fix repeated percent there too?)
- changed the title
[-]Incorrect LIKE and ILIKE result for NULL input and `%` pattern[/-][+]Incorrect LIKE and ILIKE result for NULL input, `%', and '%%' pattern[/+]on Nov 5, 2024 Interesting, I haven't checked the source code but I tried different numbers of the
%char. Only one and two will be wrong.> select arrow_cast(null, 'Utf8View') like '%'; +--------------------------------------------------+ | arrow_cast(NULL,Utf8("Utf8View")) LIKE Utf8("%") | +--------------------------------------------------+ | true | +--------------------------------------------------+ 1 row(s) fetched. Elapsed 0.001 seconds. > select arrow_cast(null, 'Utf8View') like '%%'; +---------------------------------------------------+ | arrow_cast(NULL,Utf8("Utf8View")) LIKE Utf8("%%") | +---------------------------------------------------+ | true | +---------------------------------------------------+ 1 row(s) fetched. Elapsed 0.001 seconds. > select arrow_cast(null, 'Utf8View') like '%%%'; +----------------------------------------------------+ | arrow_cast(NULL,Utf8("Utf8View")) LIKE Utf8("%%%") | +----------------------------------------------------+ | | +----------------------------------------------------+ 1 row(s) fetched. Elapsed 0.001 seconds. > select arrow_cast(null, 'Utf8View') like '%%%%'; +-----------------------------------------------------+ | arrow_cast(NULL,Utf8("Utf8View")) LIKE Utf8("%%%%") | +-----------------------------------------------------+ | | +-----------------------------------------------------+ 1 row(s) fetched. Elapsed 0.001 seconds.It's a nice find 👍
- added a commit that references this issue
on Nov 5, 2024 It looks like a missed optimization opportunity.
%,%%,%...%%patterns should all behave the same.
in #13260 i am adding a simplifier to make them the same.- added a commit that references this issue
on Nov 6, 2024 - added 4 commits that reference this issue
on Nov 6, 2024 I plan to take care of ILIKE as well, once the above is accepted.
done in apache/arrow-rs#6705
should we close this issue when we update arrow-rs dep?
Reacted by Andrew Lamb- addedwaiting-on-upstreamPR is waiting on an upstream dependency to be updatedPR is waiting on an upstream dependency to be updated
on Nov 13, 2024 Marked as waiting on upstream
Reacted by Piotr Findeisen- added a commit that references this issue
on Nov 14, 2024 - added a commit that references this issue
on Feb 3, 2025
Describe the bug
While working on #12415, I found the
LIKEandILIKEbehavior differs betweenStringViewand other string types. Given the following data and SQL:When the input value is NULL, string type will return
NULLbut string view will return false. (Something is interesting about the ILIKE operation is different between ASCII-only and UnicodeStringView🤔 )Some testing for StringView ScalarValue
When the matching pattern contains
%, it will returnfalseinsteadnull.Some testing for String ScalarValue (Same as LargeString and DictionaryString)
To Reproduce
Run the SQLs mentioned above.
Expected behavior
I'm not really sure if the behavior of StringView is expected 🤔 but I think their behavior should be consistent.If the input is null, the like and ilike should return null.
Additional context
No response