diff --git a/java-bigquery/benchmark/src/main/java/com.google.cloud.bigquery/QueryBenchmark.java b/java-bigquery/benchmark/src/main/java/com.google.cloud.bigquery/QueryBenchmark.java index 79aa484d8b69..bdab12d62a44 100644 --- a/java-bigquery/benchmark/src/main/java/com.google.cloud.bigquery/QueryBenchmark.java +++ b/java-bigquery/benchmark/src/main/java/com.google.cloud.bigquery/QueryBenchmark.java @@ -16,8 +16,10 @@ package com.google.cloud.bigquery; +import java.util.Iterator; import java.util.List; import java.util.concurrent.TimeUnit; +import org.apache.arrow.vector.VectorSchemaRoot; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; @@ -93,4 +95,73 @@ private void queryPerform(String queries, Blackhole blackhole) throws Exception public void query(QueryParams queryParams, Blackhole blackhole) throws Exception { queryPerform(queryParams.queries, blackhole); } + + @Benchmark + public void queryWithArrowRowBased(QueryParams queryParams, Blackhole blackhole) + throws Exception { + QueryJobConfiguration config = + QueryJobConfiguration.newBuilder(queryParams.queries) + .setUseLegacySql(false) + .setQueryResultsFormat(QueryResultsFormat.ARROW) + .build(); + TableResult result = bigquery.query(config); + for (FieldValueList row : result.iterateAll()) { + blackhole.consume(row); + } + } + + @Benchmark + public void queryWithArrowZeroCopy(QueryParams queryParams, Blackhole blackhole) + throws Exception { + QueryJobConfiguration config = + QueryJobConfiguration.newBuilder(queryParams.queries) + .setUseLegacySql(false) + .setQueryResultsFormat(QueryResultsFormat.ARROW) + .build(); + try (ArrowQueryResult result = bigquery.queryArrow(config)) { + for (VectorSchemaRoot root : result) { + blackhole.consume(root); + } + } + } + + @Benchmark + public void querySimplePath(QueryParams queryParams, Blackhole blackhole) throws Exception { + TableResult result = + bigquery.query( + QueryJobConfiguration.newBuilder(queryParams.queries).setUseLegacySql(false).build()); + for (FieldValueList row : result.getValues()) { + blackhole.consume(row); + } + } + + @Benchmark + public void queryWithArrowRowBasedSimplePath(QueryParams queryParams, Blackhole blackhole) + throws Exception { + QueryJobConfiguration config = + QueryJobConfiguration.newBuilder(queryParams.queries) + .setUseLegacySql(false) + .setQueryResultsFormat(QueryResultsFormat.ARROW) + .build(); + TableResult result = bigquery.query(config); + for (FieldValueList row : result.getValues()) { + blackhole.consume(row); + } + } + + @Benchmark + public void queryWithArrowZeroCopySimplePath(QueryParams queryParams, Blackhole blackhole) + throws Exception { + QueryJobConfiguration config = + QueryJobConfiguration.newBuilder(queryParams.queries) + .setUseLegacySql(false) + .setQueryResultsFormat(QueryResultsFormat.ARROW) + .build(); + try (ArrowQueryResult result = bigquery.queryArrow(config)) { + Iterator it = result.iterator(); + if (it.hasNext()) { + blackhole.consume(it.next()); + } + } + } }