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

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

                Author: ASF GitHub Bot
            Created on: 06/May/20 00:40
            Start Date: 06/May/20 00:40
    Worklog Time Spent: 10m 
      Work Description: rahul8383 commented on a change in pull request #11609:
URL: https://github.com/apache/beam/pull/11609#discussion_r420487951



##########
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:
       Moved the tests to RowTest.java
   
   case in point! 
   How can I write `FixedBytes` test which tests the behaviour of appending 
zeros? To test this behaviour, the input value should have length < 
expectedLength. But, if the input value's length is less than expected length, 
an `IllegalArgumentException` is thrown while building the Row.




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


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

    Worklog Id:     (was: 430980)
    Time Spent: 2h 40m  (was: 2.5h)

> Throw IllegalArgumentException when building Row with logical types with 
> Invalid input 
> ---------------------------------------------------------------------------------------
>
>                 Key: BEAM-9887
>                 URL: https://issues.apache.org/jira/browse/BEAM-9887
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-java-core
>            Reporter: Rahul Patwari
>            Assignee: Rahul Patwari
>            Priority: Major
>          Time Spent: 2h 40m
>  Remaining Estimate: 0h
>
> schema.logicaltypes.FixedBytes logical type expects an argument - the length 
> of the byte[].
> When an invalid input value (with length < expectedLength) is provided while 
> building the Row with FixedBytes logical type, IllegalArgumentException is 
> expected. But, the Exception is not thrown. The below code illustrates the 
> behaviour:
> {code:java}
>  Schema schema = Schema.builder().addLogicalTypeField("char", 
> FixedBytes.of(10)).build();
>  byte[] byteArray = {1, 2, 3, 4, 5};
>  Row row = Row.withSchema(schema).withFieldValue("char", byteArray).build();
>  System.out.println(Arrays.toString(row.getLogicalTypeValue("char", 
> byte[].class)));
> {code}
> The above code prints "[1, 2, 3, 4, 5]" with length 5 to the console, whereas 
> the expected length of FixedBytes, is 10.
> The code is run on the master branch.
> The behaviour is as expected with 2.20.0 release.
> {{ }}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to