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

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

                Author: ASF GitHub Bot
            Created on: 17/Sep/18 21:17
            Start Date: 17/Sep/18 21:17
    Worklog Time Spent: 10m 
      Work Description: apilloud closed pull request #6383: [BEAM-5376] Support 
nullability on all Row types
URL: https://github.com/apache/beam/pull/6383
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/values/Row.java 
b/sdks/java/core/src/main/java/org/apache/beam/sdk/values/Row.java
index 2c12a7f1a60..df74a95b52c 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/values/Row.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/values/Row.java
@@ -83,7 +83,7 @@
    * Get a {@link TypeName#BYTE} value by field name, {@link 
IllegalStateException} is thrown if
    * schema doesn't match.
    */
-  public byte getByte(String fieldName) {
+  public Byte getByte(String fieldName) {
     return getByte(getSchema().indexOf(fieldName));
   }
 
@@ -99,7 +99,7 @@ public byte getByte(String fieldName) {
    * Get a {@link TypeName#INT16} value by field name, {@link 
IllegalStateException} is thrown if
    * schema doesn't match.
    */
-  public short getInt16(String fieldName) {
+  public Short getInt16(String fieldName) {
     return getInt16(getSchema().indexOf(fieldName));
   }
 
@@ -107,7 +107,7 @@ public short getInt16(String fieldName) {
    * Get a {@link TypeName#INT32} value by field name, {@link 
IllegalStateException} is thrown if
    * schema doesn't match.
    */
-  public int getInt32(String fieldName) {
+  public Integer getInt32(String fieldName) {
     return getInt32(getSchema().indexOf(fieldName));
   }
 
@@ -115,7 +115,7 @@ public int getInt32(String fieldName) {
    * Get a {@link TypeName#INT64} value by field name, {@link 
IllegalStateException} is thrown if
    * schema doesn't match.
    */
-  public long getInt64(String fieldName) {
+  public Long getInt64(String fieldName) {
     return getInt64(getSchema().indexOf(fieldName));
   }
 
@@ -131,7 +131,7 @@ public BigDecimal getDecimal(String fieldName) {
    * Get a {@link TypeName#FLOAT} value by field name, {@link 
IllegalStateException} is thrown if
    * schema doesn't match.
    */
-  public float getFloat(String fieldName) {
+  public Float getFloat(String fieldName) {
     return getFloat(getSchema().indexOf(fieldName));
   }
 
@@ -139,7 +139,7 @@ public float getFloat(String fieldName) {
    * Get a {@link TypeName#DOUBLE} value by field name, {@link 
IllegalStateException} is thrown if
    * schema doesn't match.
    */
-  public double getDouble(String fieldName) {
+  public Double getDouble(String fieldName) {
     return getDouble(getSchema().indexOf(fieldName));
   }
 
@@ -155,7 +155,7 @@ public String getString(String fieldName) {
    * Get a {@link TypeName#DATETIME} value by field name, {@link 
IllegalStateException} is thrown if
    * schema doesn't match.
    */
-  public ReadableDateTime getDateTime(String fieldName) {
+  public @Nullable ReadableDateTime getDateTime(String fieldName) {
     return getDateTime(getSchema().indexOf(fieldName));
   }
 
@@ -163,7 +163,7 @@ public ReadableDateTime getDateTime(String fieldName) {
    * Get a {@link TypeName#BOOLEAN} value by field name, {@link 
IllegalStateException} is thrown if
    * schema doesn't match.
    */
-  public boolean getBoolean(String fieldName) {
+  public Boolean getBoolean(String fieldName) {
     return getBoolean(getSchema().indexOf(fieldName));
   }
 
@@ -258,9 +258,9 @@ public String getString(int idx) {
    * Get a {@link TypeName#DATETIME} value by field index, {@link 
IllegalStateException} is thrown
    * if schema doesn't match.
    */
-  public ReadableDateTime getDateTime(int idx) {
+  public @Nullable ReadableDateTime getDateTime(int idx) {
     ReadableInstant instant = getValue(idx);
-    return new DateTime(instant).withZone(instant.getZone());
+    return instant == null ? null : new 
DateTime(instant).withZone(instant.getZone());
   }
 
   /**
@@ -275,7 +275,7 @@ public BigDecimal getDecimal(int idx) {
    * Get a {@link Boolean} value by field index, {@link ClassCastException} is 
thrown if schema
    * doesn't match.
    */
-  public boolean getBoolean(int idx) {
+  public Boolean getBoolean(int idx) {
     return getValue(idx);
   }
 
diff --git 
a/sdks/java/core/src/test/java/org/apache/beam/sdk/schemas/JavaBeanSchemaTest.java
 
b/sdks/java/core/src/test/java/org/apache/beam/sdk/schemas/JavaBeanSchemaTest.java
index 9ef7f82e2ba..14ec6740cfd 100644
--- 
a/sdks/java/core/src/test/java/org/apache/beam/sdk/schemas/JavaBeanSchemaTest.java
+++ 
b/sdks/java/core/src/test/java/org/apache/beam/sdk/schemas/JavaBeanSchemaTest.java
@@ -101,11 +101,11 @@ public void testToRow() throws NoSuchSchemaException {
 
     assertEquals(12, row.getFieldCount());
     assertEquals("string", row.getString("str"));
-    assertEquals((byte) 1, row.getByte("aByte"));
-    assertEquals((short) 2, row.getInt16("aShort"));
-    assertEquals((int) 3, row.getInt32("anInt"));
-    assertEquals((long) 4, row.getInt64("aLong"));
-    assertEquals(true, row.getBoolean("aBoolean"));
+    assertEquals((byte) 1, (Object) row.getByte("aByte"));
+    assertEquals((short) 2, (Object) row.getInt16("aShort"));
+    assertEquals((int) 3, (Object) row.getInt32("anInt"));
+    assertEquals((long) 4, (Object) row.getInt64("aLong"));
+    assertEquals(true, (Object) row.getBoolean("aBoolean"));
     assertEquals(DATE.toInstant(), row.getDateTime("dateTime"));
     assertEquals(DATE.toInstant(), row.getDateTime("instant"));
     assertArrayEquals(BYTE_ARRAY, row.getBytes("bytes"));
@@ -155,10 +155,10 @@ public void testRecursiveGetters() throws 
NoSuchSchemaException {
 
     Row nestedRow = row.getRow("nested");
     assertEquals("string", nestedRow.getString("str"));
-    assertEquals((byte) 1, nestedRow.getByte("aByte"));
-    assertEquals((short) 2, nestedRow.getInt16("aShort"));
-    assertEquals((int) 3, nestedRow.getInt32("anInt"));
-    assertEquals((long) 4, nestedRow.getInt64("aLong"));
+    assertEquals((byte) 1, (Object) nestedRow.getByte("aByte"));
+    assertEquals((short) 2, (Object) nestedRow.getInt16("aShort"));
+    assertEquals((int) 3, (Object) nestedRow.getInt32("anInt"));
+    assertEquals((long) 4, (Object) nestedRow.getInt64("aLong"));
     assertEquals(true, nestedRow.getBoolean("aBoolean"));
     assertEquals(DATE.toInstant(), nestedRow.getDateTime("dateTime"));
     assertEquals(DATE.toInstant(), nestedRow.getDateTime("instant"));
diff --git 
a/sdks/java/core/src/test/java/org/apache/beam/sdk/schemas/JavaFieldSchemaTest.java
 
b/sdks/java/core/src/test/java/org/apache/beam/sdk/schemas/JavaFieldSchemaTest.java
index c344c4aa0c5..d4303f4d76c 100644
--- 
a/sdks/java/core/src/test/java/org/apache/beam/sdk/schemas/JavaFieldSchemaTest.java
+++ 
b/sdks/java/core/src/test/java/org/apache/beam/sdk/schemas/JavaFieldSchemaTest.java
@@ -112,10 +112,10 @@ public void testToRow() throws NoSuchSchemaException {
 
     assertEquals(12, row.getFieldCount());
     assertEquals("string", row.getString("str"));
-    assertEquals((byte) 1, row.getByte("aByte"));
-    assertEquals((short) 2, row.getInt16("aShort"));
-    assertEquals((int) 3, row.getInt32("anInt"));
-    assertEquals((long) 4, row.getInt64("aLong"));
+    assertEquals((byte) 1, (Object) row.getByte("aByte"));
+    assertEquals((short) 2, (Object) row.getInt16("aShort"));
+    assertEquals((int) 3, (Object) row.getInt32("anInt"));
+    assertEquals((long) 4, (Object) row.getInt64("aLong"));
     assertEquals(true, row.getBoolean("aBoolean"));
     assertEquals(DATE.toInstant(), row.getDateTime("dateTime"));
     assertEquals(INSTANT, row.getDateTime("instant").toInstant());
@@ -166,10 +166,10 @@ public void testRecursiveGetters() throws 
NoSuchSchemaException {
 
     Row nestedRow = row.getRow("nested");
     assertEquals("string", nestedRow.getString("str"));
-    assertEquals((byte) 1, nestedRow.getByte("aByte"));
-    assertEquals((short) 2, nestedRow.getInt16("aShort"));
-    assertEquals((int) 3, nestedRow.getInt32("anInt"));
-    assertEquals((long) 4, nestedRow.getInt64("aLong"));
+    assertEquals((byte) 1, (Object) nestedRow.getByte("aByte"));
+    assertEquals((short) 2, (Object) nestedRow.getInt16("aShort"));
+    assertEquals((int) 3, (Object) nestedRow.getInt32("anInt"));
+    assertEquals((long) 4, (Object) nestedRow.getInt64("aLong"));
     assertEquals(true, nestedRow.getBoolean("aBoolean"));
     assertEquals(DATE.toInstant(), nestedRow.getDateTime("dateTime"));
     assertEquals(INSTANT, nestedRow.getDateTime("instant").toInstant());
@@ -354,7 +354,7 @@ public void testNullValuesGetters() throws 
NoSuchSchemaException {
     Row row =
         registry.getToRowFunction(POJOWithNullables.class).apply(new 
POJOWithNullables(null, 42));
     assertNull(row.getString("str"));
-    assertEquals(42, row.getInt32("anInt"));
+    assertEquals(42, (Object) row.getInt32("anInt"));
   }
 
   @Test
diff --git 
a/sdks/java/core/src/test/java/org/apache/beam/sdk/values/RowTest.java 
b/sdks/java/core/src/test/java/org/apache/beam/sdk/values/RowTest.java
index 576ced5d24b..3f2d1099370 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/values/RowTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/values/RowTest.java
@@ -48,16 +48,40 @@
   public void testCreatesNullRecord() {
     Schema type =
         Stream.of(
-                Schema.Field.of("f_int", FieldType.INT32).withNullable(true),
-                Schema.Field.of("f_str", FieldType.STRING).withNullable(true),
-                Schema.Field.of("f_double", 
FieldType.DOUBLE).withNullable(true))
+                Schema.Field.of("f_byte", FieldType.BYTE).withNullable(true),
+                Schema.Field.of("f_int16", FieldType.INT16).withNullable(true),
+                Schema.Field.of("f_int32", FieldType.INT32).withNullable(true),
+                Schema.Field.of("f_int64", FieldType.INT64).withNullable(true),
+                Schema.Field.of("f_decimal", 
FieldType.DECIMAL).withNullable(true),
+                Schema.Field.of("f_float", FieldType.FLOAT).withNullable(true),
+                Schema.Field.of("f_double", 
FieldType.DOUBLE).withNullable(true),
+                Schema.Field.of("f_string", 
FieldType.STRING).withNullable(true),
+                Schema.Field.of("f_datetime", 
FieldType.DATETIME).withNullable(true),
+                Schema.Field.of("f_boolean", 
FieldType.BOOLEAN).withNullable(true))
             .collect(toSchema());
 
     Row row = Row.nullRow(type);
 
-    assertNull(row.getValue("f_int"));
-    assertNull(row.getValue("f_str"));
-    assertNull(row.getValue("f_double"));
+    assertNull(row.getByte("f_byte"));
+    assertNull(row.getByte(0));
+    assertNull(row.getInt16("f_int16"));
+    assertNull(row.getInt16(1));
+    assertNull(row.getInt32("f_int32"));
+    assertNull(row.getInt32(2));
+    assertNull(row.getInt64("f_int64"));
+    assertNull(row.getInt64(3));
+    assertNull(row.getDecimal("f_decimal"));
+    assertNull(row.getDecimal(4));
+    assertNull(row.getFloat("f_float"));
+    assertNull(row.getFloat(5));
+    assertNull(row.getDouble("f_double"));
+    assertNull(row.getDouble(6));
+    assertNull(row.getString("f_string"));
+    assertNull(row.getString(7));
+    assertNull(row.getDateTime("f_datetime"));
+    assertNull(row.getDateTime(8));
+    assertNull(row.getBoolean("f_boolean"));
+    assertNull(row.getBoolean(9));
   }
 
   @Test
@@ -91,18 +115,26 @@ public void testCreatesRecord() {
                 (byte) 0, (short) 1, 2, 3L, new BigDecimal(2.3), 1.2f, 3.0d, 
"str", dateTime, false)
             .build();
 
-    assertEquals(0, row.getByte("f_byte"));
-    assertEquals(1, row.getInt16("f_int16"));
-    assertEquals(2, row.getInt32("f_int32"));
-    assertEquals(3, row.getInt64("f_int64"));
+    assertEquals((byte) 0, (Object) row.getByte("f_byte"));
+    assertEquals((byte) 0, (Object) row.getByte(0));
+    assertEquals((short) 1, (Object) row.getInt16("f_int16"));
+    assertEquals((short) 1, (Object) row.getInt16(1));
+    assertEquals((int) 2, (Object) row.getInt32("f_int32"));
+    assertEquals((int) 2, (Object) row.getInt32(2));
+    assertEquals((long) 3, (Object) row.getInt64("f_int64"));
+    assertEquals((long) 3, (Object) row.getInt64(3));
     assertEquals(new BigDecimal(2.3), row.getDecimal("f_decimal"));
+    assertEquals(new BigDecimal(2.3), row.getDecimal(4));
     assertEquals(1.2f, row.getFloat("f_float"), 0);
+    assertEquals(1.2f, row.getFloat(5), 0);
     assertEquals(3.0d, row.getDouble("f_double"), 0);
+    assertEquals(3.0d, row.getDouble(6), 0);
     assertEquals("str", row.getString("f_string"));
+    assertEquals("str", row.getString(7));
     assertEquals(dateTime, row.getDateTime("f_datetime"));
+    assertEquals(dateTime, row.getDateTime(8));
     assertEquals(false, row.getBoolean("f_boolean"));
-    assertEquals("str", row.getString("f_string"));
-    assertEquals(false, row.getBoolean("f_boolean"));
+    assertEquals(false, row.getBoolean(9));
   }
 
   @Test
@@ -117,7 +149,7 @@ public void testCreatesNestedRow() {
             .collect(toSchema());
     Row nestedRow = Row.withSchema(nestedType).addValues("foobar").build();
     Row row = Row.withSchema(type).addValues(42, nestedRow).build();
-    assertEquals(42, row.getInt32("f_int"));
+    assertEquals((int) 42, (Object) row.getInt32("f_int"));
     assertEquals("foobar", row.getRow("nested").getString("f1_str"));
   }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

    Worklog Id:     (was: 145076)
    Time Spent: 2.5h  (was: 2h 20m)

> Row interface doesn't support nullability on all fields.
> --------------------------------------------------------
>
>                 Key: BEAM-5376
>                 URL: https://issues.apache.org/jira/browse/BEAM-5376
>             Project: Beam
>          Issue Type: Improvement
>          Components: dsl-sql
>            Reporter: Andrew Pilloud
>            Assignee: Andrew Pilloud
>            Priority: Major
>          Time Spent: 2.5h
>  Remaining Estimate: 0h
>
> For example: 
> {code:java}
> public boolean getBoolean(int idx);{code}
> Should be:
> {code:java}
> public Boolean getBoolean(int idx);{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to