You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by jr...@apache.org on 2022/06/22 14:14:19 UTC
[beam] branch master updated: [Go SDK] Adds a snippet for GBK in BPG (#21842)
This is an automated email from the ASF dual-hosted git repository.
jrmccluskey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new adac54e1fa4 [Go SDK] Adds a snippet for GBK in BPG (#21842)
adac54e1fa4 is described below
commit adac54e1fa4f8f5915b47b16fa7b343b29304c07
Author: Ritesh Ghorse <ri...@gmail.com>
AuthorDate: Wed Jun 22 10:14:13 2022 -0400
[Go SDK] Adds a snippet for GBK in BPG (#21842)
* add gbk snippet for Go
* changed doc
---
sdks/go/examples/snippets/04transforms.go | 10 ++++++++++
website/www/site/content/en/documentation/programming-guide.md | 4 ++++
2 files changed, 14 insertions(+)
diff --git a/sdks/go/examples/snippets/04transforms.go b/sdks/go/examples/snippets/04transforms.go
index 2c1b59c9ad5..0713fa7a9d6 100644
--- a/sdks/go/examples/snippets/04transforms.go
+++ b/sdks/go/examples/snippets/04transforms.go
@@ -67,6 +67,16 @@ func applyWordLenAnon(s beam.Scope, words beam.PCollection) beam.PCollection {
return wordLengths
}
+func applyGbk(s beam.Scope, input []stringPair) beam.PCollection {
+ // [START groupbykey]
+ // CreateAndSplit creates and returns a PCollection with <K,V>
+ // from an input slice of stringPair (struct with K, V string fields).
+ pairs := CreateAndSplit(s, input)
+ keyed := beam.GroupByKey(s, pairs)
+ // [END groupbykey]
+ return keyed
+}
+
// [START cogroupbykey_input_helpers]
type stringPair struct {
diff --git a/website/www/site/content/en/documentation/programming-guide.md b/website/www/site/content/en/documentation/programming-guide.md
index 680d91bdae5..6ab82ea1d2e 100644
--- a/website/www/site/content/en/documentation/programming-guide.md
+++ b/website/www/site/content/en/documentation/programming-guide.md
@@ -1112,6 +1112,10 @@ PCollection<KV<String, Iterable<String>>> reduced =
mapped.apply(GroupByKey.<String, String>create());
{{< /highlight >}}
+{{< highlight go >}}
+{{< code_sample "sdks/go/examples/snippets/04transforms.go" groupbykey >}}
+{{< /highlight >}}
+
##### 4.2.2.1 GroupByKey and unbounded PCollections {#groupbykey-and-unbounded-pcollections}
If you are using unbounded `PCollection`s, you must use either [non-global