github-actions[bot] commented on code in PR #68133:
URL: https://github.com/apache/doris/pull/68133#discussion_r4036146290


##########
be/src/exprs/function/like.cpp:
##########
@@ -823,10 +824,8 @@ void FunctionLike::convert_like_pattern(const 
LikeSearchState* state, const std:
         }
     }
 
-    // add $ to pattern tail to match line tail
-    if (!pattern.empty() && re_pattern->back() != '*') {
-        re_pattern->append("$");
-    }
+    // `\z` is the end of the value in both Hyperscan and RE2
+    re_pattern->append("\\z");

Review Comment:
   [P2] Keep a genuine trailing wildcard open
   
   Appending `\z` unconditionally makes a regex-requiring pattern such as 
`a_b%` compile as `^a.b.*\z`. Doris's Hyperscan callback stops scanning at the 
first reported match, so the previous open-tail form can finish after the 
required prefix, while the new end anchor cannot report until it has traversed 
the entire value. On a long valid string beginning with `axb`, this turns a 
prefix-bounded match into an O(value length) scan; the scalar fallback and 
cloned pushdown state receive the same unnecessary constraint. [Hyperscan 
documents that callbacks expose match end offsets and may halt a partially 
completed scan.](https://intel.github.io/hyperscan/dev-reference/runtime.html) 
Please omit the tail anchor when the final LIKE token is an unescaped `%` 
(while retaining `\z` for literal `*` and escaped `%`) and update the shape 
coverage accordingly.



##########
regression-test/suites/query_p0/sql_functions/string_functions/test_like_whole_string_match.groovy:
##########
@@ -0,0 +1,79 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_like_whole_string_match") {
+    sql "drop table if exists test_like_whole_string_match"
+    sql """
+        create table test_like_whole_string_match (
+            id int,
+            s varchar(64)
+        ) duplicate key(id)
+        distributed by hash(id) buckets 1
+        properties("replication_num" = "1");
+    """
+    sql """
+        insert into test_like_whole_string_match values
+            (1, 'acb'),
+            (2, concat('acb', char(10))),
+            (3, concat('acb', char(13), char(10))),
+            (4, concat('a', char(10), 'b')),
+            (5, 'acbx'),
+            (6, 'ab*'),
+            (7, concat('ab*', char(10))),
+            (8, 'ab*xyz');
+    """
+
+    // a value that ends with a newline is one character longer, so it must 
not match a
+    // pattern that is anchored at the tail
+    qt_anchor_underscore """
+        select id, length(s) as len, s like 'a_b' as r from 
test_like_whole_string_match order by id
+    """
+    qt_anchor_leading_percent """
+        select id, length(s) as len, s like '%c%b' as r from 
test_like_whole_string_match order by id
+    """
+    // a literal '*' at the end of the pattern does not make it end with a 
wildcard
+    qt_literal_star_tail """
+        select id, length(s) as len, s like 'a_*' as r from 
test_like_whole_string_match order by id
+    """
+    // a pattern that really ends with '%' still accepts anything, the newline 
included
+    qt_trailing_percent """
+        select id, length(s) as len, s like 'a_b%' as r from 
test_like_whole_string_match order by id
+    """
+
+    // a pattern without wildcards is rewritten to an equality by 
LIKE_TO_EQUAL, which would
+    // make this block pass with LIKE broken; disable the rule so the shortcut 
path really runs
+    sql "set disable_nereids_expression_rules='LIKE_TO_EQUAL'"
+    qt_equals_shortcut """
+        select id, length(s) as len, s like 'acb' as r from 
test_like_whole_string_match order by id
+    """
+
+    // a LIKE in a filter with function pushdown enabled is evaluated by 
LikeColumnPredicate,
+    // which converts the pattern a second time through 
LikeSearchState::clone()
+    sql "set enable_function_pushdown = true"
+    qt_pushdown_underscore """
+        select id from test_like_whole_string_match where s like 'a_b' order 
by id
+    """
+    qt_pushdown_literal_star """
+        select id from test_like_whole_string_match where s like 'a_*' order 
by id
+    """
+    qt_pushdown_not_literal_star """

Review Comment:
   [P3] Do not present this as specialized NOT LIKE pushdown coverage
   
   Nereids sends this as `CompoundPredicate(NOT, LIKE(...))`. 
`_normalize_predicate` checks the NOT node's direct children first; child zero 
is the LIKE function rather than the slot, so it returns before 
`_normalize_function_filters` can build `LikeColumnPredicate(opposite=true)` 
and clone the matcher state. On this DUP_KEYS table the whole expression may 
still use generic expression pushdown, so the result is valid NOT LIKE behavior 
coverage, but it does not cover the specialized path implied by the surrounding 
comment. Please rename or move this case accordingly. If specialized NOT LIKE 
pushdown is enabled later, add focused path tests together with nullable 
handling—the current opposite predicate retains NULL rows and cannot safely 
replace the residual expression by itself.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to