Get write stream details Stay organized with collections Save and categorize content based on your preferences.
Retrieves information about an existing BigQuery write stream. Use this to check the state and schema of a stream before appending data.
Code sample
Node.js
Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
const{BigQueryWriteClient}=require('@google-cloud/bigquery-storage');const{status}=require('@grpc/grpc-js');constclient=newBigQueryWriteClient();/** * Gets information about a single write stream. * * @param {string} projectId The project ID of the table. e.g. 'my-project' * @param {string} datasetId The dataset ID of the table. e.g. 'my_dataset' * @param {string} tableId The ID of the table. e.g. 'my_table' */asyncfunctiongetWriteStream(projectId,datasetId,tableId){conststreamId="_default";constname=client.writeStreamPath(projectId,datasetId,tableId,streamId);constrequest={name,};try{const[response]=awaitclient.getWriteStream(request);console.log(`Got write stream:${response.name}`);console.log(`Stream type:${response.type}`);console.log(`Stream location:${response.location}`);}catch(err){if(err.code===status.NOT_FOUND){console.log(`Write stream${name} not found.`);}else{console.error('Error getting write stream:',err);}}}Python
Before trying this sample, follow thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
importgoogle.api_core.exceptionsfromgoogle.cloudimportbigquery_storage_v1defget_write_stream(project_id:str,dataset_id:str,table_id:str,stream_id:str)->None:"""Gets information about a single write stream. Args: project_id: The project id. dataset_id: The dataset id table_id: The table id stream_id: The stream id """client=bigquery_storage_v1.BigQueryWriteClient()stream_name=(f"projects/{project_id}/datasets/{dataset_id}"f"/tables/{table_id}/streams/{stream_id}")try:stream=client.get_write_stream(name=stream_name)print(f"Got write stream:{stream.name}")print(f"Stream type:{stream.Type(stream.type_).name}")exceptgoogle.api_core.exceptions.NotFound:print(f"Write stream not found:{stream_name}")What's next
To search and filter code samples for other Google Cloud products, see theGoogle Cloud sample browser.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.