|
24 | 24 | import com.google.cloud.bigquery.BigQuery;
|
25 | 25 | import com.google.cloud.bigquery.BigQueryOptions;
|
26 | 26 | import com.google.cloud.bigquery.QueryJobConfiguration;
|
27 |
| -import com.google.cloud.bigquery.Schema; |
28 |
| -import com.google.cloud.bigquery.Table; |
29 | 27 | import com.google.cloud.bigquery.TableResult;
|
30 | 28 | import com.google.cloud.bigquery.storage.v1.AppendRowsResponse;
|
| 29 | +import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient; |
31 | 30 | import com.google.cloud.bigquery.storage.v1.Exceptions;
|
32 | 31 | import com.google.cloud.bigquery.storage.v1.Exceptions.AppendSerializtionError;
|
33 | 32 | import com.google.cloud.bigquery.storage.v1.Exceptions.StorageException;
|
34 | 33 | import com.google.cloud.bigquery.storage.v1.JsonStreamWriter;
|
35 | 34 | import com.google.cloud.bigquery.storage.v1.TableName;
|
36 |
| -import com.google.cloud.bigquery.storage.v1.TableSchema; |
37 | 35 | import com.google.common.collect.ImmutableList;
|
38 | 36 | import com.google.common.util.concurrent.MoreExecutors;
|
39 | 37 | import com.google.protobuf.Descriptors.DescriptorValidationException;
|
@@ -146,17 +144,12 @@ private static class DataWriter {
|
146 | 144 |
|
147 | 145 | public void initialize(TableName parentTable)
|
148 | 146 | throws DescriptorValidationException, IOException, InterruptedException {
|
149 |
| - // Retrive table schema information. |
150 |
| - BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); |
151 |
| - Table table = bigquery.getTable(parentTable.getDataset(), parentTable.getTable()); |
152 |
| - Schema schema = table.getDefinition().getSchema(); |
153 |
| - TableSchema tableSchema = BqToBqStorageSchemaConverter.convertTableSchema(schema); |
154 |
| - |
155 | 147 | // Use the JSON stream writer to send records in JSON format. Specify the table name to write
|
156 | 148 | // to the default stream.
|
157 | 149 | // For more information about JsonStreamWriter, see:
|
158 | 150 | // https://googleapis.dev/java/google-cloud-bigquerystorage/latest/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.html
|
159 |
| - streamWriter = JsonStreamWriter.newBuilder(parentTable.toString(), tableSchema).build(); |
| 151 | + streamWriter = |
| 152 | + JsonStreamWriter.newBuilder(parentTable.toString(), BigQueryWriteClient.create()).build(); |
160 | 153 | }
|
161 | 154 |
|
162 | 155 | public void append(AppendContext appendContext)
|
|
0 commit comments