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 2022/09/01 17:53:04 UTC

[GitHub] [accumulo-website] jmark99 commented on a diff in pull request #334: Replace older Tour with newer JShell Tour

jmark99 commented on code in PR #334:
URL: https://github.com/apache/accumulo-website/pull/334#discussion_r960952152


##########
tour/batch-scanner-code.md:
##########
@@ -4,44 +4,52 @@ title: Batch Scanner Code
 
 Below is a solution to the exercise.
 
-```java
-  static void exercise(AccumuloClient client) throws Exception {
-    // Create a table called "GothamPD".
-    client.tableOperations().create("GothamPD");
-
-    // Generate 10,000 rows of henchman data
-    try (BatchWriter writer = client.createBatchWriter("GothamPD")) {
-      for (int i = 0; i < 10_000; i++) {
-        Mutation m = new Mutation(String.format("id%04d", i));
-        m.put("villain", "alias", "henchman" + i);
-        m.put("villain", "yearsOfService", "" + (new Random().nextInt(50)));
-        m.put("villain", "wearsCape?", "false");
-        writer.addMutation(m);
-      }
-    }
-    // 1. Create a BatchScanner with 5 query threads
-    try (BatchScanner batchScanner = client.createBatchScanner("GothamPD", Authorizations.EMPTY, 5)) {
-
-      // 2. Create a collection of 2 sample ranges and set it to the batchScanner
-      List<Range>ranges = new ArrayList<Range>();
-      ranges.add(new Range("id1000", "id1999"));
-      ranges.add(new Range("id9000", "id9999"));
-      batchScanner.setRanges(ranges);
-
-      // 3. Fetch just the columns we want
-      batchScanner.fetchColumn(new Text("villain"), new Text("yearsOfService"));
-
-      // 4. Calculate average years of service
-      Long totalYears = 0L;
-      Long entriesRead = 0L;
-      for (Map.Entry<Key, Value> entry : batchScanner) {
-        totalYears += Long.valueOf(entry.getValue().toString());
-        entriesRead++;
-      }
-      System.out.println("The average years of service of " + entriesRead + " villains is " + totalYears / entriesRead);
-    }
-  }
+Create a table called "GothamBatch".
+
+```commandline
+jshell> client.tableOperations().create("GothamBatch");
+```
+
+Generate 10,000 rows of villain data
+
+```commandline
+jshell> try (BatchWriter writer = client.createBatchWriter("GothamBatch")) {
+   ...>   for (int i = 0; i < 10_000; i++) {
+   ...>     Mutation m = new Mutation(String.format("id%04d", i));
+   ...>     m.put("villain", "alias", "henchman" + i);
+   ...>     m.put("villain", "yearsOfService", "" + (new Random().nextInt(50)));
+   ...>     m.put("villain", "wearsCape?", "false");
+   ...>    writer.addMutation(m);
+   ...>   }
+   ...> }
 ```
+
+Create a BatchScanner with 5 query threads
+```commandline
+jshell> try (BatchScanner batchScanner = client.createBatchScanner("GothamBatch", Authorizations.EMPTY, 5)) {
+   ...> 
+   ...>   // Create a collection of 2 sample ranges and set it to the batchScanner
+   ...>   List<Range> ranges = new ArrayList<Range>();
+   ...> 
+   ...>   // Create a collection of 2 sample ranges and set it to the batchScanner
+   ...>   ranges.add(new Range("id1000", "id1999"));
+   ...>   ranges.add(new Range("id9000", "id9999"));
+   ...>   batchScanner.setRanges(ranges);
+   ...> 
+   ...>   // Fetch just the columns we want
+   ...>   batchScanner.fetchColumn(new Text("villain"), new Text("yearsOfService"));
+   ...> 
+   ...>   // Calculate average years of service
+   ...>   Long totalYears = 0L;
+   ...>   Long entriesRead = 0L;
+   ...>   for (Map.Entry<Key, Value> entry : batchScanner) {
+   ...>     totalYears += Long.valueOf(entry.getValue().toString());
+   ...>     entriesRead++;
+   ...>   }
+   ...>   System.out.println("The average years of service of " + entriesRead + " villains is " + totalYears / entriesRead);

Review Comment:
   @DomGarguilo I updated the batchScanner to make use of streams as suggested. Thanks for the suggestion.



-- 
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: notifications-unsubscribe@accumulo.apache.org

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