nehsyc commented on a change in pull request #13069:
URL: https://github.com/apache/beam/pull/13069#discussion_r504885576



##########
File path: sdks/python/apache_beam/coders/coder_impl.py
##########
@@ -1365,3 +1366,38 @@ def estimate_size(self, value, nested=False):
     # type: (Any, bool) -> int
     value_size = self._value_coder.estimate_size(value)
     return get_varint_size(value_size) + value_size
+
+
+class ShardedKeyCoderImpl(StreamCoderImpl):
+  """For internal use only; no backwards-compatibility guarantees.
+
+  A coder for sharded user keys.
+
+  The encoding and decoding should follow the order:
+      length of shard id byte string
+      shard id byte string
+      encoded user key
+  """
+  def __init__(self, key_coder_impl):
+    self._shard_id_coder_impl = LengthPrefixCoderImpl(BytesCoderImpl())

Review comment:
       I see. It requires a nested context which is always true for shard id. 
The `StreamCoderImpl` that the `ShardedKeyImpl` inherits seems to always use an 
[unnested](https://github.com/apache/beam/blob/master/sdks/python/apache_beam/coders/coder_impl.py#L222)
 context so the encoded key won't have a length prefix if it is a string or 
bytes. Should I make the `ShardedKeyImpl` inherit `CoderImpl` directly to allow 
different encoding for different context? Also I am confused by the Java 
documentation for [encoding/decoding 
context](https://github.com/apache/beam/blob/master/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java#L130)
 in Coder - seems like it's preferred to have a default context, either nested 
or unnested but not both.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to