Skip to content

Commit 0d4092d

Browse files
stephaniewang526chingor13
authored andcommitted
fix(debug): add debug statement to StandardTableDefinition (#128)
* 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
1 parent fbbba31 commit 0d4092d

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

‎google-cloud-bigquery/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@
102102
<groupId>org.objenesis</groupId>
103103
<artifactId>objenesis</artifactId>
104104
</dependency>
105+
<dependency>
106+
<groupId>org.hamcrest</groupId>
107+
<artifactId>hamcrest-core</artifactId>
108+
<version>1.3</version>
109+
<scope>test</scope>
110+
</dependency>
105111
</dependencies>
106112

107113
<build>

‎google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/StandardTableDefinition.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,31 @@ static StandardTableDefinition fromPb(Table tablePb) {
272272
builder.setStreamingBuffer(StreamingBuffer.fromPb(tablePb.getStreamingBuffer()));
273273
}
274274
if (tablePb.getTimePartitioning() != null) {
275-
builder.setTimePartitioning(TimePartitioning.fromPb(tablePb.getTimePartitioning()));
275+
try {
276+
builder.setTimePartitioning(TimePartitioning.fromPb(tablePb.getTimePartitioning()));
277+
} catch (IllegalArgumentException e) {
278+
throw new IllegalArgumentException(
279+
"Illegal Argument - Got unexpected time partitioning "
280+
+ tablePb.getTimePartitioning().toString()
281+
+ " in project "
282+
+ tablePb.getTableReference().getProjectId()
283+
+ " in dataset "
284+
+ tablePb.getTableReference().getDatasetId()
285+
+ " in table "
286+
+ tablePb.getTableReference().getTableId(),
287+
e);
288+
} catch (NullPointerException e) {
289+
throw new NullPointerException(
290+
"Null pointer - Got unexpected time partitioning "
291+
+ tablePb.getTimePartitioning().toString()
292+
+ " in project "
293+
+ tablePb.getTableReference().getProjectId()
294+
+ " in dataset "
295+
+ tablePb.getTableReference().getDatasetId()
296+
+ " in table "
297+
+ tablePb.getTableReference().getTableId()
298+
+ e.toString());
299+
}
276300
}
277301
if (tablePb.getRangePartitioning() != null) {
278302
builder.setRangePartitioning(RangePartitioning.fromPb(tablePb.getRangePartitioning()));

‎google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/StandardTableDefinitionTest.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@
1616

1717
package com.google.cloud.bigquery;
1818

19+
import static org.hamcrest.CoreMatchers.allOf;
20+
import static org.hamcrest.CoreMatchers.containsString;
21+
import static org.hamcrest.MatcherAssert.assertThat;
1922
import static org.junit.Assert.assertEquals;
2023
import static org.junit.Assert.assertNull;
2124
import static org.junit.Assert.assertTrue;
25+
import static org.junit.Assert.fail;
2226

2327
import com.google.api.services.bigquery.model.Streamingbuffer;
28+
import com.google.api.services.bigquery.model.Table;
29+
import com.google.api.services.bigquery.model.TableReference;
2430
import com.google.cloud.bigquery.StandardTableDefinition.StreamingBuffer;
2531
import com.google.common.collect.ImmutableList;
2632
import org.junit.Test;
@@ -118,6 +124,62 @@ public void testToAndFromPb() {
118124
definition, TableDefinition.<StandardTableDefinition>fromPb(definition.toPb()));
119125
}
120126

127+
@Test
128+
public void testFromPbWithUnexpectedTimePartitioningTypeRaisesInvalidArgumentException() {
129+
Table invalidTable =
130+
new Table()
131+
.setType("TABLE")
132+
.setTableReference(
133+
new TableReference()
134+
.setProjectId("ILLEGAL_ARG_TEST_PROJECT")
135+
.setDatasetId("ILLEGAL_ARG_TEST_DATASET")
136+
.setTableId("ILLEGAL_ARG_TEST_TABLE"))
137+
.setTimePartitioning(
138+
new com.google.api.services.bigquery.model.TimePartitioning().setType("GHURRY"));
139+
try {
140+
StandardTableDefinition.fromPb(invalidTable);
141+
} catch (IllegalArgumentException ie) {
142+
assertThat(
143+
ie.getMessage(),
144+
allOf(
145+
containsString("Illegal Argument - Got unexpected time partitioning"),
146+
containsString("GHURRY"),
147+
containsString("ILLEGAL_ARG_TEST_PROJECT"),
148+
containsString("ILLEGAL_ARG_TEST_DATASET"),
149+
containsString("ILLEGAL_ARG_TEST_TABLE")));
150+
return;
151+
}
152+
fail("testFromPb illegal argument exception did not throw!");
153+
}
154+
155+
@Test
156+
public void testFromPbWithNullTimePartitioningTypeRaisesNullPointerException() {
157+
Table invalidTable =
158+
new Table()
159+
.setType("TABLE")
160+
.setTableReference(
161+
new TableReference()
162+
.setProjectId("NULL_PTR_TEST_PROJECT")
163+
.setDatasetId("NULL_PTR_TEST_DATASET")
164+
.setTableId("NULL_PTR_TEST_TABLE"))
165+
.setTimePartitioning(
166+
new com.google.api.services.bigquery.model.TimePartitioning().setType(null));
167+
try {
168+
StandardTableDefinition.fromPb(invalidTable);
169+
} catch (NullPointerException ne) {
170+
assertThat(
171+
ne.getMessage(),
172+
allOf(
173+
containsString("Null pointer - Got unexpected time partitioning"),
174+
containsString("null"),
175+
containsString("NULL_PTR_TEST_PROJECT"),
176+
containsString("NULL_PTR_TEST_DATASET"),
177+
containsString("NULL_PTR_TEST_TABLE")));
178+
return;
179+
}
180+
fail("testFromPb null pointer exception did not throw!");
181+
}
182+
121183
@Test
122184
public void testFromPbWithNullEstimatedRowsAndBytes() {
123185
StandardTableDefinition.fromPb(

0 commit comments

Comments
 (0)