beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhalp...@apache.org
Subject [1/2] incubator-beam git commit: Replace GcsPath by IOChannelFactory in WordCount.
Date Thu, 16 Jun 2016 17:18:30 GMT
Repository: incubator-beam
Updated Branches:
  refs/heads/master 41fe8eecf -> 0a3425e77


Replace GcsPath by IOChannelFactory in WordCount.


Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/1239f111
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/1239f111
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/1239f111

Branch: refs/heads/master
Commit: 1239f1110b878a7f91f497374cca2731eb55a542
Parents: 41fe8ee
Author: Pei He <peihe@google.com>
Authored: Mon Jun 13 16:58:01 2016 -0700
Committer: Dan Halperin <dhalperi@google.com>
Committed: Thu Jun 16 10:18:20 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/beam/examples/WordCount.java | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/1239f111/examples/java/src/main/java/org/apache/beam/examples/WordCount.java
----------------------------------------------------------------------
diff --git a/examples/java/src/main/java/org/apache/beam/examples/WordCount.java b/examples/java/src/main/java/org/apache/beam/examples/WordCount.java
index f5611d3..03ed5d7 100644
--- a/examples/java/src/main/java/org/apache/beam/examples/WordCount.java
+++ b/examples/java/src/main/java/org/apache/beam/examples/WordCount.java
@@ -32,10 +32,15 @@ import org.apache.beam.sdk.transforms.PTransform;
 import org.apache.beam.sdk.transforms.ParDo;
 import org.apache.beam.sdk.transforms.SimpleFunction;
 import org.apache.beam.sdk.transforms.Sum;
-import org.apache.beam.sdk.util.gcsfs.GcsPath;
+import org.apache.beam.sdk.util.IOChannelFactory;
+import org.apache.beam.sdk.util.IOChannelUtils;
 import org.apache.beam.sdk.values.KV;
 import org.apache.beam.sdk.values.PCollection;
 
+import com.google.common.base.Strings;
+
+import java.io.IOException;
+
 /**
  * An example that counts words in Shakespeare and includes Beam best practices.
  *
@@ -176,9 +181,15 @@ public class WordCount {
     public static class OutputFactory implements DefaultValueFactory<String> {
       @Override
       public String create(PipelineOptions options) {
-        if (options.getTempLocation() != null) {
-          return GcsPath.fromUri(options.getTempLocation())
-              .resolve("counts.txt").toString();
+        String tempLocation = options.getTempLocation();
+        if (!Strings.isNullOrEmpty(tempLocation)) {
+          try {
+            IOChannelFactory factory = IOChannelUtils.getFactory(tempLocation);
+            return factory.resolve(tempLocation, "counts.txt");
+          } catch (IOException e) {
+            throw new RuntimeException(
+                String.format("Failed to resolve temp location: %s", tempLocation));
+          }
         } else {
           throw new IllegalArgumentException("Must specify --output or --tempLocation");
         }


Mime
View raw message