Class 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.
    • 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 written
        offset - 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 through WriteStream
        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 through WriteStream
        client -
        Returns:
        Builder
      • close

        public void close()
        Closes the underlying StreamWriter.
        Specified by:
        close in interface AutoCloseable