Skip to content

Commit

Permalink
fix(debug): add debug statement to StandardTableDefinition (#128)
Browse files Browse the repository at this point in the history
* chore: add debug statement to StandardTableDefinition

* update to include cause

* remove changes to method headers

* update base on comment

* adding testcase

* adding testcases

* fix test dep build error

[WARNING] Used undeclared dependencies found:
[WARNING]    org.hamcrest:hamcrest-core:jar:1.3:test

* update to add more info
  • Loading branch information
stephaniewang526 authored and chingor13 committed Jan 28, 2020
1 parent fbbba31 commit 0d4092d
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
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

0 comments on commit 0d4092d

Please sign in to comment.