You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "elenacliu (via GitHub)" <gi...@apache.org> on 2023/04/24 07:38:25 UTC

[GitHub] [rocketmq-streams] elenacliu opened a new pull request, #284: [ISSUE #246] finish data processing when function return null

elenacliu opened a new pull request, #284:
URL: https://github.com/apache/rocketmq-streams/pull/284

   #246 
   During test, I modified the mapping function in `WordCount.java` a little to generate `null` value. This is the output results. 
   <img width="1470" alt="image" src="https://user-images.githubusercontent.com/44845151/233929801-fab62c91-01de-439b-a62c-5348e29948e8.png">
   


-- 
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@rocketmq.apache.org

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


[GitHub] [rocketmq-streams] ni-ze merged pull request #284: [ISSUE #246] finish data processing when function return null

Posted by "ni-ze (via GitHub)" <gi...@apache.org>.
ni-ze merged PR #284:
URL: https://github.com/apache/rocketmq-streams/pull/284


-- 
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@rocketmq.apache.org

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


[GitHub] [rocketmq-streams] elenacliu commented on pull request #284: [ISSUE #246] finish data processing when function return null

Posted by "elenacliu (via GitHub)" <gi...@apache.org>.
elenacliu commented on PR #284:
URL: https://github.com/apache/rocketmq-streams/pull/284#issuecomment-1519585197

   Here are my examples:
   
   example1: 
   ```java
   /*
    * Licensed to the Apache Software Foundation (ASF) under one or more
    * contributor license agreements.  See the NOTICE file distributed with
    * this work for additional information regarding copyright ownership.
    * The ASF licenses this file to You under the Apache License, Version 2.0
    * (the "License"); you may not use this file except in compliance with
    * the License.  You may obtain a copy of the License at
    *
    *     http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
   package org.apache.rocketmq.streams.examples;
   
   import org.apache.rocketmq.common.MixAll;
   import org.apache.rocketmq.streams.core.RocketMQStream;
   import org.apache.rocketmq.streams.core.function.ValueMapperAction;
   import org.apache.rocketmq.streams.core.rstream.StreamBuilder;
   import org.apache.rocketmq.streams.core.topology.TopologyBuilder;
   import org.apache.rocketmq.streams.core.util.Pair;
   
   import java.nio.charset.StandardCharsets;
   import java.util.Arrays;
   import java.util.List;
   import java.util.Properties;
   
   public class WordCount {
       public static void main(String[] args) {
           StreamBuilder builder = new StreamBuilder("wordCount");
   
           builder.source("sourceTopic", total -> {
                       String value = new String(total, StandardCharsets.UTF_8);
                       return new Pair<>(null, value);
                   })
                   .flatMap((ValueMapperAction<String, List<String>>) value -> {
                       String[] splits = value.toLowerCase().split("\\W+");
                       splits[0] = null;
                       return Arrays.asList(splits);
                   })
                   .keyBy(value -> value)
                   .count()
                   .toRStream()
                   .print();
   
           TopologyBuilder topologyBuilder = builder.build();
   
           Properties properties = new Properties();
           properties.put(MixAll.NAMESRV_ADDR_PROPERTY, "127.0.0.1:9876");
   
           RocketMQStream rocketMQStream = new RocketMQStream(topologyBuilder, properties);
   
   
           Runtime.getRuntime().addShutdownHook(new Thread("wordcount-shutdown-hook") {
               @Override
               public void run() {
                   rocketMQStream.stop();
               }
           });
   
           rocketMQStream.start();
       }
   }
   ```
   example2:
   ```java
   /*
    * Licensed to the Apache Software Foundation (ASF) under one or more
    * contributor license agreements.  See the NOTICE file distributed with
    * this work for additional information regarding copyright ownership.
    * The ASF licenses this file to You under the Apache License, Version 2.0
    * (the "License"); you may not use this file except in compliance with
    * the License.  You may obtain a copy of the License at
    *
    *     http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
   package org.apache.rocketmq.streams.examples;
   
   import org.apache.rocketmq.common.MixAll;
   import org.apache.rocketmq.streams.core.RocketMQStream;
   import org.apache.rocketmq.streams.core.function.ValueMapperAction;
   import org.apache.rocketmq.streams.core.rstream.StreamBuilder;
   import org.apache.rocketmq.streams.core.topology.TopologyBuilder;
   import org.apache.rocketmq.streams.core.util.Pair;
   
   import java.nio.charset.StandardCharsets;
   import java.util.Arrays;
   import java.util.List;
   import java.util.Properties;
   
   public class WordCount {
       public static void main(String[] args) {
           StreamBuilder builder = new StreamBuilder("wordCount");
   
           builder.source("sourceTopic", total -> {
                       String value = new String(total, StandardCharsets.UTF_8);
                       return new Pair<>(null, value);
                   })
                   .flatMap((ValueMapperAction<String, List<String>>) value -> {
                       // String[] splits = value.toLowerCase().split("\\W+");
                       // splits[0] = null;
                       // return Arrays.asList(splits);
                       return null;
                   })
                   .keyBy(value -> value)
                   .count()
                   .toRStream()
                   .print();
   
           TopologyBuilder topologyBuilder = builder.build();
   
           Properties properties = new Properties();
           properties.put(MixAll.NAMESRV_ADDR_PROPERTY, "127.0.0.1:9876");
   
           RocketMQStream rocketMQStream = new RocketMQStream(topologyBuilder, properties);
   
   
           Runtime.getRuntime().addShutdownHook(new Thread("wordcount-shutdown-hook") {
               @Override
               public void run() {
                   rocketMQStream.stop();
               }
           });
   
           rocketMQStream.start();
       }
   }
   ```


-- 
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@rocketmq.apache.org

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


[GitHub] [rocketmq-streams] elenacliu commented on a diff in pull request #284: [ISSUE #246] finish data processing when function return null

Posted by "elenacliu (via GitHub)" <gi...@apache.org>.
elenacliu commented on code in PR #284:
URL: https://github.com/apache/rocketmq-streams/pull/284#discussion_r1184481555


##########
core/src/main/java/org/apache/rocketmq/streams/core/function/supplier/MultiValueChangeSupplier.java:
##########
@@ -46,7 +50,16 @@ public MultiValueMapperProcessor(ValueMapperAction<T, ? extends Iterable<? exten
         public void process(T data) throws Throwable {
             Iterable<? extends VR> convert = valueMapperAction.convert(data);
 
+            if (convert == null) {
+                logger.warn("discard data:[{}]", convert);
+                return;
+            }
+
             for (VR item : convert) {
+                if (item == null) {
+                    logger.warn("discard data:[{}]", item);

Review Comment:
   OK, so I should delete the `logger.warn` line and just return?



-- 
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@rocketmq.apache.org

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


[GitHub] [rocketmq-streams] ni-ze commented on a diff in pull request #284: [ISSUE #246] finish data processing when function return null

Posted by "ni-ze (via GitHub)" <gi...@apache.org>.
ni-ze commented on code in PR #284:
URL: https://github.com/apache/rocketmq-streams/pull/284#discussion_r1184488094


##########
core/src/main/java/org/apache/rocketmq/streams/core/function/supplier/MultiValueChangeSupplier.java:
##########
@@ -46,7 +50,16 @@ public MultiValueMapperProcessor(ValueMapperAction<T, ? extends Iterable<? exten
         public void process(T data) throws Throwable {
             Iterable<? extends VR> convert = valueMapperAction.convert(data);
 
+            if (convert == null) {
+                logger.warn("discard data:[{}]", convert);
+                return;
+            }
+
             for (VR item : convert) {
+                if (item == null) {
+                    logger.warn("discard data:[{}]", item);

Review Comment:
   Remove the log or modify to other sentence is ok. 



-- 
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@rocketmq.apache.org

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


[GitHub] [rocketmq-streams] elenacliu commented on pull request #284: [ISSUE #246] finish data processing when function return null

Posted by "elenacliu (via GitHub)" <gi...@apache.org>.
elenacliu commented on PR #284:
URL: https://github.com/apache/rocketmq-streams/pull/284#issuecomment-1533999043

   
   
   
   
   > > Besides I'm wondering will there be a complete test framework in the future to test the functions?
   > 
   > Yes, Open source projects should have complete unit tests. Are you interested in participating in unit testing contributions?
   
   Yes I'm interested in that, but I have little idea about how to setup a complete test framework in java now.


-- 
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@rocketmq.apache.org

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


[GitHub] [rocketmq-streams] elenacliu commented on pull request #284: [ISSUE #246] finish data processing when function return null

Posted by "elenacliu (via GitHub)" <gi...@apache.org>.
elenacliu commented on PR #284:
URL: https://github.com/apache/rocketmq-streams/pull/284#issuecomment-1519592981

   Besides I'm wondering will there be a complete test framework in the future to test the functions?


-- 
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@rocketmq.apache.org

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


[GitHub] [rocketmq-streams] ni-ze commented on pull request #284: [ISSUE #246] finish data processing when function return null

Posted by "ni-ze (via GitHub)" <gi...@apache.org>.
ni-ze commented on PR #284:
URL: https://github.com/apache/rocketmq-streams/pull/284#issuecomment-1533952504

   > Besides I'm wondering will there be a complete test framework in the future to test the functions?
   
   Yes, Open source projects should have complete unit tests.  Are you interested in participating in unit testing contributions?


-- 
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@rocketmq.apache.org

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


[GitHub] [rocketmq-streams] ni-ze commented on a diff in pull request #284: [ISSUE #246] finish data processing when function return null

Posted by "ni-ze (via GitHub)" <gi...@apache.org>.
ni-ze commented on code in PR #284:
URL: https://github.com/apache/rocketmq-streams/pull/284#discussion_r1184457564


##########
core/src/main/java/org/apache/rocketmq/streams/core/function/supplier/MultiValueChangeSupplier.java:
##########
@@ -46,7 +50,16 @@ public MultiValueMapperProcessor(ValueMapperAction<T, ? extends Iterable<? exten
         public void process(T data) throws Throwable {
             Iterable<? extends VR> convert = valueMapperAction.convert(data);
 
+            if (convert == null) {
+                logger.warn("discard data:[{}]", convert);
+                return;
+            }
+
             for (VR item : convert) {
+                if (item == null) {
+                    logger.warn("discard data:[{}]", item);

Review Comment:
   IMO, if it is null after convert, finish the process and return is nature, "discard data:[{}]" may cause misunderstanding.



-- 
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@rocketmq.apache.org

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