You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/05/05 19:00:47 UTC

[GitHub] [beam] TheNeuralBit commented on a change in pull request #11609: [BEAM-9887] Throw IllegalArgumentException when building Row with logical types with Invalid input

TheNeuralBit commented on a change in pull request #11609:
URL: https://github.com/apache/beam/pull/11609#discussion_r420336807



##########
File path: sdks/java/core/src/test/java/org/apache/beam/sdk/schemas/logicaltypes/LogicalTypesTest.java
##########
@@ -97,4 +99,19 @@ public void testNanosDuration() {
     assertEquals(duration, row.getLogicalTypeValue(0, NanosDuration.class));
     assertEquals(durationAsRow, row.getBaseValue(0, Row.class));
   }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testFixedBytesIllegalArgument() {
+    Schema schema = Schema.builder().addLogicalTypeField("char", FixedBytes.of(10)).build();
+    byte[] byteArrayWithLengthFive = {1, 2, 3, 4, 5};
+    Row row = Row.withSchema(schema).withFieldValue("char", byteArrayWithLengthFive).build();
+  }

Review comment:
       Could you add a test like this but with `addValues`?

##########
File path: sdks/java/core/src/test/java/org/apache/beam/sdk/schemas/logicaltypes/LogicalTypesTest.java
##########
@@ -97,4 +99,19 @@ public void testNanosDuration() {
     assertEquals(duration, row.getLogicalTypeValue(0, NanosDuration.class));
     assertEquals(durationAsRow, row.getBaseValue(0, Row.class));
   }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testFixedBytesIllegalArgument() {
+    Schema schema = Schema.builder().addLogicalTypeField("char", FixedBytes.of(10)).build();
+    byte[] byteArrayWithLengthFive = {1, 2, 3, 4, 5};
+    Row row = Row.withSchema(schema).withFieldValue("char", byteArrayWithLengthFive).build();
+  }
+
+  @Test
+  public void testFixedBytes() {
+    Schema schema = Schema.builder().addLogicalTypeField("char", FixedBytes.of(10)).build();
+    byte[] byteArray = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+    Row row = Row.withSchema(schema).withFieldValue("char", byteArray).build();
+    assertTrue(Arrays.equals(byteArray, row.getLogicalTypeValue("char", byte[].class)));
+  }

Review comment:
       Since these tests are really checking `Row`'s verification, I think they would be better in `RowTest`. Could you move them there? 




----------------------------------------------------------------
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:
users@infra.apache.org