This is an automated email from the ASF dual-hosted git repository.
pabloem 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 d6313df Add null checks to FhirIO.Search for when the search results
are empty. (#14024)
d6313df is described below
commit d6313dff2a9f5d32358a842c354975f0cd515bbf
Author: Milena Bukal <[email protected]>
AuthorDate: Fri Feb 19 19:22:31 2021 -0500
Add null checks to FhirIO.Search for when the search results are empty.
(#14024)
* Add null checks to FhirIO.Search for when the search results are empty.
* Fix ImmutableMap import.
---
.../apache/beam/sdk/io/gcp/healthcare/FhirIO.java | 1 -
.../io/gcp/healthcare/HttpHealthcareApiClient.java | 2 +-
.../beam/sdk/io/gcp/healthcare/FhirIOSearchIT.java | 32 ++++++++++++++++++++++
3 files changed, 33 insertions(+), 2 deletions(-)
diff --git
a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIO.java
b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIO.java
index 4e188fd..359ebf4 100644
---
a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIO.java
+++
b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIO.java
@@ -1685,7 +1685,6 @@ public class FhirIO {
new
HttpHealthcareApiClient.FhirResourcePages.FhirResourcePagesIterator(
client, fhirStore, resourceType, parameterObjects);
JsonArray result = new JsonArray();
- result.addAll(iter.next());
while (iter.hasNext()) {
result.addAll(iter.next());
}
diff --git
a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java
b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java
index 15f254a..b2fcb18 100644
---
a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java
+++
b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java
@@ -961,7 +961,7 @@ public class HttpHealthcareApiClient implements
HealthcareApiClient, Serializabl
JsonObject jsonResponse =
JsonParser.parseString(mapper.writeValueAsString(response)).getAsJsonObject();
JsonArray resources = jsonResponse.getAsJsonArray("entry");
- return resources.size() != 0;
+ return resources != null && resources.size() != 0;
} catch (IOException e) {
throw new NoSuchElementException(
String.format(
diff --git
a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIOSearchIT.java
b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIOSearchIT.java
index c56cecf..b636389 100644
---
a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIOSearchIT.java
+++
b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIOSearchIT.java
@@ -40,6 +40,7 @@ import org.apache.beam.sdk.testing.TestPipeline;
import org.apache.beam.sdk.transforms.Create;
import org.apache.beam.sdk.values.KV;
import org.apache.beam.sdk.values.PCollection;
+import
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -181,4 +182,35 @@ public class FhirIOSearchIT {
pipeline.run().waitUntilFinish();
}
+
+ @Test
+ public void testFhirIOSearch_emptyResult() {
+ pipeline.getOptions().as(DirectOptions.class).setBlockOnRun(false);
+
+ // Search using a search that will return no results.
+ FhirSearchParameter<String> emptySearch =
+ FhirSearchParameter.of("Patient", KEY, ImmutableMap.of("name",
"INVALID_NAME"));
+ PCollection<FhirSearchParameter<String>> searchConfigs =
+ pipeline.apply(
+
Create.of(emptySearch).withCoder(FhirSearchParameterCoder.of(StringUtf8Coder.of())));
+ FhirIO.Search.Result result =
+ searchConfigs.apply(
+ FhirIO.searchResources(healthcareDataset + "/fhirStores/" +
fhirStoreId));
+
+ // Verify that there are no failures.
+ PAssert.that(result.getFailedSearches()).empty();
+ // Verify that the result is empty.
+ PCollection<KV<String, JsonArray>> keyedResources =
result.getKeyedResources();
+ PAssert.that(keyedResources)
+ .satisfies(
+ input -> {
+ for (KV<String, JsonArray> resource : input) {
+ assertEquals(KEY, resource.getKey());
+ assertEquals(0, resource.getValue().size());
+ }
+ return null;
+ });
+
+ pipeline.run().waitUntilFinish();
+ }
}