Class JsonStreamWriter
- java.lang.Object
-
- com.google.cloud.bigquery.storage.v1beta2.JsonStreamWriter
-
- All Implemented Interfaces:
AutoCloseable
public class JsonStreamWriter extends Object 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JsonStreamWriter.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.google.api.core.ApiFuture<AppendRowsResponse>
append(org.json.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.com.google.api.core.ApiFuture<AppendRowsResponse>
append(org.json.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.void
close()
Closes the underlying StreamWriter.com.google.protobuf.Descriptors.Descriptor
getDescriptor()
Gets current descriptorString
getStreamName()
Gets streamNamestatic JsonStreamWriter.Builder
newBuilder(String streamOrTableName, TableSchema tableSchema)
newBuilder that constructs a JsonStreamWriter builder with BigQuery client being initialized by StreamWriter by default.static JsonStreamWriter.Builder
newBuilder(String streamOrTableName, TableSchema tableSchema, BigQueryWriteClient client)
newBuilder that constructs a JsonStreamWriter builder.
-
-
-
Method Detail
-
append
public com.google.api.core.ApiFuture<AppendRowsResponse> append(org.json.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.- Parameters:
jsonArr
- The JSON array that contains JSONObjects to be written- Returns:
ApiFuture<AppendRowsResponse>
returns an AppendRowsResponse message wrapped in an ApiFuture
-
append
public com.google.api.core.ApiFuture<AppendRowsResponse> append(org.json.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:
jsonArr
- The JSON array that contains JSONObjects to be writtenoffset
- Offset for deduplication- Returns:
ApiFuture<AppendRowsResponse>
returns an AppendRowsResponse message wrapped in an ApiFuture
-
getStreamName
public String getStreamName()
Gets streamName- Returns:
- String
-
getDescriptor
public com.google.protobuf.Descriptors.Descriptor getDescriptor()
Gets current descriptor- Returns:
- Descriptor
-
newBuilder
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:
streamOrTableName
- name of the stream that must follow "projects/[^/]+/datasets/[^/]+/tables/[^/]+/streams/[^/]+" or table name "projects/[^/]+/datasets/[^/]+/tables/[^/]+"tableSchema
- The schema of the table when the stream was created, which is passed back throughWriteStream
- Returns:
- Builder
-
newBuilder
public static JsonStreamWriter.Builder newBuilder(String streamOrTableName, TableSchema tableSchema, BigQueryWriteClient client)
newBuilder that constructs a JsonStreamWriter builder.- Parameters:
streamOrTableName
- name of the stream that must follow "projects/[^/]+/datasets/[^/]+/tables/[^/]+/streams/[^/]+"tableSchema
- The schema of the table when the stream was created, which is passed back throughWriteStream
client
-- Returns:
- Builder
-
close
public void close()
Closes the underlying StreamWriter.- Specified by:
close
in interfaceAutoCloseable
-
-