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

feat: add debug statement to StandardTableDefinition #128

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
6 changes: 6 additions & 0 deletions google-cloud-bigquery/pom.xml
Expand Up @@ -102,6 +102,12 @@
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -272,7 +272,31 @@ static StandardTableDefinition fromPb(Table tablePb) {
builder.setStreamingBuffer(StreamingBuffer.fromPb(tablePb.getStreamingBuffer()));
}
if (tablePb.getTimePartitioning() != null) {
builder.setTimePartitioning(TimePartitioning.fromPb(tablePb.getTimePartitioning()));
try {
builder.setTimePartitioning(TimePartitioning.fromPb(tablePb.getTimePartitioning()));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(
"Illegal Argument - Got unexpected time partitioning "
+ tablePb.getTimePartitioning().toString()
+ " in project "
+ tablePb.getTableReference().getProjectId()
+ " in dataset "
+ tablePb.getTableReference().getDatasetId()
+ " 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) {
builder.setRangePartitioning(RangePartitioning.fromPb(tablePb.getRangePartitioning()));
Expand Down
Expand Up @@ -16,11 +16,17 @@

package com.google.cloud.bigquery;

import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.google.api.services.bigquery.model.Streamingbuffer;
import com.google.api.services.bigquery.model.Table;
import com.google.api.services.bigquery.model.TableReference;
import com.google.cloud.bigquery.StandardTableDefinition.StreamingBuffer;
import com.google.common.collect.ImmutableList;
import org.junit.Test;
Expand Down Expand Up @@ -118,6 +124,62 @@ public void testToAndFromPb() {
definition, TableDefinition.<StandardTableDefinition>fromPb(definition.toPb()));
}

@Test
public void testFromPbWithUnexpectedTimePartitioningTypeRaisesInvalidArgumentException() {
Table invalidTable =
new Table()
.setType("TABLE")
.setTableReference(
new TableReference()
.setProjectId("ILLEGAL_ARG_TEST_PROJECT")
.setDatasetId("ILLEGAL_ARG_TEST_DATASET")
.setTableId("ILLEGAL_ARG_TEST_TABLE"))
.setTimePartitioning(
new com.google.api.services.bigquery.model.TimePartitioning().setType("GHURRY"));
try {
StandardTableDefinition.fromPb(invalidTable);
} catch (IllegalArgumentException ie) {
assertThat(
ie.getMessage(),
allOf(
containsString("Illegal Argument - Got unexpected time partitioning"),
containsString("GHURRY"),
containsString("ILLEGAL_ARG_TEST_PROJECT"),
containsString("ILLEGAL_ARG_TEST_DATASET"),
containsString("ILLEGAL_ARG_TEST_TABLE")));
return;
}
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