Skip to content
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

Add support of the SORT command #2262

Merged
merged 28 commits into from
May 7, 2024
Merged

Conversation

PokIsemaine
Copy link
Contributor

issues: #1952

@PokIsemaine PokIsemaine marked this pull request as ready for review April 21, 2024 15:42
jihuayu
jihuayu previously approved these changes Apr 22, 2024
Copy link
Member

@jihuayu jihuayu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job. Thank you for providing such comprehensive test cases.

@jihuayu jihuayu requested review from PragmaTwice and mapleFU April 22, 2024 01:08
@git-hulk git-hulk changed the title feat: support sort command Add support of the SORT command Apr 22, 2024
src/storage/redis_db.h Outdated Show resolved Hide resolved
Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a carefully pass tonight, just some minor comments now

src/commands/cmd_key.cc Outdated Show resolved Hide resolved
src/commands/cmd_key.cc Show resolved Hide resolved
src/commands/cmd_key.cc Outdated Show resolved Hide resolved
src/storage/redis_db.cc Outdated Show resolved Hide resolved
src/storage/redis_db.cc Outdated Show resolved Hide resolved
src/storage/redis_db.h Outdated Show resolved Hide resolved
src/commands/cmd_key.cc Show resolved Hide resolved
src/commands/cmd_key.cc Outdated Show resolved Hide resolved
src/storage/redis_db.cc Outdated Show resolved Hide resolved
src/storage/redis_db.cc Outdated Show resolved Hide resolved
src/storage/redis_db.cc Outdated Show resolved Hide resolved
src/storage/redis_db.cc Outdated Show resolved Hide resolved
src/storage/redis_db.cc Outdated Show resolved Hide resolved
src/storage/redis_db.cc Outdated Show resolved Hide resolved
@PragmaTwice
Copy link
Member

Besides, should we limit the element count here? @PragmaTwice . A huge vectorlen can easily causing OOM in our current impl?

Actually I'm thinking to specify a special command tag for such commands that loads all of the data structure, like this one, and HRANDFIELD..

Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort is too complex here, I'll dive into it later, thanks for the contribution

src/commands/cmd_key.cc Show resolved Hide resolved
src/storage/redis_db.cc Outdated Show resolved Hide resolved
Copy link
Member

@PragmaTwice PragmaTwice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks generally good to me.

See if @mapleFU or others have any concern.

src/storage/redis_db.cc Outdated Show resolved Hide resolved
Comment on lines +56 to +58
/// If `args.alpha` is false, `RedisSortObject.v` will be taken as double for comparison
/// If `args.alpha` is true and `args.sortby` is not empty, `RedisSortObject.v` will be taken as string for comparison
/// If `args.alpha` is true and `args.sortby` is empty, the comparison is by `RedisSortObject.obj`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why do here has std::variant and a std::string? We should use only variant or double + string composite?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is feasible to only use std::variant<std::string, double>, but this may require distinguishing between two types of std::string: BY(RedisSortObject.v) and the sort key itself(RedisSortObject.obj), resulting in unclear sorting logic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sigh, I think maybe struct or other is ok, since the passed in argument ( RedisSortObject ) is defined by args. It cannot have another state ( like holding a string when !args.alpha ), and this introduce a double-checking here.

std::variant seems has same space usage as struct {double; string;}. But both is ok for me

src/storage/redis_db.h Outdated Show resolved Hide resolved
src/commands/cmd_key.cc Show resolved Hide resolved
src/commands/cmd_key.cc Show resolved Hide resolved
src/storage/redis_db.cc Outdated Show resolved Hide resolved
src/storage/redis_db.cc Show resolved Hide resolved
src/storage/redis_db.cc Outdated Show resolved Hide resolved
src/storage/redis_db.cc Outdated Show resolved Hide resolved
src/storage/redis_db.cc Show resolved Hide resolved
src/storage/redis_db.cc Outdated Show resolved Hide resolved
PokIsemaine and others added 2 commits May 6, 2024 11:12
@PragmaTwice PragmaTwice requested a review from mapleFU May 6, 2024 14:10
src/storage/redis_db.cc Show resolved Hide resolved
@mapleFU
Copy link
Member

mapleFU commented May 6, 2024

Will merge in 1-days if no negative comments

@mapleFU mapleFU merged commit 3b8c69f into apache:unstable May 7, 2024
30 checks passed
Copy link

sonarcloud bot commented May 7, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

13015517713 added a commit to 13015517713/kvrocks that referenced this pull request May 7, 2024
Add support of the SORT command (apache#2262)

Co-authored-by: 纪华裕 <jihuayu123@gmail.com>
Co-authored-by: hulk <hulk.website@gmail.com>
Co-authored-by: mwish <maplewish117@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants