use of com.google.cloud.bigquery.storage.v1.StreamWriter in project java-bigquerystorage by googleapis.
the class ParallelWriteCommittedStream method writeToStream.
private void writeToStream(BigQueryWriteClient client, WriteStream writeStream, long deadlineMillis) throws Throwable {
LOG.info("Start writing to new stream:" + writeStream.getName());
synchronized (this) {
inflightCount = 0;
successCount = 0;
failureCount = 0;
error = null;
lastMetricsTimeMillis = System.currentTimeMillis();
lastMetricsSuccessCount = 0;
lastMetricsFailureCount = 0;
}
Descriptor descriptor = BQTableSchemaToProtoDescriptor.convertBQTableSchemaToProtoDescriptor(writeStream.getTableSchema());
ProtoSchema protoSchema = ProtoSchemaConverter.convert(descriptor);
try (StreamWriter writer = StreamWriter.newBuilder(writeStream.getName()).setWriterSchema(protoSchema).setTraceId("SAMPLE:parallel_append").build()) {
while (System.currentTimeMillis() < deadlineMillis) {
synchronized (this) {
if (error != null) {
// Stop writing once we get an error.
throw error;
}
}
ApiFuture<AppendRowsResponse> future = writer.append(createAppendRows(descriptor), -1);
synchronized (this) {
inflightCount++;
}
ApiFutures.addCallback(future, new AppendCompleteCallback(this), MoreExecutors.directExecutor());
}
}
}
Aggregations