You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/06/17 01:06:08 UTC
[GitHub] [beam] damondouglas opened a new pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
damondouglas opened a new pull request #12024:
URL: https://github.com/apache/beam/pull/12024
This pull requests adds a Side Input lesson to the Go SDK katas. I would like to request the following reviewers:
(R: @lostluck )
(R: @henryken )
If accepted by both reviewers, please wait until the [Stepik course](https://stepik.org/course/70387) is updated before finally merging this PR.
------------------------
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] [**Choose reviewer(s)**](https://beam.apache.org/contribute/#make-your-change) and mention them in a comment (`R: @username`).
- [x] Format the pull request title like `[BEAM-XXX] Fixes bug in ApproximateQuantiles`, where you replace `BEAM-XXX` with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
- [ ] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://beam.apache.org/contribute/#make-reviewers-job-easier).
Post-Commit Tests Status (on master branch)
------------------------------------------------------------------------------------------------
Lang | SDK | Apex | Dataflow | Flink | Samza | Spark
--- | --- | --- | --- | --- | --- | ---
Go | [](https://builds.apache.org/job/beam_PostCommit_Go/lastCompletedBuild/) | --- | --- | [](https://builds.apache.org/job/beam_PostCommit_Go_VR_Flink/lastCompletedBuild/) | --- | [](https://builds.apache.org/job/beam_PostCommit_Go_VR_Spark/lastCompletedBuild/)
Java | [](https://builds.apache.org/job/beam_PostCommit_Java/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Apex/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Dataflow/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Dataflow_Java11/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Flink/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Flink_Java11/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Java_PVR_Flink_Batch/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Java_PVR_Flink_Streaming/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Samza/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Spark/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Java_PVR_Spark_Batch/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Java_ValidatesRunner_SparkStructuredStreaming/lastCompletedBuild/)
Python | [](https://builds.apache.org/job/beam_PostCommit_Python2/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Python35/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Python36/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Python37/lastCompletedBuild/) | --- | [](https://builds.apache.org/job/beam_PostCommit_Py_VR_Dataflow/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Py_VR_Dataflow_V2/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Py_ValCont/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PreCommit_Python2_PVR_Flink_Cron/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PostCommit_Python35_VR_Flink/lastCompletedBuild/) | --- | [](https://builds.apache.org/job/beam_PostCommit_Python_VR_Spark/lastCompletedBuild/)
XLang | --- | --- | --- | [](https://builds.apache.org/job/beam_PostCommit_XVR_Flink/lastCompletedBuild/) | --- | --- | [](https://builds.apache.org/job/beam_PostCommit_XVR_Spark/lastCompletedBuild/)
Pre-Commit Tests Status (on master branch)
------------------------------------------------------------------------------------------------
--- |Java | Python | Go | Website
--- | --- | --- | --- | ---
Non-portable | [](https://builds.apache.org/job/beam_PreCommit_Java_Cron/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PreCommit_Python_Cron/lastCompletedBuild/)<br>[](https://builds.apache.org/job/beam_PreCommit_PythonLint_Cron/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PreCommit_Go_Cron/lastCompletedBuild/) | [](https://builds.apache.org/job/beam_PreCommit_Website_Cron/lastCompletedBuild/)
Portable | --- | [](https://builds.apache.org/job/beam_PreCommit_Portable_Python_Cron/lastCompletedBuild/) | --- | ---
See [.test-infra/jenkins/README](https://github.com/apache/beam/blob/master/.test-infra/jenkins/README.md) for trigger phrase, status and link of all Jenkins jobs.
----------------------------------------------------------------
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] [beam] damondouglas commented on pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
damondouglas commented on pull request #12024:
URL: https://github.com/apache/beam/pull/12024#issuecomment-646430972
@lostluck / @henryken thank you for reviewing this. If you both approve, I will update [the stepik course](https://stepik.org/course/70387) and then commit the `*-remote.yaml` files to this PR to be finally merged into master.
----------------------------------------------------------------
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] [beam] damondouglas commented on pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
damondouglas commented on pull request #12024:
URL: https://github.com/apache/beam/pull/12024#issuecomment-647240351
@lostluck I've updated [the stepik course](https://stepik.org/course/70387/) and committed the `*-remote.yaml` files to this PR. It can be merged into master now. Thank you.
----------------------------------------------------------------
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] [beam] lostluck merged pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
lostluck merged pull request #12024:
URL: https://github.com/apache/beam/pull/12024
----------------------------------------------------------------
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] [beam] lostluck commented on pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
lostluck commented on pull request #12024:
URL: https://github.com/apache/beam/pull/12024#issuecomment-647686584
Thanks!
----------------------------------------------------------------
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] [beam] lostluck commented on a change in pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
lostluck commented on a change in pull request #12024:
URL: https://github.com/apache/beam/pull/12024#discussion_r442603782
##########
File path: learning/katas/go/Core Transforms/Side Input/Side Input/pkg/task/task.go
##########
@@ -0,0 +1,45 @@
+// 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.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package task
+
+import (
+ "github.com/apache/beam/sdks/go/pkg/beam"
+)
+
+type Person struct {
+ Name, City, Country string
+}
+
+func ApplyTransform(s beam.Scope, personsKV beam.PCollection, citiesToCountries beam.PCollection) beam.PCollection {
+ citiesToCountriesView := beam.SideInput{
+ Input: citiesToCountries,
+ }
+ return beam.ParDo(s, joinFn, personsKV, citiesToCountriesView)
+}
+
+func joinFn(person Person, citiesToCountriesIter func(*string, *string) bool, emit func(Person)) {
+ var city, country string
+ for citiesToCountriesIter(&city, &country) {
Review comment:
Good question!
No.
It's a valid way to iterate through KV PCollections as Side inputs. Eg. You know your set of KVs is short, but dynamic, and you'll need all of them at random while processing a DoFn.
Ideally we also have an alternate Map/Get style random access to KV side inputs as well, but it would be in addition to the existing way.
With generics for Go taking their [next steps](https://blog.golang.org/generics-next-step), maybe next year we could bolster the iteration API with any official Iteration format, in addition to the current methods.
Edit: There's also the ordinary PCollection<V> approach, which wouldn't be KVs, which would also demonstrate Side input iteration. Side inputs iterators don't have to be KVs.
----------------------------------------------------------------
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] [beam] damondouglas commented on pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
damondouglas commented on pull request #12024:
URL: https://github.com/apache/beam/pull/12024#issuecomment-645403632
> Btw, why do we have many go.mod/sum changes?
Thank you, @henryken for reviewing. The reason is for each PR I run `go get -u github.com/apache/beam/sdks/go/pkg/beam` in each of the task folders where we have a `go.mod` file.
----------------------------------------------------------------
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] [beam] damondouglas edited a comment on pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
damondouglas edited a comment on pull request #12024:
URL: https://github.com/apache/beam/pull/12024#issuecomment-645403632
> Btw, why do we have many go.mod/sum changes?
Thank you, @henryken for reviewing. The reason for this is I run `go get -u github.com/apache/beam/sdks/go/pkg/beam` in each of the task folders where we have a `go.mod` file.
----------------------------------------------------------------
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] [beam] lostluck commented on pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
lostluck commented on pull request #12024:
URL: https://github.com/apache/beam/pull/12024#issuecomment-645497831
@damondouglas Re: updating all the go files. That's something that's probably best to have in it's own PR, after we've finished with the lesson updates. Nothing for it right now (I'll just filter those changes anyway) but it's ideal to avoid unrelated Update style changes in a PR about something else.
----------------------------------------------------------------
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] [beam] damondouglas commented on a change in pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
damondouglas commented on a change in pull request #12024:
URL: https://github.com/apache/beam/pull/12024#discussion_r442621460
##########
File path: learning/katas/go/Core Transforms/Side Input/Side Input/pkg/task/task.go
##########
@@ -0,0 +1,45 @@
+// 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.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package task
+
+import (
+ "github.com/apache/beam/sdks/go/pkg/beam"
+)
+
+type Person struct {
+ Name, City, Country string
+}
+
+func ApplyTransform(s beam.Scope, personsKV beam.PCollection, citiesToCountries beam.PCollection) beam.PCollection {
+ citiesToCountriesView := beam.SideInput{
+ Input: citiesToCountries,
+ }
+ return beam.ParDo(s, joinFn, personsKV, citiesToCountriesView)
+}
+
+func joinFn(person Person, citiesToCountriesIter func(*string, *string) bool, emit func(Person)) {
+ var city, country string
+ for citiesToCountriesIter(&city, &country) {
Review comment:
@lostluck / @henryken I'll keep close to the corresponding Java kata and use the KV<string, string> form as a source of the side input.
----------------------------------------------------------------
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] [beam] lostluck commented on a change in pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
lostluck commented on a change in pull request #12024:
URL: https://github.com/apache/beam/pull/12024#discussion_r441691646
##########
File path: learning/katas/go/Core Transforms/Side Input/Side Input/pkg/task/task.go
##########
@@ -0,0 +1,45 @@
+// 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.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package task
+
+import (
+ "github.com/apache/beam/sdks/go/pkg/beam"
+)
+
+type Person struct {
+ Name, City, Country string
+}
+
+func ApplyTransform(s beam.Scope, personsKV beam.PCollection, citiesToCountries beam.PCollection) beam.PCollection {
+ citiesToCountriesView := beam.SideInput{
+ Input: citiesToCountries,
+ }
+ return beam.ParDo(s, joinFn, personsKV, citiesToCountriesView)
+}
+
+func joinFn(person Person, citiesToCountriesIter func(*string, *string) bool, emit func(Person)) {
+ var city, country string
+ for citiesToCountriesIter(&city, &country) {
Review comment:
This is the only Side Input iterating KV API in the Go SDK at present.
While [generics in Go are making progress](https://blog.golang.org/generics-next-step) it's not something we can use at this time. Maybe late next year, we'll be able to add a beam.KV type.
Further, sideinputs are not guaranteed grouped or ordered in any way, so we'd be getting pairs in one form or another regardless.
----------------------------------------------------------------
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] [beam] lostluck commented on a change in pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
lostluck commented on a change in pull request #12024:
URL: https://github.com/apache/beam/pull/12024#discussion_r442603782
##########
File path: learning/katas/go/Core Transforms/Side Input/Side Input/pkg/task/task.go
##########
@@ -0,0 +1,45 @@
+// 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.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package task
+
+import (
+ "github.com/apache/beam/sdks/go/pkg/beam"
+)
+
+type Person struct {
+ Name, City, Country string
+}
+
+func ApplyTransform(s beam.Scope, personsKV beam.PCollection, citiesToCountries beam.PCollection) beam.PCollection {
+ citiesToCountriesView := beam.SideInput{
+ Input: citiesToCountries,
+ }
+ return beam.ParDo(s, joinFn, personsKV, citiesToCountriesView)
+}
+
+func joinFn(person Person, citiesToCountriesIter func(*string, *string) bool, emit func(Person)) {
+ var city, country string
+ for citiesToCountriesIter(&city, &country) {
Review comment:
Good question!
No.
It's a valid way to iterate through KV PCollections as Side inputs. Eg. You know your set of KVs is short, but dynamic, and you'll need all of them at random while processing a DoFn.
Ideally we also have an alternate Map/Get style random access to KV side inputs as well, but it would be in addition to the existing way.
With generics for Go taking their [next steps](https://blog.golang.org/generics-next-step), maybe next year we could bolster the iteration API with any official Iteration format, in addition to the current methods.
Edit: There's also the ordinary PCollection<V> approach, which wouldn't be KVs, which would also work.
----------------------------------------------------------------
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] [beam] damondouglas commented on a change in pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
damondouglas commented on a change in pull request #12024:
URL: https://github.com/apache/beam/pull/12024#discussion_r441763172
##########
File path: learning/katas/go/Core Transforms/Side Input/Side Input/pkg/task/task.go
##########
@@ -0,0 +1,45 @@
+// 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.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package task
+
+import (
+ "github.com/apache/beam/sdks/go/pkg/beam"
+)
+
+type Person struct {
+ Name, City, Country string
+}
+
+func ApplyTransform(s beam.Scope, personsKV beam.PCollection, citiesToCountries beam.PCollection) beam.PCollection {
+ citiesToCountriesView := beam.SideInput{
+ Input: citiesToCountries,
+ }
+ return beam.ParDo(s, joinFn, personsKV, citiesToCountriesView)
+}
+
+func joinFn(person Person, citiesToCountriesIter func(*string, *string) bool, emit func(Person)) {
+ var city, country string
+ for citiesToCountriesIter(&city, &country) {
Review comment:
Is the state of Side Input iterating of KV in the Go SDK currently preventing this kata from being helpful? Should we hold off on a Side Input lesson at this time or change the example to a singleton Side Input like what is done in the documentation?
----------------------------------------------------------------
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] [beam] henryken commented on a change in pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
henryken commented on a change in pull request #12024:
URL: https://github.com/apache/beam/pull/12024#discussion_r442628172
##########
File path: learning/katas/go/Core Transforms/Side Input/Side Input/pkg/task/task.go
##########
@@ -0,0 +1,45 @@
+// 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.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package task
+
+import (
+ "github.com/apache/beam/sdks/go/pkg/beam"
+)
+
+type Person struct {
+ Name, City, Country string
+}
+
+func ApplyTransform(s beam.Scope, personsKV beam.PCollection, citiesToCountries beam.PCollection) beam.PCollection {
+ citiesToCountriesView := beam.SideInput{
+ Input: citiesToCountries,
+ }
+ return beam.ParDo(s, joinFn, personsKV, citiesToCountriesView)
+}
+
+func joinFn(person Person, citiesToCountriesIter func(*string, *string) bool, emit func(Person)) {
+ var city, country string
+ for citiesToCountriesIter(&city, &country) {
Review comment:
Thanks for the explanation @lostluck.
I think we can keep it as it is.
----------------------------------------------------------------
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] [beam] henryken commented on a change in pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
henryken commented on a change in pull request #12024:
URL: https://github.com/apache/beam/pull/12024#discussion_r441564315
##########
File path: learning/katas/go/Core Transforms/Side Input/Side Input/task.md
##########
@@ -0,0 +1,68 @@
+<!--
+ 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. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+# Side Input
+
+In addition to the main input PCollection, you can provide additional inputs to a ParDo transform
+in the form of side inputs. A side input is an additional input that your DoFn can access each time
+it processes an element in the input PCollection. When you specify a side input, you create a view
+of some other data that can be read from within the ParDo transform’s DoFn while processing each
+element.
+
+Side inputs are useful if your ParDo needs to inject additional data when processing each element
+in the input PCollection, but the additional data needs to be determined at runtime (and not
+hard-coded). Such values might be determined by the input data, or depend on a different branch of
+your pipeline.
+
+**Kata:** Please enrich each Person with the country based on the city he/she lives in.
+
+<div class="hint">
+ Use <a href="https://godoc.org/github.com/apache/beam/sdks/go/pkg/beam#hdr-Side_Inputs">
+ beam.SideInput</a> to create a side input of the citiesToCountries PCollection
+</div>
+
+<div class="hint">
+ Use <a href="https://godoc.org/github.com/apache/beam/sdks/go/pkg/beam#ParDo">
+ beam.ParDo</a> with a DoFn that accepts a
+ <a href="https://godoc.org/github.com/apache/beam/sdks/go/pkg/beam#hdr-Side_Inputs">
+ beam.SideInput</a>.
+</div>
+
+<div class="hint">
+ Refer to the Beam Programming Guide
+ <a href="https://beam.apache.org/documentation/programming-guide/#side-inputs">"Side inputs"</a>
+ section for more information.
+</div>
+
+<div class="hint">
+ A ParDo that has a PCollection KV as side input expects a DoFn that looks like the following.
+
+ ```
Review comment:
This code snippet needs to have no indentation to render properly.
##########
File path: learning/katas/go/Core Transforms/Side Input/Side Input/pkg/task/task.go
##########
@@ -0,0 +1,45 @@
+// 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.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package task
+
+import (
+ "github.com/apache/beam/sdks/go/pkg/beam"
+)
+
+type Person struct {
+ Name, City, Country string
+}
+
+func ApplyTransform(s beam.Scope, personsKV beam.PCollection, citiesToCountries beam.PCollection) beam.PCollection {
+ citiesToCountriesView := beam.SideInput{
+ Input: citiesToCountries,
+ }
+ return beam.ParDo(s, joinFn, personsKV, citiesToCountriesView)
+}
+
+func joinFn(person Person, citiesToCountriesIter func(*string, *string) bool, emit func(Person)) {
+ var city, country string
+ for citiesToCountriesIter(&city, &country) {
Review comment:
Is there a way to use a KV-like API (e.g. get(key)) instead of iterating each of the KV pair?
The way this works seems like a List collection with a tuple.
Or probably the naming KV is misleading?
##########
File path: learning/katas/go/Core Transforms/Side Input/Side Input/pkg/task/task.go
##########
@@ -0,0 +1,45 @@
+// 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.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package task
+
+import (
+ "github.com/apache/beam/sdks/go/pkg/beam"
+)
+
+type Person struct {
+ Name, City, Country string
+}
+
+func ApplyTransform(s beam.Scope, personsKV beam.PCollection, citiesToCountries beam.PCollection) beam.PCollection {
+ citiesToCountriesView := beam.SideInput{
+ Input: citiesToCountries,
+ }
+ return beam.ParDo(s, joinFn, personsKV, citiesToCountriesView)
+}
+
+func joinFn(person Person, citiesToCountriesIter func(*string, *string) bool, emit func(Person)) {
+ var city, country string
+ for citiesToCountriesIter(&city, &country) {
+ if person.City == city {
+ emit(Person{
+ Name: person.Name,
+ City: city,
+ Country: country,
+ })
Review comment:
Add `break` statement here?
----------------------------------------------------------------
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] [beam] henryken commented on pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
henryken commented on pull request #12024:
URL: https://github.com/apache/beam/pull/12024#issuecomment-645396735
Btw, why do we have many go.mod/sum changes?
----------------------------------------------------------------
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] [beam] lostluck commented on a change in pull request #12024: [BEAM-9679] Add Side Input to Core Transform Go SDK katas
Posted by GitBox <gi...@apache.org>.
lostluck commented on a change in pull request #12024:
URL: https://github.com/apache/beam/pull/12024#discussion_r442603782
##########
File path: learning/katas/go/Core Transforms/Side Input/Side Input/pkg/task/task.go
##########
@@ -0,0 +1,45 @@
+// 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.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package task
+
+import (
+ "github.com/apache/beam/sdks/go/pkg/beam"
+)
+
+type Person struct {
+ Name, City, Country string
+}
+
+func ApplyTransform(s beam.Scope, personsKV beam.PCollection, citiesToCountries beam.PCollection) beam.PCollection {
+ citiesToCountriesView := beam.SideInput{
+ Input: citiesToCountries,
+ }
+ return beam.ParDo(s, joinFn, personsKV, citiesToCountriesView)
+}
+
+func joinFn(person Person, citiesToCountriesIter func(*string, *string) bool, emit func(Person)) {
+ var city, country string
+ for citiesToCountriesIter(&city, &country) {
Review comment:
Good question!
No.
It's a valid way to iterate through KV PCollections as Side inputs. Eg. You know your set of KVs is short, but dynamic, and you'll need all of them at random while processing a DoFn.
Ideally we also have an alternate Map/Get style random access to KV side inputs as well, but it would be in addition to the existing way.
With generics for Go taking their [next steps](https://blog.golang.org/generics-next-step), maybe next year we could bolster the iteration API with any official Iteration format, in addition to the current methods.
----------------------------------------------------------------
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