-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(hyperloglog): add support of the Hyperloglog data structure #2142
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
3e92895
Support Hyperloglog
e8cdf69
add origin copyright
d4b174d
code tuning
c780c84
code format
5f86c40
HLL: modify subkeys storage format with dense encoding (#2)
tutububug cdc375b
fix error of lint and code check (#3)
tutububug 145b703
remove debug code (#5)
tutububug ae5df70
trigger GitHub actions
85d286c
Merge branch 'unstable' into hyperloglog-dev-github
tutububug efa8984
fix check code (#7)
tutububug 57cebd5
fix
62a943f
update
48eef8d
Merge branch 'unstable' into hyperloglog-dev-github
tutububug 993dfb7
move copied functions to new file (#10)
tutububug 6df6a69
Merge branch 'unstable' into hyperloglog-dev-github
git-hulk 93f3bc4
correct register merge condition (#12)
tutububug 78a57fc
fix (#13)
tutububug 2cd439c
Merge branch 'unstable' into hyperloglog-dev-github
tutububug bbdbcb0
fix (#14)
tutububug 559ebc9
fix (#15)
tutububug bc32fa0
Merge branch 'unstable' into hyperloglog-dev-github
tutububug 98d77d3
Merge branch 'unstable' into hyperloglog-dev-github
tutububug 08d07db
fix code check
c6d99e2
Merge branch 'unstable' into hyperloglog-dev-github
git-hulk 64a7a44
Merge branch 'unstable' into hyperloglog-dev-github
tutububug 7cf88ef
minor updates
mapleFU d3b2978
remove the code for merge
mapleFU 38e99f0
resume code for bitmap
mapleFU 7e72ca8
Keep cleanup the logic
mapleFU 1af314e
Merge branch 'unstable' into hyperloglog-dev-github
mapleFU a8e84fd
basic skeleton finished
mapleFU 7f6653c
Fix testing
mapleFU 008ec3f
Update vendor lib
mapleFU afdb7a7
Trying to fix lint
mapleFU d8cc9a1
remove bad conflict resolve
mapleFU 22923f9
update comments
mapleFU e4f3e77
Change HLL to 11
mapleFU b6fc4a1
trying to fix lint
mapleFU File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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 <types/redis_hyperloglog.h> | ||
|
||
#include <algorithm> | ||
|
||
#include "commander.h" | ||
#include "commands/command_parser.h" | ||
#include "commands/error_constants.h" | ||
#include "error_constants.h" | ||
#include "parse_util.h" | ||
#include "server/redis_reply.h" | ||
#include "server/server.h" | ||
#include "storage/redis_metadata.h" | ||
|
||
namespace redis { | ||
|
||
/// PFADD key [element [element ...]] | ||
/// Complexity: O(1) for each element added. | ||
class CommandPfAdd final : public Commander { | ||
public: | ||
Status Execute(Server *srv, Connection *conn, std::string *output) override { | ||
redis::HyperLogLog hll(srv->storage, conn->GetNamespace()); | ||
std::vector<uint64_t> hashes(args_.size() - 1); | ||
for (size_t i = 1; i < args_.size(); i++) { | ||
hashes[i - 1] = redis::HyperLogLog::HllHash(args_[i]); | ||
} | ||
uint64_t ret{}; | ||
auto s = hll.Add(args_[0], hashes, &ret); | ||
if (!s.ok() && !s.IsNotFound()) { | ||
return {Status::RedisExecErr, s.ToString()}; | ||
} | ||
*output = redis::Integer(ret); | ||
return Status::OK(); | ||
} | ||
}; | ||
|
||
/// PFCOUNT key [key ...] | ||
/// Complexity: O(1) with a very small average constant time when called with a single key. | ||
/// O(N) with N being the number of keys, and much bigger constant times, | ||
/// when called with multiple keys. | ||
/// | ||
/// TODO(mwish): Currently we don't supports merge, so only one key is supported. | ||
class CommandPfCount final : public Commander { | ||
Status Execute(Server *srv, Connection *conn, std::string *output) override { | ||
redis::HyperLogLog hll(srv->storage, conn->GetNamespace()); | ||
uint64_t ret{}; | ||
auto s = hll.Count(args_[0], &ret); | ||
if (!s.ok() && !s.IsNotFound()) { | ||
return {Status::RedisExecErr, s.ToString()}; | ||
} | ||
if (s.IsNotFound()) { | ||
ret = 0; | ||
} | ||
*output = redis::Integer(ret); | ||
return Status::OK(); | ||
} | ||
}; | ||
|
||
REDIS_REGISTER_COMMANDS(MakeCmdAttr<CommandPfAdd>("pfadd", -2, "write", 1, 1, 1), | ||
MakeCmdAttr<CommandPfCount>("pfcount", 2, "read-only", 1, 1, 1), ); | ||
PragmaTwice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
} // namespace redis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
PFMERGE
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be add in next patch