public class JsonStreamWriter implements AutoCloseable
A StreamWriter that can write JSON data (JSONObjects) to BigQuery tables. The JsonStreamWriter is built on top of a StreamWriter, and it simply converts all JSON data to protobuf messages then calls StreamWriter's append() method to write to BigQuery tables. It maintains all StreamWriter functions, but also provides an additional feature: schema update support, where if the BigQuery table schema is updated, users will be able to ingest data on the new schema after some time (in order of minutes).
Implements
AutoCloseableStatic Methods
newBuilder(String streamOrTableName, TableSchema tableSchema)
public static JsonStreamWriter.Builder newBuilder(String streamOrTableName, TableSchema tableSchema)
newBuilder that constructs a JsonStreamWriter builder with BigQuery client being initialized by StreamWriter by default.
Name | Description |
streamOrTableName | String name of the stream that must follow "projects/[^/]+/datasets/[^/]+/tables/[^/]+/streams/[^/]+" or table name "projects/[^/]+/datasets/[^/]+/tables/[^/]+" |
tableSchema | TableSchema The schema of the table when the stream was created, which is passed back
through |
Type | Description |
JsonStreamWriter.Builder | Builder |
newBuilder(String streamOrTableName, TableSchema tableSchema, BigQueryWriteClient client)
public static JsonStreamWriter.Builder newBuilder(String streamOrTableName, TableSchema tableSchema, BigQueryWriteClient client)
newBuilder that constructs a JsonStreamWriter builder.
Name | Description |
streamOrTableName | String name of the stream that must follow "projects/[^/]+/datasets/[^/]+/tables/[^/]+/streams/[^/]+" |
tableSchema | TableSchema The schema of the table when the stream was created, which is passed back
through |
client | BigQueryWriteClient |
Type | Description |
JsonStreamWriter.Builder | Builder |
Methods
append(JSONArray jsonArr)
public ApiFuture<AppendRowsResponse> append(JSONArray jsonArr)
Writes a JSONArray that contains JSONObjects to the BigQuery table by first converting the JSON data to protobuf messages, then using StreamWriter's append() to write the data at current end of stream. If there is a schema update, the current StreamWriter is closed. A new StreamWriter is created with the updated TableSchema.
Name | Description |
jsonArr | org.json.JSONArray The JSON array that contains JSONObjects to be written |
Type | Description |
ApiFuture<AppendRowsResponse> | ApiFuture<AppendRowsResponse> returns an AppendRowsResponse message wrapped in an ApiFuture |
Type | Description |
IOException | |
DescriptorValidationException |
append(JSONArray jsonArr, long offset)
public ApiFuture<AppendRowsResponse> append(JSONArray jsonArr, long offset)
Writes a JSONArray that contains JSONObjects to the BigQuery table by first converting the JSON data to protobuf messages, then using StreamWriter's append() to write the data at the specified offset. If there is a schema update, the current StreamWriter is closed. A new StreamWriter is created with the updated TableSchema.
Name | Description |
jsonArr | org.json.JSONArray The JSON array that contains JSONObjects to be written |
offset | long Offset for deduplication |
Type | Description |
ApiFuture<AppendRowsResponse> | ApiFuture<AppendRowsResponse> returns an AppendRowsResponse message wrapped in an ApiFuture |
Type | Description |
IOException | |
DescriptorValidationException |
close()
public void close()
Closes the underlying StreamWriter.
getDescriptor()
public Descriptors.Descriptor getDescriptor()
Gets current descriptor
Type | Description |
Descriptor | Descriptor |
getInflightWaitSeconds()
public long getInflightWaitSeconds()
Returns the wait of a request in Client side before sending to the Server. Request could wait in Client because it reached the client side inflight request limit (adjustable when constructing the Writer). The value is the wait time for the last sent request. A constant high wait value indicates a need for more throughput, you can create a new Stream for to increase the throughput in exclusive stream case, or create a new Writer in the default stream case.
Type | Description |
long |
getStreamName()
public String getStreamName()
Gets streamName
Type | Description |
String | String |