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 c551a8c  [BEAM-7390] Add sample code snippets
     new 5ded4ae  Merge pull request #12462 from davidcavazos/sample-docs
c551a8c is described below

commit c551a8cfb175acb990a8bbcf3fae81ce15bd4198
Author: David Cavazos <[email protected]>
AuthorDate: Tue Aug 4 08:59:43 2020 -0700

    [BEAM-7390] Add sample code snippets
---
 .../transforms/python/aggregation/sample.md        | 64 +++++++++++++++++-----
 1 file changed, 51 insertions(+), 13 deletions(-)

diff --git 
a/website/www/site/content/en/documentation/transforms/python/aggregation/sample.md
 
b/website/www/site/content/en/documentation/transforms/python/aggregation/sample.md
index 7d10eb0..33fc8f6 100644
--- 
a/website/www/site/content/en/documentation/transforms/python/aggregation/sample.md
+++ 
b/website/www/site/content/en/documentation/transforms/python/aggregation/sample.md
@@ -14,24 +14,62 @@ 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.
 -->
+
 # Sample
-<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.Sample";>
-      <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="Sample" >}}
 
 Transforms for taking samples of the elements in a collection, or
-samples of the values associated with each key in a collection of 
+samples of the values associated with each key in a collection of
 key-value pairs.
 
 ## Examples
-See [BEAM-7390](https://issues.apache.org/jira/browse/BEAM-7390) for updates. 
 
-## Related transforms 
-* [Top](/documentation/transforms/python/aggregation/top) finds the largest or 
smallest element.
\ No newline at end of file
+In the following example, we create a pipeline with a `PCollection`.
+Then, we get a random sample of elements in different ways.
+
+### Example 1: Sample elements from a PCollection
+
+We use `Sample.FixedSizeGlobally()` to get a fixed-size random sample of 
elements from the *entire* `PCollection`.
+
+{{< highlight py >}}
+{{< code_sample 
"sdks/python/apache_beam/examples/snippets/transforms/aggregation/sample.py" 
sample_fixed_size_globally >}}
+{{< /highlight >}}
+
+{{< paragraph class="notebook-skip" >}}
+Output:
+{{< /paragraph >}}
+
+{{< highlight class="notebook-skip" >}}
+{{< code_sample 
"sdks/python/apache_beam/examples/snippets/transforms/aggregation/sample_test.py"
 sample >}}
+{{< /highlight >}}
+
+{{< buttons-code-snippet
+  
py="sdks/python/apache_beam/examples/snippets/transforms/aggregation/sample.py" 
>}}
+
+### Example 2: Sample elements for each key
+
+We use `Sample.FixedSizePerKey()` to get fixed-size random samples for each 
unique key in a `PCollection` of key-values.
+
+{{< highlight py >}}
+{{< code_sample 
"sdks/python/apache_beam/examples/snippets/transforms/aggregation/sample.py" 
sample_fixed_size_per_key >}}
+{{< /highlight >}}
+
+{{< paragraph class="notebook-skip" >}}
+Output:
+{{< /paragraph >}}
+
+{{< highlight class="notebook-skip" >}}
+{{< code_sample 
"sdks/python/apache_beam/examples/snippets/transforms/aggregation/sample_test.py"
 samples_per_key >}}
+{{< /highlight >}}
+
+{{< buttons-code-snippet
+  
py="sdks/python/apache_beam/examples/snippets/transforms/aggregation/sample.py" 
>}}
+
+## Related transforms
+
+* [Top](/documentation/transforms/python/aggregation/top) finds the largest or 
smallest element.
+
+{{< button-pydoc path="apache_beam.transforms.combiners" class="Sample" >}}

Reply via email to