-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Allow null consume in BatchPushSource #7573
Conversation
pulsar-io/core/src/main/java/org/apache/pulsar/io/core/BatchPushSource.java
Show resolved
Hide resolved
if (record != null) { | ||
queue.put(record); | ||
} else { | ||
queue.put(new NullRecord()); |
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.
A small optimization: Just declare a final variable and re-use
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.
done
@@ -32,26 +30,43 @@ | |||
*/ | |||
public abstract class BatchPushSource<T> implements BatchSource<T> { | |||
|
|||
private static class NullRecord implements Record { |
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.
Wouldn't it be easier to allow users to place a null value inside their existing Record class and then test for that condition rather than creating a NullRecord class? e.g.
private static final boolean isNull(Record rec) { return (rec == null) || (rec.getValue() == null); }
Then you could just call this method instead of using the instanceof NullRecord
check
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.
The thing is, is a record with a null value the same as returning null? Can a record have a null value but have other fields e.g. key with valid values
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.
The Null object is currently only inserted if the record passed in is null, so there aren't any fields.
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.
Letting users to continue to use their own Record types and using a null value inside the record seems like a more intuitive approach to me
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.
That is the approach thats taken here. Users will be using their own record types and when they are done with the task, will do consume(null) to signify the end of the task. The NullRecord is strictly private class as an internal impl detail ofBatchPushSource
* Added upgrade notes * Allow null message to be passed * More private impl * Fix unittest * Address comments Co-authored-by: Sanjeev Kulkarni <sanjeevk@splunk.com>
* Added upgrade notes * Allow null message to be passed * More private impl * Fix unittest * Address comments Co-authored-by: Sanjeev Kulkarni <sanjeevk@splunk.com>
(If this PR fixes a github issue, please add
Fixes #<xyz>
.)Fixes #
(or if this PR is one task of a github issue, please add
Master Issue: #<xyz>
to link to the master issue.)Master Issue: #
Motivation
BatchSource records allow sources to return a null record to indicate that the batch is done.
For BatchPushSource, since we are using LinkedBlockingQueue, user's cannot simply pass a null value. Thus we need a special mechanism to indicate the end of a batch.
Modifications
Describe the modifications you've done.
Verifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
Does this pull request potentially affect one of the following parts:
If
yes
was chosen, please highlight the changesDocumentation