Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java BQ] Default null array in Beam Row to empty array #32604

Merged
merged 1 commit into from
Oct 1, 2024
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 @@ -30,6 +30,7 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -272,6 +273,8 @@ private static Object messageValueFromRowValue(
if (value == null) {
if (fieldDescriptor.isOptional()) {
return null;
} else if (fieldDescriptor.isRepeated()) {
return Collections.emptyList();
} else {
throw new IllegalArgumentException(
"Received null value for non-nullable field " + fieldDescriptor.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.beam.sdk.schemas.Schema;
Expand Down Expand Up @@ -71,6 +72,7 @@ public class BeamRowToStorageApiProtoTest {
.addField("booleanValue", FieldType.BOOLEAN.withNullable(true))
.addField("bytesValue", FieldType.BYTES.withNullable(true))
.addField("arrayValue", FieldType.array(FieldType.STRING))
.addField("arrayNullValue", FieldType.array(FieldType.STRING).withNullable(true))
.addField("iterableValue", FieldType.array(FieldType.STRING))
.addField("sqlDateValue", FieldType.logicalType(SqlTypes.DATE).withNullable(true))
.addField("sqlTimeValue", FieldType.logicalType(SqlTypes.TIME).withNullable(true))
Expand Down Expand Up @@ -168,43 +170,50 @@ public class BeamRowToStorageApiProtoTest {
.build())
.addField(
FieldDescriptorProto.newBuilder()
.setName("iterablevalue")
.setName("arraynullvalue")
.setNumber(13)
.setType(Type.TYPE_STRING)
.setLabel(Label.LABEL_REPEATED)
.build())
.addField(
FieldDescriptorProto.newBuilder()
.setName("sqldatevalue")
.setName("iterablevalue")
.setNumber(14)
.setType(Type.TYPE_STRING)
.setLabel(Label.LABEL_REPEATED)
.build())
.addField(
FieldDescriptorProto.newBuilder()
.setName("sqldatevalue")
.setNumber(15)
.setType(Type.TYPE_INT32)
.setLabel(Label.LABEL_OPTIONAL)
.build())
.addField(
FieldDescriptorProto.newBuilder()
.setName("sqltimevalue")
.setNumber(15)
.setNumber(16)
.setType(Type.TYPE_INT64)
.setLabel(Label.LABEL_OPTIONAL)
.build())
.addField(
FieldDescriptorProto.newBuilder()
.setName("sqldatetimevalue")
.setNumber(16)
.setNumber(17)
.setType(Type.TYPE_INT64)
.setLabel(Label.LABEL_OPTIONAL)
.build())
.addField(
FieldDescriptorProto.newBuilder()
.setName("sqltimestampvalue")
.setNumber(17)
.setNumber(18)
.setType(Type.TYPE_INT64)
.setLabel(Label.LABEL_OPTIONAL)
.build())
.addField(
FieldDescriptorProto.newBuilder()
.setName("enumvalue")
.setNumber(18)
.setNumber(19)
.setType(Type.TYPE_STRING)
.setLabel(Label.LABEL_OPTIONAL)
.build())
Expand All @@ -225,6 +234,7 @@ public class BeamRowToStorageApiProtoTest {
.withFieldValue("booleanValue", true)
.withFieldValue("bytesValue", BYTES)
.withFieldValue("arrayValue", ImmutableList.of("one", "two", "red", "blue"))
.withFieldValue("arrayNullValue", null)
.withFieldValue("iterableValue", ImmutableList.of("blue", "red", "two", "one"))
.withFieldValue("sqlDateValue", LocalDate.now())
.withFieldValue("sqlTimeValue", LocalTime.now())
Expand All @@ -248,6 +258,7 @@ public class BeamRowToStorageApiProtoTest {
.put("booleanvalue", true)
.put("bytesvalue", ByteString.copyFrom(BYTES))
.put("arrayvalue", ImmutableList.of("one", "two", "red", "blue"))
.put("arraynullvalue", Collections.emptyList())
.put("iterablevalue", ImmutableList.of("blue", "red", "two", "one"))
.put(
"sqldatevalue",
Expand Down
Loading