HappenLee commented on code in PR #66788: URL: https://github.com/apache/doris/pull/66788#discussion_r3794191376
########## be/src/util/hyperscan_util.cpp: ########## @@ -0,0 +1,139 @@ +// 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. + +#include "util/hyperscan_util.h" + +#include <re2/re2.h> +#include <re2/stringpiece.h> + +#include <charconv> +#include <string> + +namespace doris { +namespace { + +bool is_larger_than_fifty(std::string_view str) { + int number = 0; + auto [_, error] = std::from_chars(str.data(), str.data() + str.size(), number); + return error == std::errc() && number > 50; +} + +std::string mask_escaped_characters_and_character_classes(std::string_view regexp) { + std::string masked_regexp(regexp); + bool escaped = false; + bool in_character_class = false; + bool character_class_can_close = false; + bool character_class_can_negate = false; + for (char& masked_character : masked_regexp) { + const char current = masked_character; + if (escaped) { + masked_character = ' '; + escaped = false; + if (in_character_class) { + character_class_can_close = true; + character_class_can_negate = false; + } + continue; + } + if (current == '\\') { + masked_character = ' '; + escaped = true; + continue; + } + if (in_character_class) { + masked_character = ' '; + if (current == ']' && character_class_can_close) { + in_character_class = false; + } else if (current == '^' && character_class_can_negate) { + character_class_can_negate = false; + } else { + character_class_can_close = true; + character_class_can_negate = false; + } + continue; + } + if (current == '[') { Review Comment: Fixed in 8f24b336bb9 by aligning the detector with ClickHouse's `SlowWithHyperscanChecker`: the Doris-specific partial lexical masker has been removed, and the bounded-repeat searches now run directly on the raw regexp. As a result, `(?# [)(ab?c?d){1000,5000}` is classified as expensive and rejected before every Hyperscan compiler entry point, matching ClickHouse behavior without maintaining a partial Hyperscan parser. Added the exact pattern to LIKE/REGEXP, no-index MATCH_REGEXP, multi-match, inverted-index v1, and search-DSL/v2 regexp coverage. The targeted BE run passed all 8 tests; clang-format and clang-tidy also pass. -- 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]
