[
https://issues.apache.org/jira/browse/BEAM-5427?focusedWorklogId=145837&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-145837
]
ASF GitHub Bot logged work on BEAM-5427:
----------------------------------------
Author: ASF GitHub Bot
Created on: 19/Sep/18 22:16
Start Date: 19/Sep/18 22:16
Worklog Time Spent: 10m
Work Description: HuangLED closed pull request #6432: [BEAM-5427] Fix and
update AverageFn sample code.
URL: https://github.com/apache/beam/pull/6432
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Combine.java
b/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Combine.java
index 2c65f94d09a..f9d68adfe95 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Combine.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Combine.java
@@ -254,10 +254,26 @@ private Combine() {
*
* <pre>{@code
* public class AverageFn extends CombineFn<Integer, AverageFn.Accum,
Double> {
- * public static class Accum {
+ * public static class Accum implements java.io.Serializable {
* int sum = 0;
* int count = 0;
+ *
+ * @Override
+ * public boolean equals(Object other) {
+ * if (other == null) return false;
+ * if (other == this) return true;
+ * if (!(other instanceof Accum))return false;
+ *
+ *
+ * Accum o = (Accum)other;
+ * if (this.sum != o.sum || this.count != o.count) {
+ * return false;
+ * } else {
+ * return true;
+ * }
+ * }
* }
+ *
* public Accum createAccumulator() {
* return new Accum();
* }
@@ -289,6 +305,22 @@ private Combine() {
* arbitrary tree structure. Commutativity is required because any order of
the input values is
* ignored when breaking up input values into groups.
*
+ * <h3>Note on Data Encoding</h3>
+ *
+ * <p>Data encoding is required to make CombineFn work.
+ * The sample code above implements {@code java.io.Serializable} so that
CombineFn in
+ * consequence makes use of SerializableCoder to encode the data.
+ * In many cases though, relying on Serializable could be
+ * less preferred for efficiency considerations. In addition, Serializable
may not be applicable
+ * in all situations. There are two alternatives to make data encoding work
for AverageFn:
+ *
+ * <ul>
+ * <li> Generic Coder class. Implement an encoder class explicitly and use
{@code @DefaultCoder} tag.
+ * <li> {@link CombineFn} Specific way. While extending {@link CombineFn},
overwrite
+ * both {@link #getAccumulatorCoder}
+ * and {@link #getDefaultOutputCoder}.
+ * </ul>
+ *
* @param <InputT> type of input values
* @param <AccumT> type of mutable accumulator values
* @param <OutputT> type of output values
diff --git a/website/src/contribute/index.md b/website/src/contribute/index.md
index eb38ccce7dd..fd8db873d83 100644
--- a/website/src/contribute/index.md
+++ b/website/src/contribute/index.md
@@ -66,7 +66,7 @@ Coding happens at
[https://github.com/apache/beam](https://github.com/apache/beam). To
contribute, follow the usual GitHub process: fork the repo, make your changes,
and open a pull request and @mention a reviewer. If you have more than one
commit
-in your change, you many be asked to rebase and squash the commits.
+in your change, you may be asked to rebase and squash the commits.
If you are unfamiliar with this workflow, GitHub maintains these helpful
guides:
- [Git Handbook](https://guides.github.com/introduction/git-handbook/)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 145837)
Time Spent: 10m
Remaining Estimate: 0h
> Fix sample code (AverageFn) in Combine.java
> -------------------------------------------
>
> Key: BEAM-5427
> URL: https://issues.apache.org/jira/browse/BEAM-5427
> Project: Beam
> Issue Type: Improvement
> Components: examples-java
> Reporter: Ruoyun Huang
> Assignee: Reuven Lax
> Priority: Minor
> Time Spent: 10m
> Remaining Estimate: 0h
>
> Sample code missing coder.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)