Commit ff58ec9
authored
test: parametrize to_arrow empty stream tests and update docstrings (#17919)
## Problem
When reading from an empty BigQuery table using the Read API, the stream
may return no messages. Previously, this could lead to an
`AttributeError` when trying to parse the schema from a `None` parser.
While a fallback was added to return an empty table, this fallback uses
an empty schema (zero columns), which can cause downstream consumers
(like Vertex Ray) to fail if they expect specific columns to be present.
## Solution
1. **Updated Documentation**: Added explanatory comments and updated
docstrings in `reader.py` to clarify the flow between
`ReadRowsStream.to_arrow()` and `ReadRowsIterable.to_arrow()`, and to
inform users about the fallback behavior.
2. **Added Parametrized Tests**: Added comprehensive tests to
`test_reader_v1_arrow.py` to verify the behavior of `to_arrow()` on
empty streams, both with and without a `read_session` provided.
## Notes to Reviewers
- This PR does not change functionality but adds testing and
documentation around existing behavior to prevent future regression and
aid debugging. The functionality that should ensure the correct behavior
in internal bug #352600521 was added in February in [PR #
15575](#15575).
This PR is less about fixing the bug versus documenting the correct use
of the code to avoid issues.
- To guarantee the correct schema (non-empty) for empty streams, callers
should provide the `read_session` to `ReadRowsStream.to_arrow()`.
Fixes internal bug #3526005211 parent 4af69c4 commit ff58ec9
2 files changed
Lines changed: 36 additions & 1 deletion
File tree
- packages/google-cloud-bigquery-storage
- google/cloud/bigquery_storage_v1
- tests/unit
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
352 | 359 | | |
353 | 360 | | |
354 | 361 | | |
| |||
365 | 372 | | |
366 | 373 | | |
367 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
368 | 378 | | |
369 | 379 | | |
370 | 380 | | |
| |||
Lines changed: 26 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
| |||
208 | 207 | | |
209 | 208 | | |
210 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
211 | 236 | | |
212 | 237 | | |
213 | 238 | | |
| |||
0 commit comments