From f1dc2f4775a35e1b3c1edc2d0aee3e2bc22d1e6a Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Fri, 3 Apr 2015 19:16:02 +0300 Subject: [PATCH] dbms: fixed error [#METR-15387]. --- .../DB/Functions/FunctionsStringSearch.h | 19 +++++++++++++------ .../0_stateless/00144_empty_regexp.reference | 2 ++ .../0_stateless/00144_empty_regexp.sql | 2 ++ .../0_stateless/00145_empty_likes.reference | 16 ++++++++++++++++ .../queries/0_stateless/00145_empty_likes.sql | 18 ++++++++++++++++++ 5 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 dbms/tests/queries/0_stateless/00144_empty_regexp.reference create mode 100644 dbms/tests/queries/0_stateless/00144_empty_regexp.sql create mode 100644 dbms/tests/queries/0_stateless/00145_empty_likes.reference create mode 100644 dbms/tests/queries/0_stateless/00145_empty_likes.sql diff --git a/dbms/include/DB/Functions/FunctionsStringSearch.h b/dbms/include/DB/Functions/FunctionsStringSearch.h index 50c65394f47..351fb47f1ef 100644 --- a/dbms/include/DB/Functions/FunctionsStringSearch.h +++ b/dbms/include/DB/Functions/FunctionsStringSearch.h @@ -395,14 +395,21 @@ struct MatchImpl if (required_substring.empty()) { - size_t prev_offset = 0; - for (size_t i = 0; i < size; ++i) + if (!regexp->getRE2()) /// Пустой регексп. Всегда матчит. { - res[i] = revert ^ regexp->getRE2()->Match( - re2_st::StringPiece(reinterpret_cast(&data[prev_offset]), offsets[i] - prev_offset - 1), - 0, offsets[i] - prev_offset - 1, re2_st::RE2::UNANCHORED, nullptr, 0); + memset(&res[0], 1, size * sizeof(res[0])); + } + else + { + size_t prev_offset = 0; + for (size_t i = 0; i < size; ++i) + { + res[i] = revert ^ regexp->getRE2()->Match( + re2_st::StringPiece(reinterpret_cast(&data[prev_offset]), offsets[i] - prev_offset - 1), + 0, offsets[i] - prev_offset - 1, re2_st::RE2::UNANCHORED, nullptr, 0); - prev_offset = offsets[i]; + prev_offset = offsets[i]; + } } } else diff --git a/dbms/tests/queries/0_stateless/00144_empty_regexp.reference b/dbms/tests/queries/0_stateless/00144_empty_regexp.reference new file mode 100644 index 00000000000..6ed281c757a --- /dev/null +++ b/dbms/tests/queries/0_stateless/00144_empty_regexp.reference @@ -0,0 +1,2 @@ +1 +1 diff --git a/dbms/tests/queries/0_stateless/00144_empty_regexp.sql b/dbms/tests/queries/0_stateless/00144_empty_regexp.sql new file mode 100644 index 00000000000..004b1c8ef9e --- /dev/null +++ b/dbms/tests/queries/0_stateless/00144_empty_regexp.sql @@ -0,0 +1,2 @@ +SELECT match(materialize('Hello'), ''); +SELECT match('Hello', ''); diff --git a/dbms/tests/queries/0_stateless/00145_empty_likes.reference b/dbms/tests/queries/0_stateless/00145_empty_likes.reference new file mode 100644 index 00000000000..5b87d5441e4 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00145_empty_likes.reference @@ -0,0 +1,16 @@ +0 +1 +1 +1 +1 +0 +1 +1 +0 +1 +1 +1 +1 +0 +1 +1 diff --git a/dbms/tests/queries/0_stateless/00145_empty_likes.sql b/dbms/tests/queries/0_stateless/00145_empty_likes.sql new file mode 100644 index 00000000000..e1b4adf0118 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00145_empty_likes.sql @@ -0,0 +1,18 @@ +SELECT materialize('Hello') LIKE ''; +SELECT materialize('Hello') LIKE '%'; +SELECT materialize('Hello') LIKE '%%'; +SELECT materialize('Hello') LIKE '%%%'; +SELECT materialize('Hello') LIKE '%_%'; +SELECT materialize('Hello') LIKE '_'; +SELECT materialize('Hello') LIKE '_%'; +SELECT materialize('Hello') LIKE '%_'; + +SELECT 'Hello' LIKE ''; +SELECT 'Hello' LIKE '%'; +SELECT 'Hello' LIKE '%%'; +SELECT 'Hello' LIKE '%%%'; +SELECT 'Hello' LIKE '%_%'; +SELECT 'Hello' LIKE '_'; +SELECT 'Hello' LIKE '_%'; +SELECT 'Hello' LIKE '%_'; +