You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by bh...@apache.org on 2020/05/11 19:18:37 UTC
[beam] branch master updated: [BEAM-9887] Throw
IllegalArgumentException when building Row with logical types with Invalid
input (#11609)
This is an automated email from the ASF dual-hosted git repository.
bhulette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new b0932f2 [BEAM-9887] Throw IllegalArgumentException when building Row with logical types with Invalid input (#11609)
b0932f2 is described below
commit b0932f22fab7cde80f0d32e25ca4ffa8c1bc2307
Author: Rahul Patwari <50...@users.noreply.github.com>
AuthorDate: Tue May 12 00:48:20 2020 +0530
[BEAM-9887] Throw IllegalArgumentException when building Row with logical types with Invalid input (#11609)
* [BEAM-9887] Expected Exception when building Row with logical types with Invalid input
* Fix failed BeamComplexTypeTest.testNullDatetimeFields Test to handle null values
---
.../java/org/apache/beam/sdk/values/RowUtils.java | 2 +-
.../java/org/apache/beam/sdk/values/RowTest.java | 29 +++++++++++++++++++---
.../sdk/extensions/sql/BeamComplexTypeTest.java | 8 +++---
3 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/values/RowUtils.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/values/RowUtils.java
index 3a7c860..e53440a 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/values/RowUtils.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/values/RowUtils.java
@@ -519,7 +519,7 @@ class RowUtils {
Object retValue = null;
FieldOverride override = override(rowPosition);
if (override != null) {
- retValue = override.getOverrideValue();
+ retValue = logicalType.toInputType(logicalType.toBaseType(override.getOverrideValue()));
} else if (value != null) {
retValue = logicalType.toInputType(logicalType.toBaseType(value));
}
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 a9fbc79..7134e02 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
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
@@ -34,12 +35,12 @@ import java.util.stream.Stream;
import org.apache.beam.sdk.schemas.Schema;
import org.apache.beam.sdk.schemas.Schema.FieldType;
import org.apache.beam.sdk.schemas.logicaltypes.EnumerationType;
+import org.apache.beam.sdk.schemas.logicaltypes.FixedBytes;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Lists;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
-import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -724,7 +725,7 @@ public class RowTest {
Row a = Row.withSchema(schema).addValue(a0).build();
Row b = Row.withSchema(schema).addValue(b0).build();
- Assert.assertEquals(a, b);
+ assertEquals(a, b);
}
@Test
@@ -737,6 +738,28 @@ public class RowTest {
Row a = Row.withSchema(schema).addValue(ByteBuffer.wrap(a0)).build();
Row b = Row.withSchema(schema).addValue(ByteBuffer.wrap(b0)).build();
- Assert.assertEquals(a, b);
+ assertEquals(a, b);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testLogicalTypeWithInvalidInputValueByFieldName() {
+ 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(expected = IllegalArgumentException.class)
+ public void testLogicalTypeWithInvalidInputValueByFieldIndex() {
+ Schema schema = Schema.builder().addLogicalTypeField("char", FixedBytes.of(10)).build();
+ byte[] byteArrayWithLengthFive = {1, 2, 3, 4, 5};
+ Row row = Row.withSchema(schema).addValues(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)));
}
}
diff --git a/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamComplexTypeTest.java b/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamComplexTypeTest.java
index ce46c17..8b3d7e5 100644
--- a/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamComplexTypeTest.java
+++ b/sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamComplexTypeTest.java
@@ -430,12 +430,12 @@ public class BeamComplexTypeTest {
@Override
public Instant toBaseType(Long input) {
- return new Instant((long) input);
+ return (input == null ? null : new Instant((long) input));
}
@Override
public Long toInputType(Instant base) {
- return base.getMillis();
+ return (base == null ? null : base.getMillis());
}
}
@@ -462,12 +462,12 @@ public class BeamComplexTypeTest {
@Override
public Instant toBaseType(Long input) {
- return new Instant((long) input);
+ return (input == null ? null : new Instant((long) input));
}
@Override
public Long toInputType(Instant base) {
- return base.getMillis();
+ return (base == null ? null : base.getMillis());
}
}