You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/07/02 08:10:47 UTC

[GitHub] [pulsar] murong00 opened a new pull request #11192: [pulsar-io] Refine the key in redis sink when key is null

murong00 opened a new pull request #11192:
URL: https://github.com/apache/pulsar/pull/11192


   ### 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 the value of record as key when its key is null as other sinks do.
   
   ### Modifications
   
   - Use the value of record as key when its key is null.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] murong00 commented on pull request #11192: [pulsar-io] Refine the key in redis sink when key is null

Posted by GitBox <gi...@apache.org>.
murong00 commented on pull request #11192:
URL: https://github.com/apache/pulsar/pull/11192#issuecomment-873716229


   > This behavior looks strange to me.
   > 
   > Could you provide some link to other connectors that use value as key?
   
   Like `CassandraStringSink`, `AerospikeStringSink` and `HdfsTextSink` using `record.getKey().orElseGet(() -> record.getValue())` as value.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] eolivelli commented on pull request #11192: [pulsar-io] Refine the key in redis sink when key is null

Posted by GitBox <gi...@apache.org>.
eolivelli commented on pull request #11192:
URL: https://github.com/apache/pulsar/pull/11192#issuecomment-877031418


   @congbobo184 @codelipenghui PTAL
   we need another binding +1


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] nlu90 commented on pull request #11192: [pulsar-io] Refine the key in redis sink when key is null

Posted by GitBox <gi...@apache.org>.
nlu90 commented on pull request #11192:
URL: https://github.com/apache/pulsar/pull/11192#issuecomment-875000168


   I think this is kind of the standard behavior for the connectors regarding this PR from @merlimat https://github.com/apache/pulsar/pull/2116
   
   I'm okay with it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] murong00 commented on a change in pull request #11192: [pulsar-io] Refine the key in redis sink when key is null

Posted by GitBox <gi...@apache.org>.
murong00 commented on a change in pull request #11192:
URL: https://github.com/apache/pulsar/pull/11192#discussion_r663584709



##########
File path: pulsar-io/redis/src/main/java/org/apache/pulsar/io/redis/sink/RedisSink.java
##########
@@ -121,9 +121,9 @@ private void flush() {
         if (CollectionUtils.isNotEmpty(recordsToFlush)) {
             for (Record<byte[]> record: recordsToFlush) {
                 try {
-                    // records with null keys or values will be ignored
-                    byte[] key = record.getKey().isPresent() ? record.getKey().get().getBytes(StandardCharsets.UTF_8) : null;
+                    // use the value of record as key when its key is null
                     byte[] value = record.getValue();
+                    byte[] key = record.getKey().isPresent() ? record.getKey().get().getBytes(StandardCharsets.UTF_8) : value;

Review comment:
       A null key cannot flush to redis, `java.lang.NullPointerException: null` may confuse someone who will treat as no record is coming.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] eolivelli commented on a change in pull request #11192: [pulsar-io] Refine the key in redis sink when key is null

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #11192:
URL: https://github.com/apache/pulsar/pull/11192#discussion_r662903661



##########
File path: pulsar-io/redis/src/main/java/org/apache/pulsar/io/redis/sink/RedisSink.java
##########
@@ -121,9 +121,9 @@ private void flush() {
         if (CollectionUtils.isNotEmpty(recordsToFlush)) {
             for (Record<byte[]> record: recordsToFlush) {
                 try {
-                    // records with null keys or values will be ignored
-                    byte[] key = record.getKey().isPresent() ? record.getKey().get().getBytes(StandardCharsets.UTF_8) : null;
+                    // use the value of record as key when its key is null
                     byte[] value = record.getValue();
+                    byte[] key = record.getKey().isPresent() ? record.getKey().get().getBytes(StandardCharsets.UTF_8) : value;

Review comment:
       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




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] eolivelli commented on a change in pull request #11192: [pulsar-io] Refine the key in redis sink when key is null

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #11192:
URL: https://github.com/apache/pulsar/pull/11192#discussion_r664876866



##########
File path: pulsar-io/redis/src/main/java/org/apache/pulsar/io/redis/sink/RedisSink.java
##########
@@ -121,9 +121,9 @@ private void flush() {
         if (CollectionUtils.isNotEmpty(recordsToFlush)) {
             for (Record<byte[]> record: recordsToFlush) {
                 try {
-                    // records with null keys or values will be ignored
-                    byte[] key = record.getKey().isPresent() ? record.getKey().get().getBytes(StandardCharsets.UTF_8) : null;
+                    // use the value of record as key when its key is null
                     byte[] value = record.getValue();
+                    byte[] key = record.getKey().isPresent() ? record.getKey().get().getBytes(StandardCharsets.UTF_8) : value;

Review comment:
       Empty String makes more sense to me.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] murong00 edited a comment on pull request #11192: [pulsar-io] Refine the key in redis sink when key is null

Posted by GitBox <gi...@apache.org>.
murong00 edited a comment on pull request #11192:
URL: https://github.com/apache/pulsar/pull/11192#issuecomment-873716229


   > This behavior looks strange to me.
   > 
   > Could you provide some link to other connectors that use value as key?
   
   Like `CassandraStringSink`, `AerospikeStringSink` and `HdfsTextSink` using `record.getKey().orElseGet(() -> record.getValue())` as key.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] murong00 commented on a change in pull request #11192: [pulsar-io] Refine the key in redis sink when key is null

Posted by GitBox <gi...@apache.org>.
murong00 commented on a change in pull request #11192:
URL: https://github.com/apache/pulsar/pull/11192#discussion_r664984406



##########
File path: pulsar-io/redis/src/main/java/org/apache/pulsar/io/redis/sink/RedisSink.java
##########
@@ -121,9 +121,9 @@ private void flush() {
         if (CollectionUtils.isNotEmpty(recordsToFlush)) {
             for (Record<byte[]> record: recordsToFlush) {
                 try {
-                    // records with null keys or values will be ignored
-                    byte[] key = record.getKey().isPresent() ? record.getKey().get().getBytes(StandardCharsets.UTF_8) : null;
+                    // use the value of record as key when its key is null
                     byte[] value = record.getValue();
+                    byte[] key = record.getKey().isPresent() ? record.getKey().get().getBytes(StandardCharsets.UTF_8) : value;

Review comment:
       Done, please take a look again, thanks.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] murong00 commented on a change in pull request #11192: [pulsar-io] Refine the key in redis sink when key is null

Posted by GitBox <gi...@apache.org>.
murong00 commented on a change in pull request #11192:
URL: https://github.com/apache/pulsar/pull/11192#discussion_r663585165



##########
File path: pulsar-io/redis/src/main/java/org/apache/pulsar/io/redis/sink/RedisSink.java
##########
@@ -121,9 +121,9 @@ private void flush() {
         if (CollectionUtils.isNotEmpty(recordsToFlush)) {
             for (Record<byte[]> record: recordsToFlush) {
                 try {
-                    // records with null keys or values will be ignored
-                    byte[] key = record.getKey().isPresent() ? record.getKey().get().getBytes(StandardCharsets.UTF_8) : null;
+                    // use the value of record as key when its key is null
                     byte[] value = record.getValue();
+                    byte[] key = record.getKey().isPresent() ? record.getKey().get().getBytes(StandardCharsets.UTF_8) : value;

Review comment:
       Maybe an empty string `""` looks better?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] sijie merged pull request #11192: [pulsar-io] Refine the key in redis sink when key is null

Posted by GitBox <gi...@apache.org>.
sijie merged pull request #11192:
URL: https://github.com/apache/pulsar/pull/11192


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org