Visitar URL original
Bug in table.getRows when using different selectedFields in consecutive calls · Issue #1433 · googleapis/nodejs-bigquery · GitHub
Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

Bug in table.getRows when using different selectedFields in consecutive calls #1433

Description

@jonathan-lande-cyera

Please make sure you have searched for information in the following guides.

A screenshot that you have tested with "Try this API".

https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa

image

Link to the code that reproduces this issue. A link to a public Github Repository or gist with a minimal reproduction.

https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
OR
https://github.com/jonathan-lande-cyera/nodejs-bigquery/blob/a9b6215aecd3227e009f6808c798f4661754ab55/test/table.ts#L2193C1-L2233C8

A step-by-step description of how to reproduce the issue, based on the linked reproduction.

  1. Copy code from gist into test/table.ts under describe('getRows')
  2. Run test "should return selected fields after consecutive requests"
  3. The test fails and an exception is raised

A clear and concise description of what the bug is, and what you expected to happen.

When calling table.getRows more than once, each time with different selectedFields - the method fails with:

TypeError: Cannot read properties of undefined (reading 'mode')
      at <anonymous> (src/bigquery.ts:615:25)
      at Array.map (<anonymous>)
      at mergeSchema (src/bigquery.ts:612:21)
      at Array.map (<anonymous>)
      at Function.mergeSchemaWithRows_ (src/bigquery.ts:609:25)
      at onComplete (src/table.ts:1843:23)
      at <anonymous> (src/table.ts:1891:9)
      at Table.table.request (test/table.ts:2220:11)
      at Table.getRows (src/table.ts:1860:10)
      at Table.wrapper (node_modules/@google-cloud/promisify/build/src/index.js:30:35)
      at Context.<anonymous> (test/table.ts:2222:15)
      at process.processImmediate (node:internal/timers:476:21)
      at process.callbackTrampoline (node:internal/async_hooks:128:17)

It looks like the table object's metadata.schema.fields is affected by the previous call to getRows and becomes an empty array on the second call, causing the method to fail.

A clear and concise description WHY you expect this behavior, i.e., was it a recent change, there is documentation that points to this behavior, etc. **

Calling getRows with valid selectedFields values corresponding to existing columns in the table shouldn't throw an exception.

Activity

  1. added
    api: bigquery
    on Jan 7, 2025
  2. self-assigned this
    on Jan 8, 2025
  3. added
    priority: p2
    on Jan 8, 2025
  4. alvarowolfx commented on Feb 11, 2025

    @alvarowolfx
    Contributor

    thanks @jonathan-lande-cyera in depth report. Sorry that I haven't looked at this before, I was swamped with other priorities and could give much attention to it. I've just opened #1437 to fix the issue, just waiting for some peer reviews on it.

  5. jonathan-lande-cyera commented on Mar 3, 2025

    @jonathan-lande-cyera
    Author

    Thanks for your help, @alvarowolfx. Unfortunately, I'm still encountering an error when querying a table with records and repeated fields. I couldn't easily write a test to reproduce it, but I've saved the error I'm getting.
    I would highly appreciate it if you could take a look.
    Thanks 🙏

    The error:

    TypeError: value.map is not a function
        at <dir>/node_modules/@google-cloud/bigquery/build/src/bigquery.js:325:35
        at Array.map (<anonymous>)
        at mergeSchema (<dir>/node_modules/@google-cloud/bigquery/build/src/bigquery.js:321:26)
        at Array.map (<anonymous>)
        at Function.mergeSchemaWithRows_ (<dir>/node_modules/@google-cloud/bigquery/build/src/bigquery.js:319:29)
        at onComplete (<dir>/node_modules/@google-cloud/bigquery/build/src/table.js:972:32)
        at <dir>/node_modules/@google-cloud/bigquery/build/src/table.js:1007:13
        at <dir>/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/build/src/util.js:412:25
        at Util.handleResp (<dir>/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/build/src/util.js:161:9)
        at <dir>/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/build/src/util.js:534:22
    Node.js v18.20.4
    
  6. alvarowolfx commented on Mar 7, 2025

    @alvarowolfx
    Contributor

    Sorry for the late reply, but I managed to reproduce here @jonathan-lande-cyera, but still couldn't fix it. Might be able to land the fix in the next week.

    Running this query and trying to add nested.object.a to selectedFields throws that error:

    SELECT STRUCT([STRUCT(STRUCT('1' as a, '2' as b) as object)] as nested) 
    
  7. alvarowolfx commented on Mar 13, 2025

    @alvarowolfx
    Contributor

    After digging more into this feature, I don't know why it was build as a client side feature. I found other flaws where for deeply nested objects, some format of selectedFields was not even working properly.

    Like for the query SELECT 40 as age, [STRUCT(STRUCT('1' as a, '2' as b) as object)] as nested and selectedFields=['age', 'nested.object.b'], it is currently returning [40, {nested:{object:{b:'1'}], which is incorrect.

    BigQuery API on the service for tabledata.list supports a selectedFields parameter that does the conversion on the backend side. Ref - https://cloud.google.com/bigquery/docs/reference/rest/v2/tabledata/list#query-parameters

    I'm gonna send a PR cleaning that up and leaving all the handling to the service side.

  8. jonathan-lande-cyera commented on Jul 2, 2025

    @jonathan-lande-cyera
    Author

    Hi @alvarowolfx, I think this is related to this issue.
    I've encountered this error:

    TypeError: Cannot read properties of undefined (reading 'name')
        at /app/node_modules/@google-cloud/bigquery/build/src/bigquery.js:343:41
        at Array.map (<anonymous>)
        at mergeSchema (/app/node_modules/@google-cloud/bigquery/build/src/bigquery.js:324:26)
        at Array.map (<anonymous>)
        at Function.mergeSchemaWithRows_ (/app/node_modules/@google-cloud/bigquery/build/src/bigquery.js:322:29)
        at convertSchemaFieldValue (/app/node_modules/@google-cloud/bigquery/build/src/bigquery.js:1538:30)
        at /app/node_modules/@google-cloud/bigquery/build/src/bigquery.js:336:29
        at Array.map (<anonymous>)
        at mergeSchema (/app/node_modules/@google-cloud/bigquery/build/src/bigquery.js:324:26)
        at Array.map (<anonymous>)
    }
    

    When calling the table.getRows method using SDK version 7.9.3.

  9. jonathan-lande-cyera commented on Sep 9, 2025

    @jonathan-lande-cyera
    Author

    Hi @alvarowolfx,

    We're still getting this error

    TypeError: Cannot read properties of null (reading 'map')
        at /app/node_modules/@google-cloud/bigquery/build/src/bigquery.js:328:35
        at Array.map (<anonymous>)
        at mergeSchema (/app/node_modules/@google-cloud/bigquery/build/src/bigquery.js:324:26)
        at Array.map (<anonymous>)
        at Function.mergeSchemaWithRows_ (/app/node_modules/@google-cloud/bigquery/build/src/bigquery.js:322:29)
        at convertSchemaFieldValue (/app/node_modules/@google-cloud/bigquery/build/src/bigquery.js:1538:30)
        at /app/node_modules/@google-cloud/bigquery/build/src/bigquery.js:329:32
        at Array.map (<anonymous>)
        at /app/node_modules/@google-cloud/bigquery/build/src/bigquery.js:328:35
        at Array.map (<anonymous>)
    

    When using version 7.9.4

    Any idea how to solve this?

  10. alvarowolfx commented on Sep 9, 2025

    @alvarowolfx
    Contributor

    @jonathan-lande-cyera can you create a separated issue and example to reproduce the issue ? sorry that this got lost, I ended missing because it was on a close issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: bigquerypriority: p2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions