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

fix: null type in timepartitioning. #305

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -285,17 +285,6 @@ static StandardTableDefinition fromPb(Table tablePb) {
+ " in table "
+ tablePb.getTableReference().getTableId(),
e);
} catch (NullPointerException e) {
throw new NullPointerException(
"Null pointer - Got unexpected time partitioning "
+ tablePb.getTimePartitioning().toString()
+ " in project "
+ tablePb.getTableReference().getProjectId()
+ " in dataset "
+ tablePb.getTableReference().getDatasetId()
+ " in table "
+ tablePb.getTableReference().getTableId()
+ e.toString());
}
}
if (tablePb.getRangePartitioning() != null) {
Expand Down
Expand Up @@ -142,7 +142,7 @@ static TimePartitioning fromPb(
if (Data.isNull(expirationMs)) {
expirationMs = null;
}
return newBuilder(Type.valueOf(partitioningPb.getType()))
return newBuilder(Type.valueOf(firstNonNull(partitioningPb.getType(), Type.DAY.name())))
.setExpirationMs(expirationMs)
.setField(partitioningPb.getField())
.setRequirePartitionFilter(partitioningPb.getRequirePartitionFilter())
Expand Down
Expand Up @@ -116,11 +116,22 @@ public class BigQueryImplTest {
private static final Long TABLE_CREATION_TIME = 1546275600000L;
private static final TimePartitioning TIME_PARTITIONING =
TimePartitioning.of(TimePartitioning.Type.DAY, EXPIRATION_MS);
private static final com.google.api.services.bigquery.model.TimePartitioning PB_TIMEPARTITIONING =
new com.google.api.services.bigquery.model.TimePartitioning()
.setType(null)
.setField("timestampField");
private static final TimePartitioning TIME_PARTITIONING_NULL_TYPE =
TimePartitioning.fromPb(PB_TIMEPARTITIONING);
private static final StandardTableDefinition TABLE_DEFINITION_WITH_PARTITIONING =
StandardTableDefinition.newBuilder()
.setSchema(TABLE_SCHEMA)
.setTimePartitioning(TIME_PARTITIONING)
.build();
private static final StandardTableDefinition TABLE_DEFINITION_WITH_PARTITIONING_NULL_TYPE =
StandardTableDefinition.newBuilder()
.setSchema(TABLE_SCHEMA)
.setTimePartitioning(TIME_PARTITIONING_NULL_TYPE)
.build();
private static final RangePartitioning.Range RANGE =
RangePartitioning.Range.newBuilder().setStart(1L).setInterval(2L).setEnd(10L).build();
private static final RangePartitioning RANGE_PARTITIONING =
Expand All @@ -142,7 +153,10 @@ public class BigQueryImplTest {
TableInfo.newBuilder(TABLE_ID, TABLE_DEFINITION_WITH_PARTITIONING)
.setCreationTime(TABLE_CREATION_TIME)
.build();

private static final TableInfo TABLE_INFO_WITH_PARTITIONS_NULL_TYPE =
TableInfo.newBuilder(TABLE_ID, TABLE_DEFINITION_WITH_PARTITIONING_NULL_TYPE)
.setCreationTime(TABLE_CREATION_TIME)
.build();
private static final ModelId OTHER_MODEL_ID = ModelId.of(DATASET, OTHER_MODEL);
private static final ModelId MODEL_ID_WITH_PROJECT = ModelId.of(PROJECT, DATASET, MODEL);

Expand Down Expand Up @@ -912,6 +926,22 @@ public void testListTablesReturnedParameters() {
assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class));
}

@Test
public void testListTablesReturnedParametersNullType() {
bigquery = options.getService();
ImmutableList<Table> tableList =
ImmutableList.of(
new Table(bigquery, new TableInfo.BuilderImpl(TABLE_INFO_WITH_PARTITIONS_NULL_TYPE)));
Tuple<String, Iterable<com.google.api.services.bigquery.model.Table>> result =
Tuple.of(CURSOR, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION));
EasyMock.expect(bigqueryRpcMock.listTables(PROJECT, DATASET, TABLE_LIST_OPTIONS))
.andReturn(result);
EasyMock.replay(bigqueryRpcMock);
Page<Table> page = bigquery.listTables(DATASET, TABLE_LIST_PAGE_SIZE, TABLE_LIST_PAGE_TOKEN);
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class));
}

@Test
public void testListTablesWithRangePartitioning() {
bigquery = options.getService();
Expand Down
Expand Up @@ -152,34 +152,6 @@ public void testFromPbWithUnexpectedTimePartitioningTypeRaisesInvalidArgumentExc
fail("testFromPb illegal argument exception did not throw!");
}

@Test
public void testFromPbWithNullTimePartitioningTypeRaisesNullPointerException() {
Table invalidTable =
new Table()
.setType("TABLE")
.setTableReference(
new TableReference()
.setProjectId("NULL_PTR_TEST_PROJECT")
.setDatasetId("NULL_PTR_TEST_DATASET")
.setTableId("NULL_PTR_TEST_TABLE"))
.setTimePartitioning(
new com.google.api.services.bigquery.model.TimePartitioning().setType(null));
try {
StandardTableDefinition.fromPb(invalidTable);
} catch (NullPointerException ne) {
assertThat(
ne.getMessage(),
allOf(
containsString("Null pointer - Got unexpected time partitioning"),
containsString("null"),
containsString("NULL_PTR_TEST_PROJECT"),
containsString("NULL_PTR_TEST_DATASET"),
containsString("NULL_PTR_TEST_TABLE")));
return;
}
fail("testFromPb null pointer exception did not throw!");
}

@Test
public void testFromPbWithNullEstimatedRowsAndBytes() {
StandardTableDefinition.fromPb(
Expand Down