AlikRodriguez commented on a change in pull request #15410:
URL: https://github.com/apache/beam/pull/15410#discussion_r770161564



##########
File path: sdks/python/apache_beam/coders/row_coder_test.py
##########
@@ -282,6 +284,61 @@ def test_row_coder_nested_struct(self):
 
     self.assertEqual(value, coder.decode(coder.encode(value)))
 
+  def test_encoding_position_reorder_fields(self):
+    fields = [("field1", str), ("field2", int), ("field3", int)]
+
+    expected = typing.NamedTuple('expected', fields)
+    reorder = schema_pb2.Schema(
+        id="new_order",
+        fields=[
+            schema_pb2.Field(
+                name="field3",
+                type=schema_pb2.FieldType(atomic_type=schema_pb2.STRING),
+                encoding_position=2),
+            schema_pb2.Field(
+                name="field2",
+                type=schema_pb2.FieldType(atomic_type=schema_pb2.INT32),
+                encoding_position=1),
+            schema_pb2.Field(
+                name="field1",
+                type=schema_pb2.FieldType(atomic_type=schema_pb2.INT32),
+                encoding_position=0)
+        ])
+
+    old_coder = RowCoder.from_type_hint(expected, None)
+    new_coder = RowCoder(reorder)
+
+    encode_expected = old_coder.encode(expected("foo", 7, 12))
+    encode_reorder = new_coder.encode(expected(12, 7, "foo"))
+    self.assertEqual(encode_expected, encode_reorder)
+
+  def test_encoding_position_add_fields(self):
+    fields = [("field1", str), ("field2", str)]
+
+    Old = typing.NamedTuple("Old", fields[:-1])
+    New = typing.NamedTuple("New", fields)
+
+    old_coder = RowCoder.from_type_hint(Old, None)
+    new_coder = RowCoder.from_type_hint(New, None)
+
+    self.assertEqual(
+        New("bar", None), new_coder.decode(old_coder.encode(Old("bar"))))
+
+  def test_encoding_position_add_fields_and_reorder(self):
+    fields = [("field1", typing.Optional[str]), ("field2", str),
+              ("field3", typing.Optional[str])]
+
+    Old = typing.NamedTuple("Old", fields[:-1])
+    New = typing.NamedTuple("New", fields[::1])

Review comment:
       Yes, sorry, changed making some test before, but is fixed now.




-- 
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.

To unsubscribe, e-mail: [email protected]

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


Reply via email to