diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/ConnectionWorker.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/ConnectionWorker.java index 3d713fd914..1aeb911943 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/ConnectionWorker.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/ConnectionWorker.java @@ -21,7 +21,7 @@ import com.google.api.gax.rpc.FixedHeaderProvider; import com.google.auto.value.AutoValue; import com.google.cloud.bigquery.storage.v1.AppendRowsRequest.ProtoData; -import com.google.cloud.bigquery.storage.v1.Exceptions.AppendSerializtionError; +import com.google.cloud.bigquery.storage.v1.Exceptions.AppendSerializationError; import com.google.cloud.bigquery.storage.v1.StreamConnection.DoneCallback; import com.google.cloud.bigquery.storage.v1.StreamConnection.RequestCallback; import com.google.common.annotations.VisibleForTesting; @@ -901,8 +901,8 @@ private void requestCallback(AppendRowsResponse response) { rowIndexToErrorMessage.put( Math.toIntExact(rowError.getIndex()), rowError.getMessage()); } - AppendSerializtionError exception = - new AppendSerializtionError( + AppendSerializationError exception = + new AppendSerializationError( response.getError().getCode(), response.getError().getMessage(), streamName, diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/Exceptions.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/Exceptions.java index 4bc0d97e0f..8e13121414 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/Exceptions.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/Exceptions.java @@ -216,10 +216,8 @@ public static StorageException toStorageException(Throwable exception) { } /** - * This exception is thrown from {@link JsonStreamWriter#append()} when the client side Json to - * Proto serializtion fails. It can also be thrown by the server in case rows contains invalid - * data. The exception contains a Map of indexes of faulty rows and the corresponding error - * message. + * This class has a typo in the name. It will be removed soon. Please use {@link + * AppendSerializationError} */ public static class AppendSerializtionError extends StatusRuntimeException { private final Map rowIndexToErrorMessage; @@ -244,6 +242,23 @@ public String getStreamName() { } } + /** + * This exception is thrown from {@link JsonStreamWriter#append()} when the client side Json to + * Proto serializtion fails. It can also be thrown by the server in case rows contains invalid + * data. The exception contains a Map of indexes of faulty rows and the corresponding error + * message. + */ + public static class AppendSerializationError extends AppendSerializtionError { + + public AppendSerializationError( + int codeValue, + String description, + String streamName, + Map rowIndexToErrorMessage) { + super(codeValue, description, streamName, rowIndexToErrorMessage); + } + } + /** This exception is used internally to handle field level parsing errors. */ public static class FieldParseError extends IllegalArgumentException { private final String fieldName; diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java index edf40c1e64..415830d6ec 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java @@ -20,7 +20,7 @@ import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.core.ExecutorProvider; import com.google.api.gax.rpc.TransportChannelProvider; -import com.google.cloud.bigquery.storage.v1.Exceptions.AppendSerializtionError; +import com.google.cloud.bigquery.storage.v1.Exceptions.AppendSerializationError; import com.google.common.base.Preconditions; import com.google.protobuf.Descriptors; import com.google.protobuf.Descriptors.Descriptor; @@ -194,7 +194,8 @@ public ApiFuture append(JSONArray jsonArr, long offset) // Any error in convertJsonToProtoMessage will throw an // IllegalArgumentException/IllegalStateException/NullPointerException. // IllegalArgumentException will be collected into a Map of row indexes to error messages. - // After the conversion is finished an AppendSerializtionError exception that contains all the + // After the conversion is finished an AppendSerializationError exception that contains all + // the // conversion errors will be thrown. long currentRequestSize = 0; Map rowIndexToErrorMessage = new HashMap<>(); @@ -224,7 +225,7 @@ public ApiFuture append(JSONArray jsonArr, long offset) } if (!rowIndexToErrorMessage.isEmpty()) { - throw new AppendSerializtionError( + throw new AppendSerializationError( Code.INVALID_ARGUMENT.getNumber(), "Append serialization failed for writer: " + streamName, streamName, diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriterTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriterTest.java index a748678839..50532b1e0a 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriterTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriterTest.java @@ -36,7 +36,7 @@ import com.google.cloud.bigquery.storage.test.Test.RepetitionType; import com.google.cloud.bigquery.storage.test.Test.UpdatedFooType; import com.google.cloud.bigquery.storage.v1.ConnectionWorkerPool.Settings; -import com.google.cloud.bigquery.storage.v1.Exceptions.AppendSerializtionError; +import com.google.cloud.bigquery.storage.v1.Exceptions.AppendSerializationError; import com.google.cloud.bigquery.storage.v1.TableFieldSchema.Mode; import com.google.protobuf.ByteString; import com.google.protobuf.Descriptors.DescriptorValidationException; @@ -1096,7 +1096,7 @@ public void testWithoutIgnoreUnknownFieldsUpdateFail() throws Exception { try { ApiFuture appendFuture = writer.append(jsonArr); Assert.fail("expected ExecutionException"); - } catch (AppendSerializtionError ex) { + } catch (AppendSerializationError ex) { assertEquals( "JSONObject has fields unknown to BigQuery: root.test_unknown.", ex.getRowIndexToErrorMessage().get(1)); @@ -1188,7 +1188,7 @@ public void testFlowControlSettingNoLimitBehavior() throws Exception { } @Test - public void testMultipleAppendSerializtionErrors() + public void testMultipleAppendSerializationErrors() throws DescriptorValidationException, IOException, InterruptedException { FooType expectedProto = FooType.newBuilder().setFoo("allen").build(); JSONObject foo = new JSONObject(); @@ -1213,10 +1213,10 @@ public void testMultipleAppendSerializtionErrors() getTestJsonStreamWriterBuilder(TEST_STREAM, TABLE_SCHEMA).build()) { try { ApiFuture appendFuture = writer.append(jsonArr); - Assert.fail("expected AppendSerializtionError"); - } catch (AppendSerializtionError appendSerializtionError) { + Assert.fail("expected AppendSerializationError"); + } catch (AppendSerializationError appendSerializationError) { Map rowIndexToErrorMessage = - appendSerializtionError.getRowIndexToErrorMessage(); + appendSerializationError.getRowIndexToErrorMessage(); assertEquals(2, rowIndexToErrorMessage.size()); assertEquals( "JSONObject has fields unknown to BigQuery: root.not_foo.", @@ -1253,10 +1253,10 @@ public void testBadStringToNumericRowError() getTestJsonStreamWriterBuilder(TEST_STREAM, TABLE_SCHEMA).build()) { try { ApiFuture appendFuture = writer.append(jsonArr); - Assert.fail("expected AppendSerializtionError"); - } catch (AppendSerializtionError appendSerializtionError) { + Assert.fail("expected AppendSerializationError"); + } catch (AppendSerializationError appendSerializationError) { Map rowIndexToErrorMessage = - appendSerializtionError.getRowIndexToErrorMessage(); + appendSerializationError.getRowIndexToErrorMessage(); assertEquals(1, rowIndexToErrorMessage.size()); assertTrue( rowIndexToErrorMessage diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java index 6972813e20..c80bb960ac 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java @@ -28,7 +28,7 @@ import com.google.cloud.bigquery.Schema; import com.google.cloud.bigquery.storage.test.Test.*; import com.google.cloud.bigquery.storage.v1.*; -import com.google.cloud.bigquery.storage.v1.Exceptions.AppendSerializtionError; +import com.google.cloud.bigquery.storage.v1.Exceptions.AppendSerializationError; import com.google.cloud.bigquery.storage.v1.Exceptions.OffsetAlreadyExists; import com.google.cloud.bigquery.storage.v1.Exceptions.OffsetOutOfRange; import com.google.cloud.bigquery.storage.v1.Exceptions.SchemaMismatchedException; @@ -372,8 +372,8 @@ public void testRowErrors() } catch (Throwable t) { assertTrue(t instanceof ExecutionException); t = t.getCause(); - assertTrue(t instanceof AppendSerializtionError); - AppendSerializtionError e = (AppendSerializtionError) t; + assertTrue(t instanceof AppendSerializationError); + AppendSerializationError e = (AppendSerializationError) t; LOG.info("Found row errors on stream: " + e.getStreamName()); assertEquals( "Field foo: STRING(10) has maximum length 10 but got a value with length 12 on field foo.", diff --git a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java index f5f357238a..8bd384c325 100644 --- a/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java +++ b/samples/snippets/src/main/java/com/example/bigquerystorage/WriteToDefaultStream.java @@ -28,7 +28,7 @@ import com.google.cloud.bigquery.storage.v1.AppendRowsResponse; import com.google.cloud.bigquery.storage.v1.BigQueryWriteClient; import com.google.cloud.bigquery.storage.v1.Exceptions; -import com.google.cloud.bigquery.storage.v1.Exceptions.AppendSerializtionError; +import com.google.cloud.bigquery.storage.v1.Exceptions.AppendSerializationError; import com.google.cloud.bigquery.storage.v1.Exceptions.StorageException; import com.google.cloud.bigquery.storage.v1.JsonStreamWriter; import com.google.cloud.bigquery.storage.v1.TableName; @@ -218,8 +218,8 @@ public void onFailure(Throwable throwable) { } } - if (throwable instanceof AppendSerializtionError) { - AppendSerializtionError ase = (AppendSerializtionError) throwable; + if (throwable instanceof AppendSerializationError) { + AppendSerializationError ase = (AppendSerializationError) throwable; Map rowIndexToErrorMessage = ase.getRowIndexToErrorMessage(); if (rowIndexToErrorMessage.size() > 0) { // Omit the faulty rows