Skip to content
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

Read API throws NPE for empty tables #3626

Closed
o-shevchenko opened this issue Jan 8, 2025 · 2 comments · Fixed by #3627
Closed

Read API throws NPE for empty tables #3626

o-shevchenko opened this issue Jan 8, 2025 · 2 comments · Fixed by #3627
Assignees
Labels
api: bigquery Issues related to the googleapis/java-bigquery API.

Comments

@o-shevchenko
Copy link
Contributor

o-shevchenko commented Jan 8, 2025

We get NPE when we read an empty table using Read API.
NPE happens here:

cursor = buffer.take(); // advance the cursor,Potentially blocking operation

When we run query Using Fast Query Path (Read API disabled) such code works fine.buffer.take() returns cursor and it correctly indicated in isEndOfStream as EndOfFieldValueList.
But when we enable Read API buffer.take() throws NPE since buffer is null.

Environment details

com.google.cloud:google-cloud-bigquery:2.45.0
Mac OS Sonoma M1
Java version: 17

Steps to reproduce

  1. Enable Read API (make sure you see Not Using Fast Query Path, using jobs.insert, see related issue I've attached)
  2. Read the empty table
  3. Execute next()

Code example

val connectionSettings = ConnectionSettings.newBuilder()
                    .setJobTimeoutMs(Long.MAX_VALUE) // that is crucial to enable Read API, see the attached issue
                    .setRequestTimeout(DEFAULT_QUERY_TIMEOUT_MS)
                    .setUseReadAPI(true)
                    .setMaxResults(DEFAULT_MAX_RESULT)
                    .setUseQueryCache(true)
                    .build()
                val connection = context.createConnection(connectionSettings)
                val bqResult = connection.executeSelect(code)
                bqResult.resultSet.next() // NPE
                

Stack trace

 onError(java.lang.NullPointerException: Cannot invoke "java.util.concurrent.BlockingQueue.take()" because the return value of "com.google.cloud.bigquery.BigQueryResultImpl.access$200(com.google.cloud.bigquery.BigQueryResultImpl)" is null))
 at com.google.cloud.bigquery.BigQueryResultImpl$BigQueryResultSet.next(BigQueryResultImpl.java:120)

Related issue: googleapis/java-bigquerystorage#2764
#3624

@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/java-bigquery API. label Jan 8, 2025
@o-shevchenko o-shevchenko changed the title Read API NPE for empty tables Read API throws NPE for empty tables Jan 8, 2025
@PhongChuong PhongChuong self-assigned this Jan 8, 2025
@PhongChuong
Copy link
Contributor

Thanks for the concise bug report.
I'll send a PR for a fix.

@PhongChuong
Copy link
Contributor

The fix should roll out in the next release. Thanks for the bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/java-bigquery API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants