You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2020/10/19 21:40:03 UTC

[GitHub] [accumulo] milleruntime opened a new issue #1742: Better Use of forEach on Scanner to simplify iteration

milleruntime opened a new issue #1742:
URL: https://github.com/apache/accumulo/issues/1742


   It would be nice if we could reduce some of the boiler plate when iterating using Scanner.  It feels like Scanner should be able to use the [forEach](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html#forEach-java.util.function.Consumer-) method introduced in Java 1.8 better than the way it works now.  For example, since Java 1.8 I can use the forEach to iterate over a Map nicely like so:
   ```
   Map<Key,Value> myMap = new HashMap<>();
         myMap.forEach((k,v) -> {
           Text cf = k.getColumnFamily();
           int size = v.getSize();
         });
   ```
   But I can't do that with the Accumulo Scanner, the best I can do is:
   ```
   for (Entry<Key,Value> entry : scanner) {
           if (entry.getKey().getColumnFamily().equals(CurrentLocationColumnFamily.NAME)) {
             assigned.put(entry.getKey(), entry.getValue());
           } else if (entry.getKey().getColumnFamily().equals(FutureLocationColumnFamily.NAME)) {
             future.put(entry.getKey(), entry.getValue());
           }
         }
   ```
   I am not sure if it is possible with our API but it would be nice, if that code could look like this:
   ```
   scanner.forEach((k,v) -> {
           if (k.getColumnFamily().equals(CurrentLocationColumnFamily.NAME)) {
             assigned.put(k, v);
           } else if (k.getColumnFamily().equals(FutureLocationColumnFamily.NAME)) {
             future.put(k, v);
           }
         }
   ```


----------------------------------------------------------------
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.

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



[GitHub] [accumulo] ctubbsii commented on issue #1742: Better Use of forEach on Scanner to simplify iteration

Posted by GitBox <gi...@apache.org>.
ctubbsii commented on issue #1742:
URL: https://github.com/apache/accumulo/issues/1742#issuecomment-712505918


   In ScannerBase, something like the following should work fine:
   ```java
       default void forEach​(BiConsumer<? super Key,​? super Value> keyValueConsumer) {
         for (Entry<Key, Value> entry : this) {
           keyValueConsumer.accept(entry.getKey(), entry.getValue());
         }
       } 
   ```
   


----------------------------------------------------------------
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.

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



[GitHub] [accumulo] keith-turner commented on issue #1742: Better Use of forEach on Scanner to simplify iteration

Posted by GitBox <gi...@apache.org>.
keith-turner commented on issue #1742:
URL: https://github.com/apache/accumulo/issues/1742#issuecomment-712509817


   Could also consider stream support.  This would give forEach and more.
   
   https://issues.apache.org/jira/browse/ACCUMULO-4562


----------------------------------------------------------------
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.

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



[GitHub] [accumulo] ctubbsii closed issue #1742: Better Use of forEach on Scanner to simplify iteration

Posted by GitBox <gi...@apache.org>.
ctubbsii closed issue #1742:
URL: https://github.com/apache/accumulo/issues/1742


   


----------------------------------------------------------------
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.

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



[GitHub] [accumulo] ctubbsii commented on issue #1742: Better Use of forEach on Scanner to simplify iteration

Posted by GitBox <gi...@apache.org>.
ctubbsii commented on issue #1742:
URL: https://github.com/apache/accumulo/issues/1742#issuecomment-712649953


   > Could also consider stream support. This would give forEach and more.
   > 
   > https://issues.apache.org/jira/browse/ACCUMULO-4562
   
   I was thinking about that also. However, a `Stream` would only give us a stream of `Entry<Key, Value>`, and a `forEach` for that wouldn't be as useful as one with a `BiConsumer`, like the `Map` interface provides. It might be nice to have both eventually. However, this can be done independently without worrying about all the messiness that comes with decisions about streams (like what to do with `.stream().parallel()`).


----------------------------------------------------------------
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.

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



[GitHub] [accumulo] keith-turner commented on issue #1742: Better Use of forEach on Scanner to simplify iteration

Posted by GitBox <gi...@apache.org>.
keith-turner commented on issue #1742:
URL: https://github.com/apache/accumulo/issues/1742#issuecomment-714578654


   >  However, a Stream would only give us a stream of Entry<Key, Value>, and a forEach for that wouldn't be as useful as one with a BiConsumer
   
   Good point. BiConsumer is really nice and stream of Entry is a bit cumbersome.


----------------------------------------------------------------
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.

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