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
Resolves #1663: Add .map variant to RecordCursor that supports changing a result's continuation #1664
Resolves #1663: Add .map variant to RecordCursor that supports changing a result's continuation #1664
Conversation
AWS CodeBuild CI Report for Linux CentOS 7
|
AWS CodeBuild CI Report for Linux CentOS 7
|
// Stripping away the prefix and resuming the cursor should produce the rest of the list | ||
byte[] continuation = result.getContinuation().toBytes(); | ||
assertNotNull(continuation); | ||
RecordCursor<Integer> tailCursor = RecordCursor.fromList(ints, Arrays.copyOfRange(continuation, prefix.size(), continuation.length)); |
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.
If only to provide an example, it would probably be good to have this also map the continuation.
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.
I do wonder whether this is a problematic api, since:
RecordCursor.fromList(ints, continuation).mapContinuation(continuation -> { ... });
could be surprising, since the continuation does not line up.
This is similar to flatMapPipelined
, and perhaps this should be a static method like that, but doing so would require providing a ContinuationConverter
class (or two lambdas) that can do bidirectional conversion.
Potentially more importantly, the code as you have it might make it harder to decouple the code creating the continuation from the one mapping the continuation. Maybe, it's not a real issue, I'm having trouble thinking of a situation where there isn't something that passes the continuation into the code creating cursor, and also calls mapContinuation.
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.
Yeah, the way that it's the caller's responsibility to manipulate the continuation does feel like it could be a bit of a foot-gun. The alternative using a static method might look something like this:
interface ContinuationConvertor {
@Nullable
byte[] unwrapContinuation(@Nullable byte[] continuation);
RecordCursorContinuation wrapContinuation(@Nonnull RecordCursorContinuation continuation);
}
static <T> RecordCursor<T> mapContinuation(@Nonnull Function<byte[], RecordCursor<T>> cursorFunction, @Nonnull ContinuationConvertor convertor, @Nullable byte[] continuation) {
byte[] innerContinuation = convertor.unwrapContinuation(continuation);
return cursorFunction.apply(innerContinuation)
.mapContinuation(convertor::wrapContinuation);
}
(Note that it uses the current .mapContinuation
value in its implementation, but that could theoretically be rewritten.)
Which...maybe isn't too bad, but it doesn't feel great.
AWS CodeBuild CI Report for Linux CentOS 7
|
AWS CodeBuild CI Report for Linux CentOS 7
|
} | ||
|
||
/** | ||
* Get a new cursor by applying transforming the continuation of each result. This function creates |
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.
* Get a new cursor by applying transforming the continuation of each result. This function creates | |
* Get a new cursor by applying a transformation to the continuation of each result. This function creates |
3ae777b
to
1a74148
Compare
Rebase addresses merge conflict |
AWS CodeBuild CI Report for Linux CentOS 7
|
AWS CodeBuild CI Report for Linux CentOS 7
|
…ports changing a result's continuation This adds a variant to `RecordCursor.map` that allows the caller to adjust the continuations returned by a `RecordCursor`. This would allow, for example, for someone to wrap the continuations with new data, or otherwise adjust the continuations returned. This resolves FoundationDB#1663.
… the user think about both wrapping and unwrapping the continuation
1a74148
to
844ee07
Compare
AWS CodeBuild CI Report for Linux CentOS 7
|
844ee07
to
08b1be3
Compare
AWS CodeBuild CI Report for Linux CentOS 7
|
AWS CodeBuild CI Report for Linux CentOS 7
|
AWS CodeBuild CI Report for Linux CentOS 7
|
08b1be3
to
d04a5a5
Compare
Made a trivial commit (changing commit date) to cause PRBs to re-run |
AWS CodeBuild CI Report for Linux CentOS 7
|
Kudos, SonarCloud Quality Gate passed! |
AWS CodeBuild CI Report for Linux CentOS 7
|
This adds a variant to
RecordCursor.map
that allows the caller to adjust the continuations returned by aRecordCursor
. This would allow, for example, for someone to wrap the continuations with new data, or otherwise adjust the continuations returned.This resolves #1663.