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 count code snippets
Date Mon, 20 Jul 2020 23:40:29 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 5e766f0  [BEAM-7390] Add count code snippets
     new f36250f  Merge pull request #12321 from davidcavazos/count-docs
5e766f0 is described below

commit 5e766f0b91f01312cd512c236ba40a88d6e428ed
Author: David Cavazos <dcavazos@google.com>
AuthorDate: Mon Jul 20 12:27:58 2020 -0700

    [BEAM-7390] Add count code snippets
---
 .../transforms/python/aggregation/count.md         | 81 ++++++++++++++++++----
 1 file changed, 69 insertions(+), 12 deletions(-)

diff --git a/website/www/site/content/en/documentation/transforms/python/aggregation/count.md
b/website/www/site/content/en/documentation/transforms/python/aggregation/count.md
index 46ddebb..f4d332e 100644
--- a/website/www/site/content/en/documentation/transforms/python/aggregation/count.md
+++ b/website/www/site/content/en/documentation/transforms/python/aggregation/count.md
@@ -14,22 +14,79 @@ 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.
 -->
+
 # Count
-<table align="left">
-    <a target="_blank" class="button"
-        href="https://beam.apache.org/releases/pydoc/2.12.0/apache_beam.transforms.combiners.html?#apache_beam.transforms.combiners.Count">
-      <img src="https://beam.apache.org/images/logos/sdks/python.png" width="20px" height="20px"
-           alt="Pydoc" />
-     Pydoc
-    </a>
-</table>
-<br><br>
 
+{{< localstorage language language-py >}}
+
+{{< button-pydoc path="apache_beam.transforms.combiners" class="Count" >}}
 
 Counts the number of elements within each aggregation.
 
 ## Examples
-See [BEAM-7390](https://issues.apache.org/jira/browse/BEAM-7390) for updates. 
 
-## Related transforms 
-N/A
\ No newline at end of file
+In the following example, we create a pipeline with two `PCollection`s of produce.
+Then, we apply `Count` to get the total number of elements in different ways.
+
+### Example 1: Counting all elements in a PCollection
+
+We use `Count.Globally()` to count *all* elements in a `PCollection`, even if there are duplicate
elements.
+
+{{< highlight py >}}
+{{< code_sample "sdks/python/apache_beam/examples/snippets/transforms/aggregation/count.py"
count_globally >}}
+{{< /highlight >}}
+
+{{< paragraph class="notebook-skip" >}}
+Output:
+{{< /paragraph >}}
+
+{{< highlight class="notebook-skip" >}}
+{{< code_sample "sdks/python/apache_beam/examples/snippets/transforms/aggregation/count_test.py"
total_elements >}}
+{{< /highlight >}}
+
+{{< buttons-code-snippet
+  py="sdks/python/apache_beam/examples/snippets/transforms/aggregation/count.py" >}}
+
+### Example 2: Counting elements for each key
+
+We use `Count.PerKey()` to count the elements for each unique key in a `PCollection` of key-values.
+
+{{< highlight py >}}
+{{< code_sample "sdks/python/apache_beam/examples/snippets/transforms/aggregation/count.py"
count_per_key >}}
+{{< /highlight >}}
+
+{{< paragraph class="notebook-skip" >}}
+Output:
+{{< /paragraph >}}
+
+{{< highlight class="notebook-skip" >}}
+{{< code_sample "sdks/python/apache_beam/examples/snippets/transforms/aggregation/count_test.py"
total_elements_per_key >}}
+{{< /highlight >}}
+
+{{< buttons-code-snippet
+  py="sdks/python/apache_beam/examples/snippets/transforms/aggregation/count.py" >}}
+
+### Example 3: Counting all unique elements
+
+We use `Count.PerElement()` to count the only the unique elements in a `PCollection`.
+
+{{< highlight py >}}
+{{< code_sample "sdks/python/apache_beam/examples/snippets/transforms/aggregation/count.py"
count_per_element >}}
+{{< /highlight >}}
+
+{{< paragraph class="notebook-skip" >}}
+Output:
+{{< /paragraph >}}
+
+{{< highlight class="notebook-skip" >}}
+{{< code_sample "sdks/python/apache_beam/examples/snippets/transforms/aggregation/count_test.py"
total_unique_elements >}}
+{{< /highlight >}}
+
+{{< buttons-code-snippet
+  py="sdks/python/apache_beam/examples/snippets/transforms/aggregation/count.py" >}}
+
+## Related transforms
+
+N/A
+
+{{< button-pydoc path="apache_beam.transforms.combiners" class="Count" >}}


Mime
View raw message