You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pegasus.apache.org by zh...@apache.org on 2021/06/08 06:11:19 UTC
[incubator-pegasus] branch master updated: feat: add sortkey
pattern rule (#749)
This is an automated email from the ASF dual-hosted git repository.
zhaoliwei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git
The following commit(s) were added to refs/heads/master by this push:
new b657a9d feat: add sortkey pattern rule (#749)
b657a9d is described below
commit b657a9d72d4c5ee83b47a172a2b3ebdf052a974d
Author: zhao liwei <zl...@163.com>
AuthorDate: Tue Jun 8 14:11:11 2021 +0800
feat: add sortkey pattern rule (#749)
---
src/server/compaction_filter_rule.cpp | 6 ++++
src/server/compaction_filter_rule.h | 19 ++++++++++++-
src/server/test/compaction_filter_rule_test.cpp | 37 +++++++++++++++++++++++++
3 files changed, 61 insertions(+), 1 deletion(-)
diff --git a/src/server/compaction_filter_rule.cpp b/src/server/compaction_filter_rule.cpp
index 7e64e9f..1e0ea45 100644
--- a/src/server/compaction_filter_rule.cpp
+++ b/src/server/compaction_filter_rule.cpp
@@ -56,5 +56,11 @@ bool hashkey_pattern_rule::match(const std::string &hash_key,
return string_pattern_match(hash_key, match_type, pattern);
}
+bool sortkey_pattern_rule::match(const std::string &hash_key,
+ const std::string &sort_key,
+ const rocksdb::Slice &existing_value) const
+{
+ return string_pattern_match(sort_key, match_type, pattern);
+}
} // namespace server
} // namespace pegasus
diff --git a/src/server/compaction_filter_rule.h b/src/server/compaction_filter_rule.h
index 435aeb5..da65661 100644
--- a/src/server/compaction_filter_rule.h
+++ b/src/server/compaction_filter_rule.h
@@ -55,7 +55,7 @@ ENUM_END(string_match_type)
class hashkey_pattern_rule : public compaction_filter_rule
{
public:
- explicit hashkey_pattern_rule() = default;
+ hashkey_pattern_rule() = default;
bool match(const std::string &hash_key,
const std::string &sort_key,
@@ -67,5 +67,22 @@ private:
FRIEND_TEST(hashkey_pattern_rule_test, match);
};
+
+class sortkey_pattern_rule : public compaction_filter_rule
+{
+public:
+ sortkey_pattern_rule() = default;
+
+ bool match(const std::string &hash_key,
+ const std::string &sort_key,
+ const rocksdb::Slice &existing_value) const;
+
+private:
+ std::string pattern;
+ string_match_type match_type;
+
+ FRIEND_TEST(sortkey_pattern_rule_test, match);
+};
+
} // namespace server
} // namespace pegasus
diff --git a/src/server/test/compaction_filter_rule_test.cpp b/src/server/test/compaction_filter_rule_test.cpp
index 0d9d3fd..a91b3f7 100644
--- a/src/server/test/compaction_filter_rule_test.cpp
+++ b/src/server/test/compaction_filter_rule_test.cpp
@@ -58,5 +58,42 @@ TEST(hashkey_pattern_rule_test, match)
ASSERT_EQ(rule.match(test.hashkey, "", slice), test.match);
}
}
+
+TEST(sortkey_pattern_rule_test, match)
+{
+ struct test_case
+ {
+ std::string sortkey;
+ std::string pattern;
+ string_match_type match_type;
+ bool match;
+ } tests[] = {
+ {"sortkey", "", SMT_MATCH_ANYWHERE, false},
+ {"sortkey", "sortkey", SMT_MATCH_ANYWHERE, true},
+ {"sortkey", "ort", SMT_MATCH_ANYWHERE, true},
+ {"sortkey", "sort", SMT_MATCH_ANYWHERE, true},
+ {"sortkey", "key", SMT_MATCH_ANYWHERE, true},
+ {"sortkey", "hashkey", SMT_MATCH_ANYWHERE, false},
+ {"sortkey", "sortkey", SMT_MATCH_PREFIX, true},
+ {"sortkey", "sort", SMT_MATCH_PREFIX, true},
+ {"sortkey", "key", SMT_MATCH_PREFIX, false},
+ {"sortkey", "hashkey", SMT_MATCH_PREFIX, false},
+ {"sortkey", "sortkey", SMT_MATCH_POSTFIX, true},
+ {"sortkey", "sort", SMT_MATCH_POSTFIX, false},
+ {"sortkey", "key", SMT_MATCH_POSTFIX, true},
+ {"sortkey", "hashkey", SMT_MATCH_POSTFIX, false},
+ {"sort", "sortkey", SMT_MATCH_POSTFIX, false},
+ {"sortkey", "sortkey", SMT_INVALID, false},
+ };
+
+ rocksdb::Slice slice;
+ sortkey_pattern_rule rule;
+ for (const auto &test : tests) {
+ rule.match_type = test.match_type;
+ rule.pattern = test.pattern;
+ ASSERT_EQ(rule.match("", test.sortkey, slice), test.match);
+ }
+}
+
} // namespace server
} // namespace pegasus
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pegasus.apache.org
For additional commands, e-mail: commits-help@pegasus.apache.org