This is an automated email from the ASF dual-hosted git repository.
ahmedabualsaud 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 2b18c281326 null arrays default to empty array (#33919)
2b18c281326 is described below
commit 2b18c28132630689639a308dcc30da1441fd65ae
Author: Ahmed Abualsaud <[email protected]>
AuthorDate: Tue Feb 11 15:54:26 2025 +0000
null arrays default to empty array (#33919)
---
.../org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java | 4 ++++
.../apache/beam/sdk/io/gcp/bigquery/BigQueryUtilsTest.java | 11 +++++++++++
2 files changed, 15 insertions(+)
diff --git
a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java
b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java
index b4d110f90fe..0ac29d749f8 100644
---
a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java
+++
b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java
@@ -35,6 +35,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -714,6 +715,9 @@ public class BigQueryUtils {
if (fieldType.getNullable()) {
return null;
} else {
+ if (fieldType.getTypeName().isCollectionType()) {
+ return Collections.emptyList();
+ }
throw new IllegalArgumentException(
"Received null value for non-nullable field \"" + field.getName()
+ "\"");
}
diff --git
a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtilsTest.java
b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtilsTest.java
index 8b65e58a460..8e2a909a417 100644
---
a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtilsTest.java
+++
b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtilsTest.java
@@ -450,6 +450,9 @@ public class BigQueryUtilsTest {
private static final TableRow BQ_ENUM_ROW = new TableRow().set("color",
"GREEN");
+ private static final Row NULL_ARRAY_ROW =
+
Row.withSchema(ARRAY_TYPE_NULLS).addValue(Collections.emptyList()).build();
+
private static final Row ARRAY_ROW_NULLS =
Row.withSchema(ARRAY_TYPE_NULLS).addValues((Object) Arrays.asList(123L,
null, null)).build();
@@ -459,6 +462,8 @@ public class BigQueryUtilsTest {
private static final Row MAP_ROW =
Row.withSchema(MAP_MAP_TYPE).addValues(ImmutableMap.of("test",
123.456)).build();
+ private static final TableRow BQ_NULL_ARRAY_ROW = new TableRow().set("ids",
null);
+
private static final TableRow BQ_ARRAY_ROW_NULLS =
new TableRow()
.set(
@@ -1021,6 +1026,12 @@ public class BigQueryUtilsTest {
assertEquals(ENUM_STRING_ROW, beamRow);
}
+ @Test
+ public void testToBeamRow_nullArray() {
+ Row beamRow = BigQueryUtils.toBeamRow(ARRAY_TYPE_NULLS, BQ_NULL_ARRAY_ROW);
+ assertEquals(NULL_ARRAY_ROW, beamRow);
+ }
+
@Test
public void testToBeamRow_arrayNulls() {
Row beamRow = BigQueryUtils.toBeamRow(ARRAY_TYPE_NULLS,
BQ_ARRAY_ROW_NULLS);