[
https://issues.apache.org/jira/browse/BEAM-3932?focusedWorklogId=85324&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-85324
]
ASF GitHub Bot logged work on BEAM-3932:
----------------------------------------
Author: ASF GitHub Bot
Created on: 28/Mar/18 17:11
Start Date: 28/Mar/18 17:11
Worklog Time Spent: 10m
Work Description: iemejia closed pull request #4951: [BEAM-3932] Adds
handling of array null values to MutationSizeEstimator
URL: https://github.com/apache/beam/pull/4951
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/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/MutationSizeEstimator.java
b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/MutationSizeEstimator.java
index c483af969c6..20c09e8074b 100644
---
a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/MutationSizeEstimator.java
+++
b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/MutationSizeEstimator.java
@@ -120,6 +120,9 @@ private static long estimatePrimitiveValue(Value v) {
}
private static long estimateArrayValue(Value v) {
+ if (v.isNull()) {
+ return 0;
+ }
switch (v.getType().getArrayElementType().getCode()) {
case BOOL:
return v.getBoolArray().size();
diff --git
a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/spanner/MutationSizeEstimatorTest.java
b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/spanner/MutationSizeEstimatorTest.java
index 013b83d4586..0c6d0898b92 100644
---
a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/spanner/MutationSizeEstimatorTest.java
+++
b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/spanner/MutationSizeEstimatorTest.java
@@ -64,6 +64,29 @@ public void primitiveArrays() throws Exception {
assertThat(MutationSizeEstimator.sizeOf(bool), is(4L));
}
+ @Test
+ public void nullPrimitiveArrays() throws Exception {
+ Mutation int64 =
+ Mutation.newInsertOrUpdateBuilder("test")
+ .set("one")
+ .toInt64Array((long[]) null)
+ .build();
+ Mutation float64 =
+ Mutation.newInsertOrUpdateBuilder("test")
+ .set("one")
+ .toFloat64Array((double[]) null)
+ .build();
+ Mutation bool =
+ Mutation.newInsertOrUpdateBuilder("test")
+ .set("one")
+ .toBoolArray((boolean[]) null)
+ .build();
+
+ assertThat(MutationSizeEstimator.sizeOf(int64), is(0L));
+ assertThat(MutationSizeEstimator.sizeOf(float64), is(0L));
+ assertThat(MutationSizeEstimator.sizeOf(bool), is(0L));
+ }
+
@Test
public void strings() throws Exception {
Mutation emptyString =
Mutation.newInsertOrUpdateBuilder("test").set("one").to("").build();
@@ -75,11 +98,17 @@ public void strings() throws Exception {
.set("one")
.toStringArray(Arrays.asList("one", "two", null))
.build();
+ Mutation nullArray =
+ Mutation.newInsertOrUpdateBuilder("test")
+ .set("one")
+ .toStringArray(null)
+ .build();
assertThat(MutationSizeEstimator.sizeOf(emptyString), is(0L));
assertThat(MutationSizeEstimator.sizeOf(nullString), is(0L));
assertThat(MutationSizeEstimator.sizeOf(sampleString), is(3L));
assertThat(MutationSizeEstimator.sizeOf(sampleArray), is(6L));
+ assertThat(MutationSizeEstimator.sizeOf(nullArray), is(0L));
}
@Test
@@ -93,10 +122,16 @@ public void bytes() throws Exception {
.set("one")
.to(ByteArray.fromBase64("abcdabcd"))
.build();
+ Mutation nullArray =
+ Mutation.newInsertOrUpdateBuilder("test")
+ .set("one")
+ .toBytesArray(null)
+ .build();
assertThat(MutationSizeEstimator.sizeOf(empty), is(0L));
assertThat(MutationSizeEstimator.sizeOf(nullValue), is(0L));
assertThat(MutationSizeEstimator.sizeOf(sample), is(6L));
+ assertThat(MutationSizeEstimator.sizeOf(nullArray), is(0L));
}
@Test
@@ -128,12 +163,25 @@ public void dates() throws Exception {
Date.fromYearMonthDay(2017, 1, 2)))
.build();
+ Mutation nullTimestampArray =
+ Mutation.newInsertOrUpdateBuilder("test")
+ .set("one")
+ .toTimestampArray(null)
+ .build();
+ Mutation nullDateArray =
+ Mutation.newInsertOrUpdateBuilder("test")
+ .set("one")
+ .toDateArray(null)
+ .build();
+
assertThat(MutationSizeEstimator.sizeOf(timestamp), is(12L));
assertThat(MutationSizeEstimator.sizeOf(date), is(12L));
assertThat(MutationSizeEstimator.sizeOf(nullTimestamp), is(12L));
assertThat(MutationSizeEstimator.sizeOf(nullDate), is(12L));
assertThat(MutationSizeEstimator.sizeOf(timestampArray), is(24L));
assertThat(MutationSizeEstimator.sizeOf(dateArray), is(48L));
+ assertThat(MutationSizeEstimator.sizeOf(nullTimestampArray), is(0L));
+ assertThat(MutationSizeEstimator.sizeOf(nullDateArray), is(0L));
}
@Test
----------------------------------------------------------------
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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 85324)
Time Spent: 50m (was: 40m)
> Spanner MutationSizeEstimator doesn't handle null array values
> --------------------------------------------------------------
>
> Key: BEAM-3932
> URL: https://issues.apache.org/jira/browse/BEAM-3932
> Project: Beam
> Issue Type: Bug
> Components: io-java-gcp
> Affects Versions: 2.3.0
> Reporter: Mairbek Khadikov
> Assignee: Mairbek Khadikov
> Priority: Major
> Fix For: 2.5.0
>
> Time Spent: 50m
> Remaining Estimate: 0h
>
> More details here
> https://stackoverflow.com/questions/49484770/dataflow-spanner-api-throws-illegalstateexception-when-value-of-array-type-colum
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)