|
45 | 45 | import com.google.cloud.bigquery.Acl.DatasetAclEntity; |
46 | 46 | import com.google.cloud.bigquery.Acl.Expr; |
47 | 47 | import com.google.cloud.bigquery.Acl.User; |
| 48 | +import com.google.cloud.bigquery.ArrowQueryResult; |
48 | 49 | import com.google.cloud.bigquery.BigQuery; |
49 | 50 | import com.google.cloud.bigquery.BigQuery.DatasetField; |
50 | 51 | import com.google.cloud.bigquery.BigQuery.DatasetListOption; |
|
118 | 119 | import com.google.cloud.bigquery.QueryJobConfiguration.JobCreationMode; |
119 | 120 | import com.google.cloud.bigquery.QueryJobConfiguration.Priority; |
120 | 121 | import com.google.cloud.bigquery.QueryParameterValue; |
| 122 | +import com.google.cloud.bigquery.QueryResultsFormat; |
121 | 123 | import com.google.cloud.bigquery.Range; |
122 | 124 | import com.google.cloud.bigquery.RangePartitioning; |
123 | 125 | import com.google.cloud.bigquery.Routine; |
|
203 | 205 | import java.util.concurrent.TimeoutException; |
204 | 206 | import java.util.logging.Level; |
205 | 207 | import java.util.logging.Logger; |
| 208 | +import org.apache.arrow.vector.VectorSchemaRoot; |
206 | 209 | import org.junit.jupiter.api.AfterAll; |
207 | 210 | import org.junit.jupiter.api.BeforeAll; |
208 | 211 | import org.junit.jupiter.api.Test; |
@@ -7497,6 +7500,50 @@ void testQueryWithTimeout() throws InterruptedException { |
7497 | 7500 | assertTrue(millis < 1_000_000 * 2); |
7498 | 7501 | } |
7499 | 7502 |
|
| 7503 | + @Test |
| 7504 | + void testQueryResultsFormatArrow() throws InterruptedException { |
| 7505 | + RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create(); |
| 7506 | + BigQuery bigQuery = bigqueryHelper.getOptions().getService(); |
| 7507 | + String query = "SELECT 1 as id, 'hello' as name, TIMESTAMP('2026-08-10T12:00:00Z') as ts"; |
| 7508 | + QueryJobConfiguration config = |
| 7509 | + QueryJobConfiguration.newBuilder(query) |
| 7510 | + .setQueryResultsFormat(QueryResultsFormat.ARROW) |
| 7511 | + .setJobCreationMode(JobCreationMode.JOB_CREATION_OPTIONAL) |
| 7512 | + .build(); |
| 7513 | + try (ArrowQueryResult result = bigQuery.queryArrow(config)) { |
| 7514 | + assertNotNull(result); |
| 7515 | + int batchCount = 0; |
| 7516 | + long totalRows = 0; |
| 7517 | + for (VectorSchemaRoot root : result) { |
| 7518 | + batchCount++; |
| 7519 | + totalRows += root.getRowCount(); |
| 7520 | + assertEquals(1, root.getRowCount()); |
| 7521 | + } |
| 7522 | + assertTrue(batchCount > 0); |
| 7523 | + assertEquals(1, totalRows); |
| 7524 | + } |
| 7525 | + } |
| 7526 | + |
| 7527 | + @Test |
| 7528 | + void testQueryResultsFormatArrowMultiPage() throws InterruptedException { |
| 7529 | + RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create(); |
| 7530 | + BigQuery bigQuery = bigqueryHelper.getOptions().getService(); |
| 7531 | + String query = "SELECT x FROM UNNEST(GENERATE_ARRAY(1, 15000)) AS x"; |
| 7532 | + QueryJobConfiguration config = |
| 7533 | + QueryJobConfiguration.newBuilder(query) |
| 7534 | + .setQueryResultsFormat(QueryResultsFormat.ARROW) |
| 7535 | + .setJobCreationMode(JobCreationMode.JOB_CREATION_OPTIONAL) |
| 7536 | + .build(); |
| 7537 | + try (ArrowQueryResult result = bigQuery.queryArrow(config)) { |
| 7538 | + assertNotNull(result); |
| 7539 | + long totalRows = 0; |
| 7540 | + for (VectorSchemaRoot root : result) { |
| 7541 | + totalRows += root.getRowCount(); |
| 7542 | + } |
| 7543 | + assertEquals(15000, totalRows); |
| 7544 | + } |
| 7545 | + } |
| 7546 | + |
7500 | 7547 | @Test |
7501 | 7548 | void testUniverseDomainWithInvalidUniverseDomain() { |
7502 | 7549 | RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create(); |
|
0 commit comments