You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by lc...@apache.org on 2017/05/09 17:47:16 UTC
[5/6] beam git commit: Remove context from size estimate operations.
Remove context from size estimate operations.
Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/9751f029
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/9751f029
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/9751f029
Branch: refs/heads/release-2.0.0
Commit: 9751f0295e2a9ff5fdd56acb0e1c67cd1bba7fde
Parents: 5763c38
Author: Robert Bradshaw <ro...@gmail.com>
Authored: Fri May 5 15:18:52 2017 -0700
Committer: Luke Cwik <lc...@google.com>
Committed: Tue May 9 10:46:22 2017 -0700
----------------------------------------------------------------------
.../java/org/apache/beam/sdk/coders/Coder.java | 52 ++++----------------
1 file changed, 10 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/beam/blob/9751f029/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java
index eeafbd2..d140e89 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java
@@ -301,40 +301,10 @@ public abstract class Coder<T> implements Serializable {
* unless it is overridden. This is considered expensive.
*/
public boolean isRegisterByteSizeObserverCheap(T value) {
- return isRegisterByteSizeObserverCheap(value, Context.NESTED);
- }
-
- /**
- * {@inheritDoc}
- *
- * <p>Not intended to be called by user code, but instead by
- * {@link PipelineRunner}
- * implementations.
- *
- * @return {@code false} unless it is overridden. {@link StructuredCoder#registerByteSizeObserver}
- * invokes {@link #getEncodedElementByteSize} which requires re-encoding an element
- * unless it is overridden. This is considered expensive.
- */
- @Deprecated
- public boolean isRegisterByteSizeObserverCheap(T value, Context context) {
return false;
}
/**
- * Returns the size in bytes of the encoded value using this coder.
- */
- protected long getEncodedElementByteSize(T value, Context context)
- throws Exception {
- try (CountingOutputStream os = new CountingOutputStream(ByteStreams.nullOutputStream())) {
- encode(value, os, context);
- return os.getCount();
- } catch (Exception exn) {
- throw new IllegalArgumentException(
- "Unable to encode element '" + value + "' with coder '" + this + "'.", exn);
- }
- }
-
- /**
* Notifies the {@code ElementByteSizeObserver} about the byte size
* of the encoded value using this {@code Coder}.
*
@@ -347,22 +317,20 @@ public abstract class Coder<T> implements Serializable {
*/
public void registerByteSizeObserver(T value, ElementByteSizeObserver observer)
throws Exception {
- registerByteSizeObserver(value, observer, Context.NESTED);
+ observer.update(getEncodedElementByteSize(value));
}
/**
- * Notifies the {@code ElementByteSizeObserver} about the byte size
- * of the encoded value using this {@code Coder}.
- *
- * <p>Not intended to be called by user code, but instead by
- * {@link PipelineRunner}
- * implementations.
+ * Returns the size in bytes of the encoded value using this coder.
*/
- @Deprecated
- public void registerByteSizeObserver(
- T value, ElementByteSizeObserver observer, Context context)
- throws Exception {
- observer.update(getEncodedElementByteSize(value, context));
+ protected long getEncodedElementByteSize(T value) throws Exception {
+ try (CountingOutputStream os = new CountingOutputStream(ByteStreams.nullOutputStream())) {
+ encode(value, os);
+ return os.getCount();
+ } catch (Exception exn) {
+ throw new IllegalArgumentException(
+ "Unable to encode element '" + value + "' with coder '" + this + "'.", exn);
+ }
}
/**