0

I'm trying to use @google-cloud/bigquery-storage and it seems I can't get adapt. This is what I'm trying to do.

const { v1, adapt } = require('@google-cloud/bigquery-storage');
const { BigQueryWriteClient } = v1;
const { BigQuery } = require('@google-cloud/bigquery');

    async function BQStorageWrite() {
    
        const bigquery = new BigQuery({ projectId: bqProjectId });
        const dataset = bigquery.dataset(bqDataSetId);
        const table = await dataset.table(bqTableId);
        const [metadata] = await table.getMetadata();
    
        console.log('adapt ' + adapt); // adapt undefined
        console.log('v1 ' + v1); // v1 [object Object]
    
        const storageSchema = adapt.convertBigQuerySchemaToStorageTableSchema(
              metadata.schema
        );

       //Writing data to a BQ Table
    }

adapt is undefined as per the console log, hence I get an error saying 'TypeError: Cannot read properties of undefined (reading 'convertBigQuerySchemaToStorageTableSchema')'

Am I missing something obvious here? What is the correct way to get this imported? Thank you.

DbxD
  • 540
  • 2
  • 15
  • 29
  • 1
    Does this [code](https://github.com/googleapis/nodejs-bigquery-storage/blob/HEAD/samples/append_rows_table_to_proto2.js) help you in resolving the issue? – Prajna Rai T May 04 '23 at 14:37
  • Thanks @Prajna Rai T, this is one of the implementations I’m looking at. The problem appears to be ‘adapt’ is not a part of @google-cloud/bigquery-storage v 3.3.0 which was released in January. It was added to the codebase in March and there is no release since then. If you try the below npmrunkit, you can see v1 is part of the object, but not ‘adapt’. Do we have any other solution which doesn’t involve 'adapt' or creating protobuf files outside of the NodeJS code? Thanks. https://npm.runkit.com/@google-cloud/bigquery-storage/CHANGELOG.md?t=1683190272040 – DbxD May 04 '23 at 23:26
  • Have to tried using this java [code](https://cloud.google.com/bigquery/docs/samples/bigquerystorage-jsonstreamwriter-pending#code-sample) for your requirement? – Prajna Rai T May 05 '23 at 06:57
  • No, I'm trying to achieve this with the node js library. – DbxD May 06 '23 at 08:07
  • Did you get any error messages when using this [code](https://github.com/googleapis/nodejs-bigquery-storage/blob/HEAD/samples/append_rows_table_to_proto2.js)? Could you provide your full code so that I can replicate from my side? Looking into your code issue seems to be because of undefined adapt. – Prajna Rai T May 09 '23 at 13:18
  • Yes, you are correct. I contacted Google on this matter. They haven't released 'adapt' into the library yet. Hence we can't import it (yet). It will be available in the next library release. – DbxD May 09 '23 at 20:57
  • Hi @DbxD, I have posted the answer as Community wiki. So If my answer addressed your question, please consider upvoting and accepting it. If not, let me know so that the answer can be improved. – Prajna Rai T May 15 '23 at 05:31

1 Answers1

1

@DbxD, As you have mentioned in the comment.

adapt is not released into the library yet till the latest version @google-cloud/bigquery-storage v 3.3.0. Hence we can't import it. It will be available in the next library release.

For more information link1 and link2 can be referred.

Posting the answer as community wiki for the benefit of the community that might encounter this use case in the future.

Feel free to edit this answer for additional information.

Prajna Rai T
  • 1,666
  • 3
  • 15