Class JsonStreamWriter (2.45.0)

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.

Inheritance

java.lang.Object > JsonStreamWriter

Implements

AutoCloseable

Static 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.

Parameters
NameDescription
streamOrTableNameString

name of the stream that must follow "projects/[^/]+/datasets/[^/]+/tables/[^/]+/streams/[^/]+" or table name "projects/[^/]+/datasets/[^/]+/tables/[^/]+"

tableSchemaTableSchema

The schema of the table when the stream was created, which is passed back through WriteStream

Returns
TypeDescription
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.

Parameters
NameDescription
streamOrTableNameString

name of the stream that must follow "projects/[^/]+/datasets/[^/]+/tables/[^/]+/streams/[^/]+"

tableSchemaTableSchema

The schema of the table when the stream was created, which is passed back through WriteStream

clientBigQueryWriteClient
Returns
TypeDescription
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.

Parameter
NameDescription
jsonArrorg.json.JSONArray

The JSON array that contains JSONObjects to be written

Returns
TypeDescription
ApiFuture<AppendRowsResponse>

ApiFuture<AppendRowsResponse> returns an AppendRowsResponse message wrapped in an ApiFuture

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.

Parameters
NameDescription
jsonArrorg.json.JSONArray

The JSON array that contains JSONObjects to be written

offsetlong

Offset for deduplication

Returns
TypeDescription
ApiFuture<AppendRowsResponse>

ApiFuture<AppendRowsResponse> returns an AppendRowsResponse message wrapped in an ApiFuture

close()

public void close()

Closes the underlying StreamWriter.

getDescriptor()

public Descriptors.Descriptor getDescriptor()

Gets current descriptor

Returns
TypeDescription
Descriptor

Descriptor

getStreamName()

public String getStreamName()

Gets streamName

Returns
TypeDescription
String

String