|
37 | 37 | import com.google.common.annotations.VisibleForTesting; |
38 | 38 | import com.google.common.base.Function; |
39 | 39 | import com.google.common.collect.ImmutableList; |
40 | | -import com.google.common.collect.ImmutableMap; |
41 | 40 | import com.google.common.collect.Iterables; |
42 | 41 | import com.google.common.collect.Lists; |
43 | 42 | import com.google.common.collect.Maps; |
@@ -129,28 +128,6 @@ public Page<FieldValueList> getNextPage() { |
129 | 128 | } |
130 | 129 | } |
131 | 130 |
|
132 | | - private static class QueryResultsPageFetcherImpl |
133 | | - implements NextPageFetcher<FieldValueList>, QueryResult.QueryResultsPageFetcher { |
134 | | - |
135 | | - private static final long serialVersionUID = -9198905840550459803L; |
136 | | - private final Map<BigQueryRpc.Option, ?> requestOptions; |
137 | | - private final BigQueryOptions serviceOptions; |
138 | | - private final JobId job; |
139 | | - |
140 | | - QueryResultsPageFetcherImpl(JobId job, BigQueryOptions serviceOptions, String cursor, |
141 | | - Map<BigQueryRpc.Option, ?> optionMap) { |
142 | | - this.requestOptions = |
143 | | - PageImpl.nextRequestOptions(BigQueryRpc.Option.PAGE_TOKEN, cursor, optionMap); |
144 | | - this.serviceOptions = serviceOptions; |
145 | | - this.job = job; |
146 | | - } |
147 | | - |
148 | | - @Override |
149 | | - public QueryResult getNextPage() { |
150 | | - return getQueryResults(job, serviceOptions, requestOptions).getResult(); |
151 | | - } |
152 | | - } |
153 | | - |
154 | 131 | private final BigQueryRpc bigQueryRpc; |
155 | 132 |
|
156 | 133 | BigQueryImpl(BigQueryOptions options) { |
@@ -612,49 +589,17 @@ public GetQueryResultsResponse call() { |
612 | 589 | completeJobId.getProject(), completeJobId.getJob(), optionsMap); |
613 | 590 | } |
614 | 591 | }, serviceOptions.getRetrySettings(), EXCEPTION_HANDLER, serviceOptions.getClock()); |
615 | | - QueryResponse.Builder builder = QueryResponse.newBuilder(); |
616 | | - builder.setJobId(JobId.fromPb(results.getJobReference())); |
617 | | - builder.setNumDmlAffectedRows(results.getNumDmlAffectedRows()); |
618 | | - builder.setEtag(results.getEtag()); |
619 | | - builder.setJobCompleted(results.getJobComplete()); |
620 | | - List<TableRow> rowsPb = results.getRows(); |
621 | | - if (results.getJobComplete()) { |
622 | | - QueryResult.Builder resultBuilder = |
623 | | - transformQueryResults( |
624 | | - completeJobId, |
625 | | - rowsPb, |
626 | | - results.getSchema(), |
627 | | - results.getPageToken(), |
628 | | - serviceOptions, |
629 | | - ImmutableMap.<BigQueryRpc.Option, Object>of()); |
630 | | - if (results.getTotalRows() != null) { |
631 | | - resultBuilder.setTotalRows(results.getTotalRows().longValue()); |
632 | | - } |
633 | | - builder.setResult(resultBuilder.build()); |
634 | | - } |
635 | | - if (results.getErrors() != null) { |
636 | | - builder.setExecutionErrors( |
637 | | - Lists.transform(results.getErrors(), BigQueryError.FROM_PB_FUNCTION)); |
638 | | - } |
639 | | - return builder.build(); |
| 592 | + TableSchema schemaPb = results.getSchema(); |
| 593 | + return QueryResponse.newBuilder() |
| 594 | + .setCompleted(results.getJobComplete()) |
| 595 | + .setSchema(schemaPb == null ? null : Schema.fromPb(schemaPb)) |
| 596 | + .setTotalRows(results.getTotalRows() == null ? 0 : results.getTotalRows().longValue()) |
| 597 | + .build(); |
640 | 598 | } catch (RetryHelper.RetryHelperException e) { |
641 | 599 | throw BigQueryException.translateAndThrow(e); |
642 | 600 | } |
643 | 601 | } |
644 | 602 |
|
645 | | - private static QueryResult.Builder transformQueryResults(JobId jobId, List<TableRow> rowsPb, |
646 | | - TableSchema schemaPb, String cursor, BigQueryOptions serviceOptions, |
647 | | - Map<BigQueryRpc.Option, ?> optionsMap) { |
648 | | - QueryResultsPageFetcherImpl nextPageFetcher = |
649 | | - new QueryResultsPageFetcherImpl(jobId, serviceOptions, cursor, optionsMap); |
650 | | - Schema schema = schemaPb != null ? Schema.fromPb(schemaPb) : null; |
651 | | - return QueryResult.newBuilder() |
652 | | - .setPageFetcher(nextPageFetcher) |
653 | | - .setCursor(cursor) |
654 | | - .setSchema(schema) |
655 | | - .setResults(transformTableData(rowsPb, schema)); |
656 | | - } |
657 | | - |
658 | 603 | @Override |
659 | 604 | public TableDataWriteChannel writer(WriteChannelConfiguration writeChannelConfiguration) { |
660 | 605 | return new TableDataWriteChannel(getOptions(), |
|
0 commit comments