fix(task-gcs): handle null value on BigQueryFetch

This commit is contained in:
tchiotludo
2019-10-29 21:41:19 +01:00
parent 0d0d72e831
commit 25eb085324
2 changed files with 7 additions and 1 deletions

View File

@@ -3,7 +3,6 @@ package org.floworc.task.gcp.bigquery;
import com.google.cloud.bigquery.*;
import com.google.common.collect.ImmutableMap;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;
import org.floworc.core.models.tasks.RunnableTask;
import org.floworc.core.models.tasks.Task;
@@ -95,6 +94,10 @@ public class BigQueryFetch extends Task implements RunnableTask {
.collect(Collectors.toList());
}
if (value.isNull()) {
return null;
}
if (LegacySQLTypeName.BOOLEAN.equals(field.getType())) {
return value.getBooleanValue();
}

View File

@@ -14,6 +14,7 @@ import java.time.LocalTime;
import java.util.List;
import java.util.Map;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.is;
@@ -31,6 +32,7 @@ class BigQueryFetchTest {
ImmutableMap.of(
"sql", "SELECT " +
" \"hello\" as string," +
" NULL AS `nullable`," +
" 1 as int," +
" 1.25 AS float," +
" DATE(\"2008-12-25\") AS date," +
@@ -53,6 +55,7 @@ class BigQueryFetchTest {
assertThat(rows.size(), is(1));
assertThat(rows.get(0).get("string"), is("hello"));
assertThat(rows.get(0).get("nullable"), is(nullValue()));
assertThat(rows.get(0).get("int"), is(1L));
assertThat(rows.get(0).get("float"), is(1.25D));
assertThat(rows.get(0).get("date"), is(LocalDate.parse("2008-12-25")));