Skip to content

Commit

Permalink
Fix playground examples (#31647)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amar3tto authored Jun 19, 2024
1 parent 0cce58f commit 561bf2f
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
# - group
# - strings

# [START groupbykey]
import apache_beam as beam
def groupbykey():
# [START groupbykey]
import apache_beam as beam

with beam.Pipeline() as p:
with beam.Pipeline() as p:

(p | beam.Create(['apple', 'ball', 'car', 'bear', 'cheetah', 'ant'])
| beam.Map(lambda word: (word[0], word))
| beam.GroupByKey()
| beam.LogElements())
# [END groupbykey]
(p | beam.Create(['apple', 'ball', 'car', 'bear', 'cheetah', 'ant'])
| beam.Map(lambda word: (word[0], word))
| beam.GroupByKey()
| beam.LogElements())
# [END groupbykey]

if __name__ == '__main__':
groupbykey()
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# pylint:disable=line-too-long

# beam-playground:
# name: AppromximateQuantiles
# name: ApproximateQuantiles
# description: Demonstration of ApproximateQuantiles transform usage.
# multifile: false
# default_example: false
Expand All @@ -34,7 +34,7 @@


def approximatequantiles(test=None):
# [START quantiles]
# [START approximatequantiles]
import apache_beam as beam

with beam.Pipeline() as pipeline:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# pylint:disable=line-too-long

# beam-playground:
# name: AppromximateUnique
# name: ApproximateUnique
# description: Demonstration of ApproximateUnique transform usage.
# multifile: false
# default_example: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.

{{< localstorage language language-py >}}

{{< button-pydoc path="apache_beam.transforms.stat" class="ApproximateQuantile" >}}
{{< button-pydoc path="apache_beam.transforms.stats" class="ApproximateQuantiles" >}}

## Examples

Expand All @@ -28,3 +28,7 @@ limitations under the License.
{{< /playground >}}

## Related transforms

N/A

{{< button-pydoc path="apache_beam.transforms.stats" class="ApproximateQuantiles" >}}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ 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.
-->

# ApproximateUnique

{{< localstorage language language-py >}}

{{< button-pydoc path="apache_beam.transforms.stat" class="ApproximateUnique" >}}
{{< button-pydoc path="apache_beam.transforms.stats" class="ApproximateUnique" >}}

## Examples

Expand All @@ -27,3 +28,7 @@ limitations under the License.
{{< /playground >}}

## Related transforms

N/A

{{< button-pydoc path="apache_beam.transforms.stats" class="ApproximateUnique" >}}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.

{{< localstorage language language-py >}}

{{< button-pydoc path="apache_beam.transforms.stat" class="BatchElements" >}}
{{< button-pydoc path="apache_beam.transforms.util" class="BatchElements" >}}

## Examples

Expand All @@ -28,4 +28,7 @@ limitations under the License.
{{< /playground >}}

## Related transforms

* [GroupIntoBatches](/documentation/transforms/python/aggregation/groupintobatches) batches elements by key

{{< button-pydoc path="apache_beam.transforms.util" class="BatchElements" >}}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ We use `Count.PerKey()` to count the elements for each unique key in a `PCollect

### Example 3: Counting all unique elements

We use `Count.PerElement()` to count the only the unique elements in a `PCollection`.
We use `Count.PerElement()` to count only the unique elements in a `PCollection`.

{{< playground height="700px" >}}
{{< playground_snippet language="py" path="SDK_PYTHON_CountPerElement" show="count_per_element" >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ See more information in the [Beam Programming Guide](/documentation/programming-
We use `GroupByKey` to group all the produce for each season.

{{< playground height="700px" >}}
{{< playground_snippet language="py" path="SDK_PYTHON_GroupByKey" show="groupbykeysort" >}}
{{< playground_snippet language="py" path="SDK_PYTHON_GroupByKeySort" show="groupbykey" >}}
{{< /playground >}}

**Example 2**:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "BatchElements"
title: "ToList"
---
<!--
Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
-->

# BatchElements
# ToList

{{< localstorage language language-py >}}

Expand All @@ -26,3 +26,9 @@ limitations under the License.
{{< playground height="700px" >}}
{{< playground_snippet language="py" path="SDK_PYTHON_ToList" show="tolist" >}}
{{< /playground >}}

## Related transforms

N/A

{{< button-pydoc path="apache_beam.transforms.combiners" class="ToList" >}}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ limitations under the License.
<tr><th>Transform</th><th>Description</th></tr>
<tr><td><a href="/documentation/transforms/python/aggregation/approximatequantiles">ApproximateQuantiles</a></td><td>Given a distribution, find the approximate N-tiles.</td></tr>
<tr><td><a href="/documentation/transforms/python/aggregation/approximateunique">ApproximateUnique</a></td><td>Given a pcollection, return the estimated number of unique elements.</td></tr>
<tr><td><a href="/documentation/transforms/python/aggregation/batchelements">BatchElements</a></td><td>Given a pcollection, return the estimated number of unique elements.</td></tr>
<tr><td><a href="/documentation/transforms/python/aggregation/batchelements">BatchElements</a></td><td>Transform that batches elements for amortized processing.</td></tr>
<tr><td><a href="/documentation/transforms/python/aggregation/cogroupbykey">CoGroupByKey</a></td><td>Takes several keyed collections of elements and produces a collection where each element consists of a key and all values associated with that key.</td></tr>
<tr><td><a href="/documentation/transforms/python/aggregation/combineglobally">CombineGlobally</a></td><td>Transforms to combine elements.</td></tr>
<tr><td><a href="/documentation/transforms/python/aggregation/combineperkey">CombinePerKey</a></td><td>Transforms to combine elements for each key.</td></tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
<ul class="section-nav-list">
<li><a href="/documentation/transforms/python/aggregation/approximatequantiles/">ApproximateQuantiles</a></li>
<li><a href="/documentation/transforms/python/aggregation/approximateunique/">ApproximateUnique</a></li>
<li><a href="/documentation/transforms/python/aggregation/batchelements/">BatchElements</a></li>
<li><a href="/documentation/transforms/python/aggregation/cogroupbykey/">CoGroupByKey</a></li>
<li><a href="/documentation/transforms/python/aggregation/combineglobally/">CombineGlobally</a></li>
<li><a href="/documentation/transforms/python/aggregation/combineperkey/">CombinePerKey</a></li>
Expand Down

0 comments on commit 561bf2f

Please sign in to comment.