Skip to content
This repository was archived by the owner on Nov 11, 2022. It is now read-only.

BigQuery: fix an issue with option propagation and refactor to future-proof #540

Merged
merged 4 commits into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixups
  • Loading branch information
dhalperi committed Jan 30, 2017
commit 502f99f6dfb233b2681ea6be55b8f63d900c4e67
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ private TableReference executeQueryAndWaitForCompletion()
destinationTable.setDatasetId(temporaryDatasetId);
destinationTable.setTableId(temporaryTableId);
queryConfig.setDestinationTable(destinationTable);
queryConfig.setAllowLargeResults(Boolean.TRUE);

Job queryJob = executeWithBackOff(
client.jobs().insert(projectId, job),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,18 @@ public void testReadFromQueryNoTables() throws IOException, InterruptedException

// Mock job polling.
JobStatus status = new JobStatus().setState("DONE");
TableReference tableRef =
new TableReference().setProjectId("project").setDatasetId("dataset").setTableId("table");
JobConfigurationQuery queryConfig = new JobConfigurationQuery().setDestinationTable(tableRef);
JobConfigurationQuery resultQueryConfig =
new JobConfigurationQuery().setDestinationTable(
new TableReference()
.setProjectId("project")
.setDatasetId("tempdataset")
.setTableId("temptable")
);
Job getJob =
new Job()
.setJobReference(new JobReference())
.setStatus(status)
.setConfiguration(new JobConfiguration().setQuery(queryConfig));
.setConfiguration(new JobConfiguration().setQuery(resultQueryConfig));
when(mockJobsGet.execute()).thenReturn(getJob);

// Mock table schema fetch.
Expand All @@ -281,8 +285,9 @@ public void testReadFromQueryNoTables() throws IOException, InterruptedException
String query = String.format(
"SELECT \"Arthur\" as name, 42 as count, \"%s\" as photo",
photoBytesEncoded);
JobConfigurationQuery queryConfig = new JobConfigurationQuery().setQuery(query);
try (BigQueryTableRowIterator iterator =
BigQueryTableRowIterator.fromQuery(query, "project", mockClient, null, null)) {
BigQueryTableRowIterator.fromQuery(queryConfig, "project", mockClient)) {
iterator.open();
assertTrue(iterator.advance());
TableRow row = iterator.getCurrent();
Expand Down Expand Up @@ -317,7 +322,7 @@ public void testReadFromQueryNoTables() throws IOException, InterruptedException
verify(mockTablesDelete).execute();
// Table data read.
verify(mockClient).tabledata();
verify(mockTabledata).list("project", "dataset", "table");
verify(mockTabledata).list("project", "tempdataset", "temptable");
verify(mockTabledataList).execute();
}

Expand All @@ -334,18 +339,16 @@ public void testQueryFailed() throws IOException {
when(mockJobsInsert.execute()).thenThrow(exception, exception, exception, exception);

String query = "NOT A QUERY";
JobConfigurationQuery queryConfig = new JobConfigurationQuery().setQuery(query);
try (BigQueryTableRowIterator iterator =
BigQueryTableRowIterator.fromQuery(query, "project", mockClient, null, null)) {

try {
iterator.open();
fail();
} catch (Exception expected) {
// Verify message explains cause and reports the query.
assertThat(expected.getMessage(), containsString("Error"));
assertThat(expected.getMessage(), containsString(query));
assertThat(expected.getCause().getMessage(), containsString(errorReason));
}
BigQueryTableRowIterator.fromQuery(queryConfig, "project", mockClient)) {
iterator.open();
fail();
} catch (Exception expected) {
// Verify message explains cause and reports the query.
assertThat(expected.getMessage(), containsString("Error"));
assertThat(expected.getMessage(), containsString(query));
assertThat(expected.getCause().getMessage(), containsString(errorReason));
}

// Job inserted to run the query, then polled once.
Expand Down