beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From al...@apache.org
Subject [beam] branch master updated: [BEAM-7390] Add sum code snippets
Date Fri, 07 Aug 2020 00:36:18 GMT
This is an automated email from the ASF dual-hosted git repository.

altay 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 0b6af20  [BEAM-7390] Add sum code snippets
     new a46fbb8  Merge pull request #12472 from davidcavazos/sum-docs
0b6af20 is described below

commit 0b6af207dbdc54ff2e570f16ba04cef44a23d7e0
Author: David Cavazos <dcavazos@google.com>
AuthorDate: Wed Aug 5 10:20:08 2020 -0700

    [BEAM-7390] Add sum code snippets
---
 .../transforms/python/aggregation/sum.md           | 58 +++++++++++++++++++++-
 .../en/documentation/transforms/python/overview.md |  2 +-
 .../partials/section-menu/en/documentation.html    |  1 +
 3 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/website/www/site/content/en/documentation/transforms/python/aggregation/sum.md
b/website/www/site/content/en/documentation/transforms/python/aggregation/sum.md
index 8d49f5b..a9aef38 100644
--- a/website/www/site/content/en/documentation/transforms/python/aggregation/sum.md
+++ b/website/www/site/content/en/documentation/transforms/python/aggregation/sum.md
@@ -17,7 +17,61 @@ limitations under the License.
 
 # Sum
 
+{{< localstorage language language-py >}}
+
+{{< button-pydoc path="apache_beam.transforms.core" class="CombineGlobally" >}}
+
+Sums all the elements within each aggregation.
+
 ## Examples
-See [BEAM-7390](https://issues.apache.org/jira/browse/BEAM-7390) for updates. 
 
-## Related transforms
\ No newline at end of file
+In the following example, we create a pipeline with a `PCollection`.
+Then, we get the sum of all the element values in different ways.
+
+### Example 1: Sum of the elements in a PCollection
+
+We use `Combine.Globally()` to get sum of all the element values from the *entire* `PCollection`.
+
+{{< highlight py >}}
+{{< code_sample "sdks/python/apache_beam/examples/snippets/transforms/aggregation/sum.py"
sum_globally >}}
+{{< /highlight >}}
+
+{{< paragraph class="notebook-skip" >}}
+Output:
+{{< /paragraph >}}
+
+{{< highlight class="notebook-skip" >}}
+{{< code_sample "sdks/python/apache_beam/examples/snippets/transforms/aggregation/sum_test.py"
total >}}
+{{< /highlight >}}
+
+{{< buttons-code-snippet
+  py="sdks/python/apache_beam/examples/snippets/transforms/aggregation/sum.py" >}}
+
+### Example 2: Sum of the elements for each key
+
+We use `Combine.PerKey()` to get the sum of all the element values for each unique key in
a `PCollection` of key-values.
+
+{{< highlight py >}}
+{{< code_sample "sdks/python/apache_beam/examples/snippets/transforms/aggregation/sum.py"
sum_per_key >}}
+{{< /highlight >}}
+
+{{< paragraph class="notebook-skip" >}}
+Output:
+{{< /paragraph >}}
+
+{{< highlight class="notebook-skip" >}}
+{{< code_sample "sdks/python/apache_beam/examples/snippets/transforms/aggregation/sum_test.py"
totals_per_key >}}
+{{< /highlight >}}
+
+{{< buttons-code-snippet
+  py="sdks/python/apache_beam/examples/snippets/transforms/aggregation/sum.py" >}}
+
+## Related transforms
+
+* [CombineGlobally](/documentation/transforms/python/aggregation/combineglobally)
+* [CombinePerKey](/documentation/transforms/python/aggregation/combineperkey)
+* [Max](/documentation/transforms/python/aggregation/max)
+* [Mean](/documentation/transforms/python/aggregation/mean)
+* [Min](/documentation/transforms/python/aggregation/min)
+
+{{< button-pydoc path="apache_beam.transforms.core" class="CombineGlobally" >}}
diff --git a/website/www/site/content/en/documentation/transforms/python/overview.md b/website/www/site/content/en/documentation/transforms/python/overview.md
index d648ac7..059abcb 100644
--- a/website/www/site/content/en/documentation/transforms/python/overview.md
+++ b/website/www/site/content/en/documentation/transforms/python/overview.md
@@ -60,7 +60,7 @@ limitations under the License.
   <tr><td><a href="/documentation/transforms/python/aggregation/mean">Mean</a></td><td>Computes
the average within each aggregation.</td></tr>
   <tr><td><a href="/documentation/transforms/python/aggregation/min">Min</a></td><td>Gets
the element with the minimum value within each aggregation.</td></tr>
   <tr><td><a href="/documentation/transforms/python/aggregation/sample">Sample</a></td><td>Randomly
select some number of elements from each aggregation.</td></tr>
-  <tr><td>Sum</td><td>Not available.</td></tr>
+  <tr><td><a href="/documentation/transforms/python/aggregation/sum">Sum</a></td><td>Sums
all the elements within each aggregation.</td></tr>
   <tr><td><a href="/documentation/transforms/python/aggregation/top">Top</a></td><td>Compute
the largest element(s) in each aggregation.</td></tr>
 </table>
 
diff --git a/website/www/site/layouts/partials/section-menu/en/documentation.html b/website/www/site/layouts/partials/section-menu/en/documentation.html
index c8d0da9..f5ca3b8 100644
--- a/website/www/site/layouts/partials/section-menu/en/documentation.html
+++ b/website/www/site/layouts/partials/section-menu/en/documentation.html
@@ -204,6 +204,7 @@
           <li><a href="/documentation/transforms/python/aggregation/mean/">Mean</a></li>
           <li><a href="/documentation/transforms/python/aggregation/min/">Min</a></li>
           <li><a href="/documentation/transforms/python/aggregation/sample/">Sample</a></li>
+          <li><a href="/documentation/transforms/python/aggregation/sum/">Sum</a></li>
           <li><a href="/documentation/transforms/python/aggregation/top/">Top</a></li>
         </ul>
       </li>


Mime
View raw message