-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[pulsar-io] Refine the key in redis sink when key is null #11192
Conversation
byte[] value = record.getValue(); | ||
byte[] key = record.getKey().isPresent() ? record.getKey().get().getBytes(StandardCharsets.UTF_8) : value; |
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.
why are you using the value
as key ?
probably if the record has no "key" we should discard it
mapping a null key to the value is not immediate for the user
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 null key cannot flush to redis, java.lang.NullPointerException: null
may confuse someone who will treat as no record is coming.
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.
Maybe an empty string ""
looks better?
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.
Empty String makes more sense 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.
Done, please take a look again, thanks.
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.
This behavior looks strange to me.
Could you provide some link to other connectors that use value as key?
Like |
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.
LGTM
@congbobo184 @codelipenghui PTAL |
### Motivation When the record has a null key, someone maybe confused by a NPE warn as below: ``` 11:26:22.730 [pool-5-thread-1] WARN org.apache.pulsar.io.redis.sink.RedisSink - Record flush thread was exception java.lang.NullPointerException: null at java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011) ~[?:1.8.0_291] at java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:1006) ~[?:1.8.0_291] at org.apache.pulsar.io.redis.sink.RedisSink.flush(RedisSink.java:127) ~[pulsar-io-redis-2.8.0.nar-unpacked/:?] at org.apache.pulsar.io.redis.sink.RedisSink.lambda$write$1(RedisSink.java:94) ~[pulsar-io-redis-2.8.0.nar-unpacked/:?] ``` We can use an empty string as key when its key is null as other sinks do. ### Modifications - Use an empty string as key when its key is null. (cherry picked from commit 27797d9)
### Motivation When the record has a null key, someone maybe confused by a NPE warn as below: ``` 11:26:22.730 [pool-5-thread-1] WARN org.apache.pulsar.io.redis.sink.RedisSink - Record flush thread was exception java.lang.NullPointerException: null at java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011) ~[?:1.8.0_291] at java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:1006) ~[?:1.8.0_291] at org.apache.pulsar.io.redis.sink.RedisSink.flush(RedisSink.java:127) ~[pulsar-io-redis-2.8.0.nar-unpacked/:?] at org.apache.pulsar.io.redis.sink.RedisSink.lambda$write$1(RedisSink.java:94) ~[pulsar-io-redis-2.8.0.nar-unpacked/:?] ``` We can use an empty string as key when its key is null as other sinks do. ### Modifications - Use an empty string as key when its key is null.
Motivation
When the record has a null key, someone maybe confused by a NPE warn as below:
We can use an empty string as key when its key is null as other sinks do.
Modifications