-
Notifications
You must be signed in to change notification settings - Fork 5
Rs3 range query support #435
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
94098b9
Range query support for rs3
hachikuji 33800c7
WIP
hachikuji e406f61
blah
hachikuji 9e5cf0a
Merge remote-tracking branch 'origin/main' into rs3-range-query-support
hachikuji 8fc7596
blah
hachikuji ee2eec2
Complete range query implementation
hachikuji cd1767f
Missing header files
hachikuji c44dbfe
Fix checkstyle
hachikuji 7064673
Add end to end tests for range queries
hachikuji d56714f
Fix broken test case in `GrpcRS3ClientEndToEndTest`
hachikuji 15c47f3
Merge remote-tracking branch 'origin/main' into rs3-range-query-support
hachikuji 2786874
Use linked blocking queue in GrpcMessageQueue
hachikuji a7fadfd
Remove use of AtomicReference in GrpcMessageQueue
hachikuji 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
64 changes: 64 additions & 0 deletions
64
kafka-client/src/main/java/dev/responsive/kafka/internal/db/rs3/client/Range.java
This file contains hidden or 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,64 @@ | ||
| package dev.responsive.kafka.internal.db.rs3.client; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public class Range { | ||
| private final RangeBound start; | ||
| private final RangeBound end; | ||
|
|
||
| public Range(RangeBound start, RangeBound end) { | ||
| this.start = start; | ||
| this.end = end; | ||
| } | ||
|
|
||
| public RangeBound start() { | ||
| return start; | ||
| } | ||
|
|
||
| public RangeBound end() { | ||
| return end; | ||
| } | ||
|
|
||
| public boolean contains(byte[] key) { | ||
| return greaterThanStartBound(key) && lessThanEndBound(key); | ||
| } | ||
|
|
||
| public boolean greaterThanStartBound(byte[] key) { | ||
| return start.map(new RangeBound.Mapper<>() { | ||
| @Override | ||
| public Boolean map(final RangeBound.InclusiveBound b) { | ||
| return Arrays.compare(b.key(), key) <= 0; | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean map(final RangeBound.ExclusiveBound b) { | ||
| return Arrays.compare(b.key(), key) < 0; | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean map(final RangeBound.Unbounded b) { | ||
| return true; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| public boolean lessThanEndBound(byte[] key) { | ||
| return end.map(new RangeBound.Mapper<>() { | ||
| @Override | ||
| public Boolean map(final RangeBound.InclusiveBound b) { | ||
| return Arrays.compare(b.key(), key) >= 0; | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean map(final RangeBound.ExclusiveBound b) { | ||
| return Arrays.compare(b.key(), key) > 0; | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean map(final RangeBound.Unbounded b) { | ||
| return true; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| } |
121 changes: 121 additions & 0 deletions
121
kafka-client/src/main/java/dev/responsive/kafka/internal/db/rs3/client/RangeBound.java
This file contains hidden or 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,121 @@ | ||
| /* | ||
| * Copyright 2025 Responsive Computing, Inc. | ||
| * | ||
| * This source code is licensed under the Responsive Business Source License Agreement v1.0 | ||
| * available at: | ||
| * | ||
| * https://www.responsive.dev/legal/responsive-bsl-10 | ||
| * | ||
| * This software requires a valid Commercial License Key for production use. Trial and commercial | ||
| * licenses can be obtained at https://www.responsive.dev | ||
| */ | ||
|
|
||
| package dev.responsive.kafka.internal.db.rs3.client; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Objects; | ||
|
|
||
| public interface RangeBound { | ||
|
|
||
| <T> T map(Mapper<T> mapper); | ||
|
|
||
| static Unbounded unbounded() { | ||
| return Unbounded.INSTANCE; | ||
| } | ||
|
|
||
| static InclusiveBound inclusive(byte[] key) { | ||
| return new InclusiveBound(key); | ||
| } | ||
|
|
||
| static ExclusiveBound exclusive(byte[] key) { | ||
| return new ExclusiveBound(key); | ||
| } | ||
|
|
||
| class InclusiveBound implements RangeBound { | ||
| private final byte[] key; | ||
|
|
||
| public InclusiveBound(final byte[] key) { | ||
| this.key = key; | ||
| } | ||
|
|
||
| public byte[] key() { | ||
| return key; | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T map(final Mapper<T> mapper) { | ||
| return mapper.map(this); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(final Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| final InclusiveBound that = (InclusiveBound) o; | ||
| return Objects.deepEquals(key, that.key); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Arrays.hashCode(key); | ||
| } | ||
| } | ||
|
|
||
| class ExclusiveBound implements RangeBound { | ||
| private final byte[] key; | ||
|
|
||
| public ExclusiveBound(final byte[] key) { | ||
| this.key = key; | ||
| } | ||
|
|
||
| public byte[] key() { | ||
| return key; | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T map(final Mapper<T> mapper) { | ||
| return mapper.map(this); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(final Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| final ExclusiveBound that = (ExclusiveBound) o; | ||
| return Objects.deepEquals(key, that.key); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Arrays.hashCode(key); | ||
| } | ||
| } | ||
|
|
||
| class Unbounded implements RangeBound { | ||
| private static final Unbounded INSTANCE = new Unbounded(); | ||
|
|
||
| private Unbounded() {} | ||
|
|
||
| @Override | ||
| public <T> T map(final Mapper<T> mapper) { | ||
| return mapper.map(this); | ||
| } | ||
| } | ||
|
|
||
| interface Mapper<T> { | ||
| T map(InclusiveBound b); | ||
|
|
||
| T map(ExclusiveBound b); | ||
|
|
||
| T map(Unbounded b); | ||
| } | ||
|
|
||
| } | ||
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.
nit: maybe call this a
Visitorinstead? This looks like the classic visitor pattern to meThere 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.
Yeah, it's a visitor pattern, but I'm using it as a poor man's version of pattern matching to implement a
mapfunction. I thought using theVisitorname made its usage feel a little too vague. I don't feel strongly about it though..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.
Up to you - I felt the opposite 😛 . I was a bit confused at first and had to look at how it was used but it would've felt obvious if it was named
Visitor. But that could just be me. We had the Visitor pattern drilled into us working on ksql syntax trees 😄