From f823b9a177e77ee1a6c25f6779c13f9e031c662b Mon Sep 17 00:00:00 2001 From: Duc Canh Le Date: Mon, 10 Oct 2022 13:31:10 +0800 Subject: [PATCH] add not like to atom map --- src/Storages/MergeTree/KeyCondition.cpp | 21 +++++++++++++++++++ ...58_key_condition_not_like_prefix.reference | 1 + .../002458_key_condition_not_like_prefix.sql | 5 +++++ 3 files changed, 27 insertions(+) create mode 100644 tests/queries/0_stateless/002458_key_condition_not_like_prefix.reference create mode 100644 tests/queries/0_stateless/002458_key_condition_not_like_prefix.sql diff --git a/src/Storages/MergeTree/KeyCondition.cpp b/src/Storages/MergeTree/KeyCondition.cpp index 24b3a4a60b9..ccdd26eb333 100644 --- a/src/Storages/MergeTree/KeyCondition.cpp +++ b/src/Storages/MergeTree/KeyCondition.cpp @@ -560,6 +560,27 @@ const KeyCondition::AtomMap KeyCondition::atom_map return true; } }, + { + "notLike", + [] (RPNElement & out, const Field & value) + { + if (value.getType() != Field::Types::String) + return false; + + String prefix = extractFixedPrefixFromLikePattern(value.get()); + if (prefix.empty()) + return false; + + String right_bound = firstStringThatIsGreaterThanAllStringsWithPrefix(prefix); + + out.function = RPNElement::FUNCTION_NOT_IN_RANGE; + out.range = !right_bound.empty() + ? Range(prefix, true, right_bound, false) + : Range::createLeftBounded(prefix, true); + + return true; + } + }, { "startsWith", [] (RPNElement & out, const Field & value) diff --git a/tests/queries/0_stateless/002458_key_condition_not_like_prefix.reference b/tests/queries/0_stateless/002458_key_condition_not_like_prefix.reference new file mode 100644 index 00000000000..87766d889a3 --- /dev/null +++ b/tests/queries/0_stateless/002458_key_condition_not_like_prefix.reference @@ -0,0 +1 @@ +200000 diff --git a/tests/queries/0_stateless/002458_key_condition_not_like_prefix.sql b/tests/queries/0_stateless/002458_key_condition_not_like_prefix.sql new file mode 100644 index 00000000000..211fa5662e7 --- /dev/null +++ b/tests/queries/0_stateless/002458_key_condition_not_like_prefix.sql @@ -0,0 +1,5 @@ +CREATE TABLE data (str String) ENGINE=MergeTree ORDER BY str; +INSERT INTO data (str) SELECT 'aa' FROM numbers(100000); +INSERT INTO data (str) SELECT 'ba' FROM numbers(100000); +INSERT INTO data (str) SELECT 'ca' FROM numbers(100000); +SELECT count()FROM data WHERE str NOT LIKE 'a%' SETTINGS force_primary_key=1; \ No newline at end of file