Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Executing multiple queries with a single bigquery connection

I have a simple Kotlin snippet which tries to execute some queries in a row using the new `executeSelect` method from the Connection:

fun main() {
val count = 3
println("Start")
val connection = BigQueryOptions.getDefaultInstance().service.createConnection()

repeat(count) {
val result = connection.executeSelect("SELECT RAND() as random_value$it")
println("Result for $it: $result")
}
}

However running this code results in the following output:

Start
Jun 03, 2024 9:32:56 PM com.google.cloud.bigquery.ConnectionImpl getExecuteSelectResponse
INFO: 
 Using Fast Query Path
Result for 0: com.google.cloud.bigquery.BigQueryResultImpl@7a1234bf
Jun 03, 2024 9:32:58 PM com.google.cloud.bigquery.ConnectionImpl getExecuteSelectResponse
INFO: 
 Using Fast Query Path
Exception in thread "main" java.util.concurrent.RejectedExecutionException: Task com.google.cloud.bigquery.ConnectionImpl$Lambda$100/0x0000000801191b18@39a2bb97 rejected from java.util.concurrent.ThreadPoolExecutor@3ad2e17[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 3]
at java.base/java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2065)
at java.base/java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:833)
at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1365)
at com.google.cloud.bigquery.ConnectionImpl.runNextPageTaskAsync(ConnectionImpl.java:628)
at com.google.cloud.bigquery.ConnectionImpl.processQueryResponseResults(ConnectionImpl.java:579)
at com.google.cloud.bigquery.ConnectionImpl.queryRpc(ConnectionImpl.java:474)
at com.google.cloud.bigquery.ConnectionImpl.getExecuteSelectResponse(ConnectionImpl.java:239)
at com.google.cloud.bigquery.ConnectionImpl.executeSelect(ConnectionImpl.java:198)
at org.example.MainKt.main(Main.kt:12)
at org.example.MainKt.main(Main.kt)
 
Process finished with exit code 1
 
The version of google-cloud-bigquery is 2.39.1
 
Does this mean that for each query a new connection needs to be created?
0 0 172
0 REPLIES 0