From d58a3146458a4593876e1bb62d3c2b6d0bfb1c05 Mon Sep 17 00:00:00 2001 From: Siddharth Agrawal Date: Thu, 7 Mar 2024 16:46:40 -0800 Subject: [PATCH] Fix: accept default stream name (#2432) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: accept default stream name * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot --- README.md | 2 +- .../com/google/cloud/bigquery/storage/v1/Exceptions.java | 3 +++ .../bigquery/storage/v1/SchemaAwareStreamWriter.java | 2 ++ .../cloud/bigquery/storage/v1/JsonStreamWriterTest.java | 9 +++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3171e5e6f5..72c58d3d6a 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ If you are using Maven without the BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.33.0') +implementation platform('com.google.cloud:libraries-bom:26.34.0') implementation 'com.google.cloud:google-cloud-bigquerystorage' ``` 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 2738e10d45..51662755ae 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 @@ -150,6 +150,9 @@ private static StorageError toStorageError(com.google.rpc.Status rpcStatus) { @Nullable public static StorageException toStorageException( com.google.rpc.Status rpcStatus, Throwable exception) { + if (rpcStatus == null) { + return null; + } StorageError error = toStorageError(rpcStatus); Status grpcStatus = Status.fromCodeValue(rpcStatus.getCode()).withDescription(rpcStatus.getMessage()); diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/SchemaAwareStreamWriter.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/SchemaAwareStreamWriter.java index 51df76a06c..c837e2fd74 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/SchemaAwareStreamWriter.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/SchemaAwareStreamWriter.java @@ -467,6 +467,8 @@ private Builder( if (!tableMatcher.matches() && !defaultStreamMatcher.matches()) { throw new IllegalArgumentException("Invalid name: " + streamOrTableName); + } else if (!tableMatcher.matches() && defaultStreamMatcher.matches()) { + this.streamName = streamOrTableName; } else { this.streamName = streamOrTableName + "/_default"; } 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 d3a25510f8..692725d95c 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 @@ -72,6 +72,7 @@ public class JsonStreamWriterTest { private static final String TEST_STREAM = "projects/p/datasets/d/tables/t/streams/_default"; private static final String TEST_STREAM_2 = "projects/p/datasets/d2/tables/t2/streams/_default"; private static final String TEST_TABLE = "projects/p/datasets/d/tables/t"; + private static final String TEST_TABLE_DEFAULT = "projects/p/datasets/d/tables/t/_default"; private static LocalChannelProvider channelProvider; private FakeScheduledExecutorService fakeExecutor; private FakeBigQueryWrite testBigQueryWrite; @@ -198,6 +199,14 @@ public void testTwoParamNewBuilder() assertEquals(TEST_STREAM, writer.getStreamName()); } + @Test + public void testConstructWriterUsingDefaultStreamName() + throws DescriptorValidationException, IOException, InterruptedException { + JsonStreamWriter writer = + getTestJsonStreamWriterBuilder(TEST_TABLE_DEFAULT, TABLE_SCHEMA).build(); + assertEquals(TEST_TABLE_DEFAULT, writer.getStreamName()); + } + @Test public void testSingleAppendSimpleJson() throws Exception { FooType expectedProto = FooType.newBuilder().setFoo("allen").build();