Hi,
It seems that there isn't method setWriteDisposition in Builder:
Any idea what might might be amiss?
Br,
pekka
Solved! Go to Solution.
To set the writeDisposition property for a BigQuery Storage Write API request in Java, you should configure it when creating a WriteStream object. The writeDisposition setting is not directly set on a BatchCommitWriteStreamsRequest. Instead, it is specified for each individual WriteStream. Here's an example of how to set the writeDisposition property to WRITE_TRUNCATE for a WriteStream: import com.google.cloud.bigquery.storage.v1.CreateWriteStreamRequest; import com.google.cloud.bigquery.storage.v1.WriteStream; import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient; // ... BigQueryWriteClient writeClient = BigQueryWriteClient.create(); // Create a WriteStream with WRITE_TRUNCATE disposition WriteStream writeStream = WriteStream.newBuilder() .setType(WriteStream.Type.PENDING) .setWriteDisposition(WriteStream.WriteDisposition.WRITE_TRUNCATE) .build(); CreateWriteStreamRequest createWriteStreamRequest = CreateWriteStreamRequest.newBuilder() .setParent("projects/your-project/datasets/your-dataset/tables/your-table") .setWriteStream(writeStream) .build(); WriteStream createdWriteStream = writeClient.createWriteStream(createWriteStreamRequest); // Now you can write data to this stream and then commit it using BatchCommitWriteStreamsRequest In this example, the writeDisposition is set to WRITE_TRUNCATE when creating the write stream. This means that when you commit this stream using BatchCommitWriteStreamsRequest, the table will first be truncated before the new data is written. Please note that the BatchCommitWriteStreamsRequest is used to commit the data that has been written to the streams and does not have a method to set writeDisposition. Remember to replace "projects/your-project/datasets/your-dataset/tables/your-table" with your actual project, dataset, and table names. Also, ensure that you handle exceptions and manage resources properly, especially in a production environment.
To set the writeDisposition property for a BigQuery Storage Write API request in Java, you should configure it when creating a WriteStream object. The writeDisposition setting is not directly set on a BatchCommitWriteStreamsRequest. Instead, it is specified for each individual WriteStream. Here's an example of how to set the writeDisposition property to WRITE_TRUNCATE for a WriteStream: import com.google.cloud.bigquery.storage.v1.CreateWriteStreamRequest; import com.google.cloud.bigquery.storage.v1.WriteStream; import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient; // ... BigQueryWriteClient writeClient = BigQueryWriteClient.create(); // Create a WriteStream with WRITE_TRUNCATE disposition WriteStream writeStream = WriteStream.newBuilder() .setType(WriteStream.Type.PENDING) .setWriteDisposition(WriteStream.WriteDisposition.WRITE_TRUNCATE) .build(); CreateWriteStreamRequest createWriteStreamRequest = CreateWriteStreamRequest.newBuilder() .setParent("projects/your-project/datasets/your-dataset/tables/your-table") .setWriteStream(writeStream) .build(); WriteStream createdWriteStream = writeClient.createWriteStream(createWriteStreamRequest); // Now you can write data to this stream and then commit it using BatchCommitWriteStreamsRequest In this example, the writeDisposition is set to WRITE_TRUNCATE when creating the write stream. This means that when you commit this stream using BatchCommitWriteStreamsRequest, the table will first be truncated before the new data is written. Please note that the BatchCommitWriteStreamsRequest is used to commit the data that has been written to the streams and does not have a method to set writeDisposition. Remember to replace "projects/your-project/datasets/your-dataset/tables/your-table" with your actual project, dataset, and table names. Also, ensure that you handle exceptions and manage resources properly, especially in a production environment.