pskevin commented on a change in pull request #12445:
URL: https://github.com/apache/beam/pull/12445#discussion_r465365506



##########
File path: sdks/go/examples/xlang/wordcount/xlang_wordcount.go
##########
@@ -0,0 +1,100 @@
+package main
+
+import (
+       "context"
+       "flag"
+       "fmt"
+       "log"
+       "regexp"
+       "strings"
+
+       "github.com/apache/beam/sdks/go/pkg/beam/core/typex"
+       "github.com/apache/beam/sdks/go/pkg/beam/core/util/reflectx"
+
+       "github.com/apache/beam/sdks/go/pkg/beam"
+       "github.com/apache/beam/sdks/go/pkg/beam/io/textio"
+       "github.com/apache/beam/sdks/go/pkg/beam/x/beamx"
+
+       // Imports to enable correct filesystem access and runner setup in 
LOOPBACK mode
+       _ "github.com/apache/beam/sdks/go/pkg/beam/io/filesystem/gcs"
+       _ "github.com/apache/beam/sdks/go/pkg/beam/io/filesystem/local"
+       _ "github.com/apache/beam/sdks/go/pkg/beam/runners/universal"
+)
+
+var (
+       // Set this option to choose a different input file or glob.
+       input = flag.String("input", "./input", "File(s) to read.")
+
+       // Set this required option to specify where to write the output.
+       output = flag.String("output", "./output", "Output file (required).")
+)
+
+var (
+       wordRE  = regexp.MustCompile(`[a-zA-Z]+('[a-z])?`)
+       empty   = beam.NewCounter("extract", "emptyLines")
+       lineLen = beam.NewDistribution("extract", "lineLenDistro")
+)
+
+// extractFn is a DoFn that emits the words in a given line.
+func extractFn(ctx context.Context, line string, emit func(string)) {
+       lineLen.Update(ctx, int64(len(line)))
+       if len(strings.TrimSpace(line)) == 0 {
+               empty.Inc(ctx, 1)
+       }
+       for _, word := range wordRE.FindAllString(line, -1) {
+               emit(word)
+       }
+}
+
+// formatFn is a DoFn that formats a word and its count as a string.
+func formatFn(w string, c int64) string {
+       fmt.Println(w, c)

Review comment:
       Thanks for catching that! Ack.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to