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



##########
File path: 
runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/ValidateRunnerXlangTest.java
##########
@@ -177,6 +232,14 @@ public void coGroupByKeyTest() {
     PAssert.that(col).containsInAnyOrder("0:1,2,4", "1:3,5,6");
   }
 
+  /**
+   * Motivation behind combineGloballyTest.

Review comment:
       Let's keep these unrelated documentation updates in a separate PR.

##########
File path: sdks/go/examples/xlang/wordcount/input
##########
@@ -0,0 +1,5 @@
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris id tellus 
vehicula, rutrum turpis quis, suscipit est. Quisque vehicula nec ex a interdum. 
Phasellus vulputate nunc sit amet nisl dapibus tincidunt ut ullamcorper nisi. 
Mauris gravida porta leo vel congue. Duis sit amet arcu eu nisl pharetra 
interdum a eget enim. Nulla facilisis massa ut egestas interdum. Nunc elit dui, 
hendrerit at pharetra a, pellentesque non turpis. Integer auctor vulputate 
congue. Pellentesque habitant morbi tristique senectus et netus et malesuada 
fames ac turpis egestas. Ut sagittis convallis lorem non semper. Ut ultrices 
elit a enim pulvinar fermentum.

Review comment:
       Is it possible to use a generated input for tests instead of committing 
this file ?

##########
File path: sdks/go/examples/xlang/wordcount/xlang_wordcount.go
##########
@@ -0,0 +1,100 @@
+package main

Review comment:
       You need to add Apache license to all new files.

##########
File path: sdks/python/Pipfile.lock
##########
@@ -0,0 +1,946 @@
+{
+    "_meta": {
+        "hash": {
+            "sha256": 
"4d830f0b6c127288985ac4b35fef456c1bfcd8ffb2d771f32593d302e04bb80c"
+        },
+        "pipfile-spec": 6,
+        "requires": {

Review comment:
       Ditto.

##########
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)
+       return fmt.Sprintf("%s: %v", w, c)
+}
+
+func init() {
+       beam.RegisterFunction(extractFn)
+       beam.RegisterFunction(formatFn)
+}
+
+func main() {
+       // If beamx or Go flags are used, flags must be parsed first.
+       flag.Parse()
+       // beam.Init() is an initialization hook that must be called on 
startup. On
+       // distributed runners, it is used to intercept control.
+       beam.Init()
+
+       // Input validation is done as usual. Note that it must be after Init().
+       if *output == "" {
+               log.Fatal("No output provided")
+       }
+
+       // Concepts #3 and #4: The pipeline uses the named transform and DoFn.
+       p := beam.NewPipeline()
+       s := p.Root()
+
+       lines := textio.Read(s, *input)
+       // Convert lines of text into individual words.
+       col := beam.ParDo(s, extractFn, lines)
+
+       // Using Cross-language Count from Python's test expansion service
+       // TODO(pskevin): Cleaner using-face API
+       outputType := typex.NewKV(typex.New(reflectx.String), 
typex.New(reflectx.Int64))
+       external := &beam.ExternalTransform{
+               In:            []beam.PCollection{col},
+               Urn:           "beam:transforms:xlang:count",
+               ExpansionAddr: "localhost:8118",
+               Out:           []typex.FullType{outputType},
+               Bounded:       true, // TODO(pskevin): Infer this value from 
output PCollection(s) part of the expanded tranform
+       }
+       counted := beam.CrossLanguage(s, p, external) // TODO(pskevin): Add 
external transform to Pipeline without passing it to the transform

Review comment:
       Can we directly setup 'CrossLanguage' transform as the primary user API 
instead of having to setup a separate ExternalTransform struct ?

##########
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)
+       return fmt.Sprintf("%s: %v", w, c)
+}
+
+func init() {
+       beam.RegisterFunction(extractFn)
+       beam.RegisterFunction(formatFn)
+}
+
+func main() {
+       // If beamx or Go flags are used, flags must be parsed first.
+       flag.Parse()
+       // beam.Init() is an initialization hook that must be called on 
startup. On
+       // distributed runners, it is used to intercept control.
+       beam.Init()
+
+       // Input validation is done as usual. Note that it must be after Init().
+       if *output == "" {
+               log.Fatal("No output provided")
+       }
+
+       // Concepts #3 and #4: The pipeline uses the named transform and DoFn.
+       p := beam.NewPipeline()
+       s := p.Root()
+
+       lines := textio.Read(s, *input)
+       // Convert lines of text into individual words.
+       col := beam.ParDo(s, extractFn, lines)
+
+       // Using Cross-language Count from Python's test expansion service
+       // TODO(pskevin): Cleaner using-face API
+       outputType := typex.NewKV(typex.New(reflectx.String), 
typex.New(reflectx.Int64))
+       external := &beam.ExternalTransform{

Review comment:
       Woohoo!

##########
File path: sdks/python/Pipfile
##########
@@ -0,0 +1,12 @@
+[[source]]
+name = "pypi"

Review comment:
       Do we need this ?

##########
File path: sdks/python/apache_beam/examples/wordcount_docker.py
##########
@@ -0,0 +1,148 @@
+#
+# 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.

Review comment:
       Probably extract out these wordcount_xxx updates to a separate PR.

##########
File path: sdks/python/apache_beam/transforms/validate_runner_xlang_test.py
##########
@@ -14,6 +14,42 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+
+"""
+###########################################################
+Runner Validation Test Suite for Cross-language Transforms
+###########################################################
+ As per Beams's Portability Framework design, Cross-language transforms

Review comment:
       Ditto regarding keeping these documentation updates in the other PR.




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