Skip to content

Commit

Permalink
Fix: accept default stream name
Browse files Browse the repository at this point in the history
  • Loading branch information
agrawal-siddharth committed Mar 7, 2024
1 parent feeaf04 commit cc02238
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -198,6 +199,14 @@ public void testTwoParamNewBuilder()
assertEquals(TEST_STREAM, writer.getStreamName());
}

@Test
public void testTwoParamNewBuilderDefault()
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();
Expand Down

0 comments on commit cc02238

Please sign in to comment.