public class StreamWriter extends Object implements AutoCloseable
TODO: Support batching.
| Modifier and Type | Class and Description |
|---|---|
static class |
StreamWriter.Builder
A builder of
StreamWriters. |
| Modifier and Type | Method and Description |
|---|---|
com.google.api.core.ApiFuture<AppendRowsResponse> |
append(ProtoRows rows)
Schedules the writing of rows at the end of current stream.
|
com.google.api.core.ApiFuture<AppendRowsResponse> |
append(ProtoRows rows,
long offset)
Schedules the writing of rows at given offset.
|
void |
close()
Close the stream writer.
|
static long |
getApiMaxRequestBytes()
The maximum size of one request.
|
long |
getInflightWaitSeconds()
Returns the wait of a request in Client side before sending to the Server.
|
String |
getStreamName() |
TableSchema |
getUpdatedSchema()
Thread-safe getter of updated TableSchema
|
String |
getWriterId() |
static StreamWriter.Builder |
newBuilder(String streamName)
Constructs a new
StreamWriterV2.Builder using the given stream. |
static StreamWriter.Builder |
newBuilder(String streamName,
BigQueryWriteClient client)
Constructs a new
StreamWriterV2.Builder using the given stream and client. |
public static long getApiMaxRequestBytes()
public com.google.api.core.ApiFuture<AppendRowsResponse> append(ProtoRows rows)
rows - the rows in serialized format to write to BigQuery.public com.google.api.core.ApiFuture<AppendRowsResponse> append(ProtoRows rows, long offset)
Example of writing rows with specific offset.
ApiFuture<AppendRowsResponse> future = writer.append(rows, 0);
ApiFutures.addCallback(future, new ApiFutureCallback<AppendRowsResponse>() {
public void onSuccess(AppendRowsResponse response) {
if (!response.hasError()) {
System.out.println("written with offset: " + response.getAppendResult().getOffset());
} else {
System.out.println("received an in stream error: " + response.getError().toString());
}
}
public void onFailure(Throwable t) {
System.out.println("failed to write: " + t);
}
}, MoreExecutors.directExecutor());
rows - the rows in serialized format to write to BigQuery.offset - the offset of the first row. Provide -1 to write at the current end of stream.public long getInflightWaitSeconds()
public String getWriterId()
public String getStreamName()
public void close()
close in interface AutoCloseablepublic static StreamWriter.Builder newBuilder(String streamName, BigQueryWriteClient client)
StreamWriterV2.Builder using the given stream and client. AppendRows
needs special headers to be added to client, so a passed in client will not work. This should
be used by test only.public static StreamWriter.Builder newBuilder(String streamName)
StreamWriterV2.Builder using the given stream.public TableSchema getUpdatedSchema()
Copyright © 2022 Google LLC. All rights reserved.