Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public Object processLogicalType(
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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand All @@ -34,12 +35,12 @@
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;
Expand Down Expand Up @@ -724,7 +725,7 @@ public void testByteArrayEquality() {
Row a = Row.withSchema(schema).addValue(a0).build();
Row b = Row.withSchema(schema).addValue(b0).build();

Assert.assertEquals(a, b);
assertEquals(a, b);
}

@Test
Expand All @@ -737,6 +738,28 @@ public void testByteBufferEquality() {
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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,12 @@ public Schema.FieldType getBaseType() {

@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());
}
}

Expand All @@ -462,12 +462,12 @@ public Schema.FieldType getBaseType() {

@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());
}
}

Expand Down