[ 
https://issues.apache.org/jira/browse/BEAM-13960?focusedWorklogId=732008&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-732008
 ]

ASF GitHub Bot logged work on BEAM-13960:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 23/Feb/22 23:57
            Start Date: 23/Feb/22 23:57
    Worklog Time Spent: 10m 
      Work Description: laraschmidt commented on a change in pull request 
#16875:
URL: https://github.com/apache/beam/pull/16875#discussion_r813432339



##########
File path: 
sdks/java/core/src/test/java/org/apache/beam/sdk/schemas/SchemaTranslationTest.java
##########
@@ -290,6 +297,74 @@ public void fromProtoAndToProto() throws Exception {
     }
   }
 
+  /** Tests round-trip proto encodings for {@link Row}. */
+  @RunWith(Parameterized.class)
+  public static class RowToFromProtoTest {
+
+    public static Row simpleRow(FieldType type, Object value) {
+      return Row.withSchema(Schema.of(Field.of("s", 
type))).addValue(value).build();
+    }
+
+    public static Row simpleNullRow(FieldType type) {
+      return Row.withSchema(Schema.of(Field.nullable("s", 
type))).addValue(null).build();
+    }
+
+    @Parameters(name = "{index}: {0}")
+    public static Iterable<Row> data() {
+      Map<String, Integer> map = new HashMap<>();
+      map.put("string", 42);
+      List<String> list = new ArrayList<>();
+      list.add("string");
+      Schema schema =
+          Schema.builder()
+              .addField("field_one", FieldType.STRING)
+              .addField("field_two", FieldType.INT32)
+              .build();
+      Row row = Row.withSchema(schema).addValue("value").addValue(42).build();
+
+      return ImmutableList.<Row>builder()
+          .add(simpleRow(FieldType.STRING, "string"))
+          .add(simpleRow(FieldType.BOOLEAN, true))
+          .add(simpleRow(FieldType.BYTE, (byte) 12))
+          .add(simpleRow(FieldType.INT16, (short) 12))
+          .add(simpleRow(FieldType.INT32, 12))
+          .add(simpleRow(FieldType.INT64, 12L))
+          .add(simpleRow(FieldType.BYTES, new byte[] {0x42, 0x69, 0x00}))
+          .add(simpleRow(FieldType.FLOAT, (float) 12))
+          .add(simpleRow(FieldType.DOUBLE, 12.0))
+          .add(simpleRow(FieldType.map(FieldType.STRING, FieldType.INT32), 
map))
+          .add(simpleRow(FieldType.array(FieldType.STRING), list))
+          .add(simpleRow(FieldType.row(row.getSchema()), row))
+          .add(simpleRow(FieldType.DATETIME, new Instant(23L)))
+          .add(simpleRow(FieldType.DECIMAL, BigDecimal.valueOf(100000)))
+          .add(simpleRow(FieldType.logicalType(new NullArgumentLogicalType()), 
"str"))
+          .add(simpleRow(FieldType.logicalType(new DateTime()), 
LocalDateTime.of(2000, 1, 3, 3, 1)))
+          .add(simpleNullRow(FieldType.STRING))
+          .add(simpleNullRow(FieldType.INT32))
+          .add(simpleNullRow(FieldType.map(FieldType.STRING, FieldType.INT32)))
+          .add(simpleNullRow(FieldType.array(FieldType.STRING)))
+          .add(simpleNullRow(FieldType.row(row.getSchema())))
+          .add(simpleNullRow(FieldType.logicalType(new 
NullArgumentLogicalType())))
+          .add(simpleNullRow(FieldType.logicalType(new DateTime())))
+          .add(simpleNullRow(FieldType.DECIMAL))
+          .add(simpleNullRow(FieldType.DATETIME))
+          .build();
+    }
+
+    @Parameter(0)
+    public Row row;
+
+    @Test
+    public void toAndFromProto() throws Exception {
+      SchemaApi.Row rowProto = SchemaTranslation.rowToProto(row);
+      Row decodedRow =
+          (Row) SchemaTranslation.rowFromProto(rowProto, 
FieldType.row(row.getSchema()));
+      System.out.println(decodedRow);
+      System.out.println(row);

Review comment:
       probably :)




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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 732008)
    Time Spent: 1h 50m  (was: 1h 40m)

> SchemaTranslation.RowToProto does not properly handle all types
> ---------------------------------------------------------------
>
>                 Key: BEAM-13960
>                 URL: https://issues.apache.org/jira/browse/BEAM-13960
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-java-core
>            Reporter: Lara Schmidt
>            Assignee: Lara Schmidt
>            Priority: P2
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> It doesn't properly handle logical types, nulls, datetime or decimal.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to