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: set requestId for fast query path in QueryRequestInfo instead of QueryJobConfiguration #987
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
988a2ba
feat: set requestId for fast query path in QueryRequestInfo instead o…
stephaniewang526 d0d7254
push more changes
stephaniewang526 8c4439a
fix: toEquals() test case
stephaniewang526 030135a
update to use ArgumentCaptor to avoid Matcher issue
stephaniewang526 71c46ae
nit
stephaniewang526 91e1fb9
add check for QueryRequestCapture against QueryJobConfiguration
stephaniewang526 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1885,9 +1885,8 @@ public void testFastQueryRequestCompleted() throws InterruptedException { | |
.setTotalBytesProcessed(42L) | ||
.setTotalRows(BigInteger.valueOf(1L)); | ||
|
||
QueryRequestInfo requestInfo = new QueryRequestInfo(QUERY_JOB_CONFIGURATION_FOR_QUERY); | ||
|
||
when(bigqueryRpcMock.queryRpc(PROJECT, requestInfo.toPb())).thenReturn(queryResponsePb); | ||
when(bigqueryRpcMock.queryRpc(eq(PROJECT), requestPbCapture.capture())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to validate that what is captured is actually what we expect to see (except the requestId). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: 7123195 |
||
.thenReturn(queryResponsePb); | ||
|
||
bigquery = options.getService(); | ||
TableResult result = bigquery.query(QUERY_JOB_CONFIGURATION_FOR_QUERY); | ||
|
@@ -1900,7 +1899,15 @@ public void testFastQueryRequestCompleted() throws InterruptedException { | |
assertThat(row.get(0).getBooleanValue()).isFalse(); | ||
assertThat(row.get(1).getLongValue()).isEqualTo(1); | ||
} | ||
verify(bigqueryRpcMock).queryRpc(PROJECT, requestInfo.toPb()); | ||
|
||
QueryRequest requestPb = requestPbCapture.getValue(); | ||
assertEquals(QUERY_JOB_CONFIGURATION_FOR_QUERY.getQuery(), requestPb.getQuery()); | ||
assertEquals( | ||
QUERY_JOB_CONFIGURATION_FOR_QUERY.getDefaultDataset().getDataset(), | ||
requestPb.getDefaultDataset().getDatasetId()); | ||
assertEquals(QUERY_JOB_CONFIGURATION_FOR_QUERY.useQueryCache(), requestPb.getUseQueryCache()); | ||
|
||
verify(bigqueryRpcMock).queryRpc(eq(PROJECT), requestPbCapture.capture()); | ||
} | ||
|
||
@Test | ||
|
@@ -1937,22 +1944,30 @@ public void testFastQueryMultiplePages() throws InterruptedException { | |
.setTotalBytesProcessed(42L) | ||
.setTotalRows(BigInteger.valueOf(1L)); | ||
|
||
QueryRequestInfo requestInfo = new QueryRequestInfo(QUERY_JOB_CONFIGURATION_FOR_QUERY); | ||
when(bigqueryRpcMock.queryRpc(PROJECT, requestInfo.toPb())).thenReturn(queryResponsePb); | ||
when(bigqueryRpcMock.queryRpc(eq(PROJECT), requestPbCapture.capture())) | ||
.thenReturn(queryResponsePb); | ||
|
||
bigquery = options.getService(); | ||
TableResult result = bigquery.query(QUERY_JOB_CONFIGURATION_FOR_QUERY); | ||
assertTrue(result.hasNextPage()); | ||
assertNotNull(result.getNextPageToken()); | ||
assertNotNull(result.getNextPage()); | ||
|
||
QueryRequest requestPb = requestPbCapture.getValue(); | ||
assertEquals(QUERY_JOB_CONFIGURATION_FOR_QUERY.getQuery(), requestPb.getQuery()); | ||
assertEquals( | ||
QUERY_JOB_CONFIGURATION_FOR_QUERY.getDefaultDataset().getDataset(), | ||
requestPb.getDefaultDataset().getDatasetId()); | ||
assertEquals(QUERY_JOB_CONFIGURATION_FOR_QUERY.useQueryCache(), requestPb.getUseQueryCache()); | ||
|
||
verify(bigqueryRpcMock).getJob(PROJECT, JOB, null, EMPTY_RPC_OPTIONS); | ||
verify(bigqueryRpcMock) | ||
.listTableData( | ||
PROJECT, | ||
DATASET, | ||
TABLE, | ||
BigQueryImpl.optionMap(BigQuery.TableDataListOption.pageToken(CURSOR))); | ||
verify(bigqueryRpcMock).queryRpc(PROJECT, requestInfo.toPb()); | ||
verify(bigqueryRpcMock).queryRpc(eq(PROJECT), requestPbCapture.capture()); | ||
} | ||
|
||
@Test | ||
|
@@ -1983,10 +1998,8 @@ public void testFastQuerySlowDdl() throws InterruptedException { | |
.setTotalRows(BigInteger.valueOf(1L)) | ||
.setSchema(TABLE_SCHEMA.toPb()); | ||
|
||
QueryRequestInfo requestInfo = new QueryRequestInfo(QUERY_JOB_CONFIGURATION_FOR_QUERY); | ||
QueryRequest requestPb = requestInfo.toPb(); | ||
|
||
when(bigqueryRpcMock.queryRpc(PROJECT, requestPb)).thenReturn(queryResponsePb); | ||
when(bigqueryRpcMock.queryRpc(eq(PROJECT), requestPbCapture.capture())) | ||
.thenReturn(queryResponsePb); | ||
responseJob.getConfiguration().getQuery().setDestinationTable(TABLE_ID.toPb()); | ||
when(bigqueryRpcMock.getJob(PROJECT, JOB, null, EMPTY_RPC_OPTIONS)).thenReturn(responseJob); | ||
when(bigqueryRpcMock.getQueryResults( | ||
|
@@ -2004,7 +2017,14 @@ public void testFastQuerySlowDdl() throws InterruptedException { | |
assertThat(row.get(1).getLongValue()).isEqualTo(1); | ||
} | ||
|
||
verify(bigqueryRpcMock).queryRpc(PROJECT, requestInfo.toPb()); | ||
QueryRequest requestPb = requestPbCapture.getValue(); | ||
assertEquals(QUERY_JOB_CONFIGURATION_FOR_QUERY.getQuery(), requestPb.getQuery()); | ||
assertEquals( | ||
QUERY_JOB_CONFIGURATION_FOR_QUERY.getDefaultDataset().getDataset(), | ||
requestPb.getDefaultDataset().getDatasetId()); | ||
assertEquals(QUERY_JOB_CONFIGURATION_FOR_QUERY.useQueryCache(), requestPb.getUseQueryCache()); | ||
|
||
verify(bigqueryRpcMock).queryRpc(eq(PROJECT), requestPbCapture.capture()); | ||
verify(bigqueryRpcMock).getJob(PROJECT, JOB, null, EMPTY_RPC_OPTIONS); | ||
verify(bigqueryRpcMock) | ||
.getQueryResults( | ||
|
@@ -2287,9 +2307,6 @@ public void testFastQuerySQLShouldRetry() throws Exception { | |
.setTotalRows(BigInteger.valueOf(1L)) | ||
.setSchema(TABLE_SCHEMA.toPb()); | ||
|
||
QueryRequestInfo requestInfo = new QueryRequestInfo(QUERY_JOB_CONFIGURATION_FOR_QUERY); | ||
QueryRequest requestPb = requestInfo.toPb(); | ||
|
||
when(bigqueryRpcMock.queryRpc(eq(PROJECT), requestPbCapture.capture())) | ||
.thenThrow(new BigQueryException(500, "InternalError")) | ||
.thenThrow(new BigQueryException(502, "Bad Gateway")) | ||
|
@@ -2310,13 +2327,13 @@ public void testFastQuerySQLShouldRetry() throws Exception { | |
|
||
List<QueryRequest> allRequests = requestPbCapture.getAllValues(); | ||
boolean idempotent = true; | ||
String requestId = requestPb.getRequestId(); | ||
String firstRequestId = allRequests.get(0).getRequestId(); | ||
for (QueryRequest request : allRequests) { | ||
idempotent = request.getRequestId().equals(requestId); | ||
idempotent = request.getRequestId().equals(firstRequestId); | ||
} | ||
assertTrue(idempotent); | ||
|
||
verify(bigqueryRpcMock, times(5)).queryRpc(PROJECT, requestPb); | ||
verify(bigqueryRpcMock, times(5)).queryRpc(eq(PROJECT), requestPbCapture.capture()); | ||
} | ||
|
||
@Test | ||
|
@@ -2331,9 +2348,6 @@ public void testFastQueryDMLShouldRetry() throws Exception { | |
.setNumDmlAffectedRows(1L) | ||
.setSchema(TABLE_SCHEMA.toPb()); | ||
|
||
QueryRequestInfo requestInfo = new QueryRequestInfo(QUERY_JOB_CONFIGURATION_FOR_DMLQUERY); | ||
QueryRequest requestPb = requestInfo.toPb(); | ||
|
||
when(bigqueryRpcMock.queryRpc(eq(PROJECT), requestPbCapture.capture())) | ||
.thenThrow(new BigQueryException(500, "InternalError")) | ||
.thenThrow(new BigQueryException(502, "Bad Gateway")) | ||
|
@@ -2354,13 +2368,13 @@ public void testFastQueryDMLShouldRetry() throws Exception { | |
|
||
List<QueryRequest> allRequests = requestPbCapture.getAllValues(); | ||
boolean idempotent = true; | ||
String requestId = requestPb.getRequestId(); | ||
String firstRequestId = allRequests.get(0).getRequestId(); | ||
for (QueryRequest request : allRequests) { | ||
idempotent = request.getRequestId().equals(requestId); | ||
idempotent = request.getRequestId().equals(firstRequestId); | ||
} | ||
assertTrue(idempotent); | ||
|
||
verify(bigqueryRpcMock, times(5)).queryRpc(PROJECT, requestPb); | ||
verify(bigqueryRpcMock, times(5)).queryRpc(eq(PROJECT), requestPbCapture.capture()); | ||
} | ||
|
||
@Test | ||
|
@@ -2374,9 +2388,6 @@ public void testFastQueryDDLShouldRetry() throws Exception { | |
.setTotalBytesProcessed(42L) | ||
.setSchema(TABLE_SCHEMA.toPb()); | ||
|
||
QueryRequestInfo requestInfo = new QueryRequestInfo(QUERY_JOB_CONFIGURATION_FOR_DDLQUERY); | ||
QueryRequest requestPb = requestInfo.toPb(); | ||
|
||
when(bigqueryRpcMock.queryRpc(eq(PROJECT), requestPbCapture.capture())) | ||
.thenThrow(new BigQueryException(500, "InternalError")) | ||
.thenThrow(new BigQueryException(502, "Bad Gateway")) | ||
|
@@ -2397,13 +2408,13 @@ public void testFastQueryDDLShouldRetry() throws Exception { | |
|
||
List<QueryRequest> allRequests = requestPbCapture.getAllValues(); | ||
boolean idempotent = true; | ||
String requestId = requestPb.getRequestId(); | ||
String firstRequestId = allRequests.get(0).getRequestId(); | ||
for (QueryRequest request : allRequests) { | ||
idempotent = request.getRequestId().equals(requestId); | ||
idempotent = request.getRequestId().equals(firstRequestId); | ||
} | ||
assertTrue(idempotent); | ||
|
||
verify(bigqueryRpcMock, times(5)).queryRpc(PROJECT, requestPb); | ||
verify(bigqueryRpcMock, times(5)).queryRpc(eq(PROJECT), requestPbCapture.capture()); | ||
} | ||
|
||
@Test | ||
|
@@ -2424,10 +2435,7 @@ public void testFastQueryBigQueryException() throws InterruptedException { | |
.setPageToken(null) | ||
.setErrors(errorProtoList); | ||
|
||
QueryRequestInfo requestInfo = new QueryRequestInfo(QUERY_JOB_CONFIGURATION_FOR_QUERY); | ||
QueryRequest requestPb = requestInfo.toPb(); | ||
|
||
when(bigqueryRpcMock.queryRpc(PROJECT, requestPb)).thenReturn(responsePb); | ||
when(bigqueryRpcMock.queryRpc(eq(PROJECT), requestPbCapture.capture())).thenReturn(responsePb); | ||
|
||
bigquery = options.getService(); | ||
try { | ||
|
@@ -2436,7 +2444,14 @@ public void testFastQueryBigQueryException() throws InterruptedException { | |
} catch (BigQueryException ex) { | ||
assertEquals(Lists.transform(errorProtoList, BigQueryError.FROM_PB_FUNCTION), ex.getErrors()); | ||
} | ||
verify(bigqueryRpcMock).queryRpc(PROJECT, requestPb); | ||
|
||
QueryRequest requestPb = requestPbCapture.getValue(); | ||
assertEquals(QUERY_JOB_CONFIGURATION_FOR_QUERY.getQuery(), requestPb.getQuery()); | ||
assertEquals( | ||
QUERY_JOB_CONFIGURATION_FOR_QUERY.getDefaultDataset().getDataset(), | ||
requestPb.getDefaultDataset().getDatasetId()); | ||
assertEquals(QUERY_JOB_CONFIGURATION_FOR_QUERY.useQueryCache(), requestPb.getUseQueryCache()); | ||
verify(bigqueryRpcMock).queryRpc(eq(PROJECT), requestPbCapture.capture()); | ||
} | ||
|
||
@Test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any cases where a QueryRequestInfo may get reused? Such usage may indicate we set this at time of sending the request (outside of the retry wrapper) rather than time of instantiating the request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes -- we decided to design it to set this requestId at the time of instantiating the request object which means when a user runs the same QueryJobConfiguration twice, they will be sending two requestIds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying. My worry was mostly around cases where someone may retain a reference and use this in unexpected ways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted -- thank you!