public class StreamWriter extends Object implements AutoCloseable
TODO: Support batching.
| Modifier and Type | Class and Description |
|---|---|
static class |
StreamWriter.Builder
A builder of
StreamWriters. |
static class |
StreamWriter.SingleConnectionOrConnectionPool
When in single table mode, append directly to connectionWorker.
|
| 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 |
getLocation() |
ProtoSchema |
getProtoSchema() |
String |
getStreamName() |
TableSchema |
getUpdatedSchema()
Thread-safe getter of updated TableSchema.
|
String |
getWriterId() |
boolean |
isClosed() |
boolean |
isUserClosed() |
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 ProtoSchema getProtoSchema()
public String getLocation()
public boolean isClosed()
public boolean isUserClosed()
public void close()
close in interface AutoCloseablepublic static StreamWriter.Builder newBuilder(String streamName, BigQueryWriteClient client)
StreamWriterV2.Builder using the given stream and client.public static StreamWriter.Builder newBuilder(String streamName)
StreamWriterV2.Builder using the given stream.public TableSchema getUpdatedSchema()
This will return the updated schema only when the creation timestamp of this writer is older than the updated schema.
Copyright © 2023 Google LLC. All rights reserved.