2121import com .google .api .gax .core .ExecutorProvider ;
2222import com .google .api .gax .retrying .RetrySettings ;
2323import com .google .api .gax .rpc .TransportChannelProvider ;
24+ import com .google .gson .JsonArray ;
2425import com .google .protobuf .Descriptors ;
2526import java .io .IOException ;
2627import java .time .Duration ;
@@ -45,9 +46,7 @@ public class JsonStreamWriter implements AutoCloseable {
4546 * @param builder The Builder object for the JsonStreamWriter
4647 */
4748 private JsonStreamWriter (SchemaAwareStreamWriter .Builder <Object > builder )
48- throws Descriptors .DescriptorValidationException ,
49- IllegalArgumentException ,
50- IOException ,
49+ throws Descriptors .DescriptorValidationException , IllegalArgumentException , IOException ,
5150 InterruptedException {
5251 this .schemaAwareStreamWriter = builder .build ();
5352 }
@@ -83,13 +82,46 @@ public ApiFuture<AppendRowsResponse> append(JSONArray jsonArr, long offset)
8382 return this .schemaAwareStreamWriter .append (jsonArr , offset );
8483 }
8584
86- public String getStreamName () {
87- return this .schemaAwareStreamWriter .getStreamName ();
85+ private JSONArray gsonToOrgJSON (JsonArray jsonArr ) {
86+ return new JSONArray (jsonArr .toString ());
87+ }
88+
89+ /**
90+ * Writes a JsonArray that contains JsonObjects to the BigQuery table by first converting the JSON
91+ * data to protobuf messages, then using StreamWriter's append() to write the data at current end
92+ * of stream. If there is a schema update, the current StreamWriter is closed. A new StreamWriter
93+ * is created with the updated TableSchema.
94+ *
95+ * @param jsonArr The JSON array that contains JsonObjects to be written
96+ * @return {@code ApiFuture<AppendRowsResponse>} returns an AppendRowsResponse message wrapped in
97+ * an ApiFuture
98+ */
99+ public ApiFuture <AppendRowsResponse > append (JsonArray jsonArr )
100+ throws IOException , Descriptors .DescriptorValidationException {
101+ return this .append (jsonArr , -1 );
88102 }
89103
90104 /**
91- * @return A unique Id for this writer.
105+ * Writes a JsonArray that contains JsonObjects to the BigQuery table by first converting the JSON
106+ * data to protobuf messages, then using StreamWriter's append() to write the data at the
107+ * specified offset. If there is a schema update, the current StreamWriter is closed. A new
108+ * StreamWriter is created with the updated TableSchema.
109+ *
110+ * @param jsonArr The JSON array that contains JSONObjects to be written
111+ * @param offset Offset for deduplication
112+ * @return {@code ApiFuture<AppendRowsResponse>} returns an AppendRowsResponse message wrapped in
113+ * an ApiFuture
92114 */
115+ public ApiFuture <AppendRowsResponse > append (JsonArray jsonArr , long offset )
116+ throws IOException , Descriptors .DescriptorValidationException {
117+ return this .append (gsonToOrgJSON (jsonArr ), offset );
118+ }
119+
120+ public String getStreamName () {
121+ return this .schemaAwareStreamWriter .getStreamName ();
122+ }
123+
124+ /** @return A unique Id for this writer. */
93125 public String getWriterId () {
94126 return this .schemaAwareStreamWriter .getWriterId ();
95127 }
0 commit comments