GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: provide append() methods that accept com.google.gson objects by agrawal-siddharth · Pull Request #2985 · googleapis/java-bigquerystorage

This repository was archived by the owner on Feb 24, 2026. It is now read-only.

feat: provide append() methods that accept com.google.gson objects #2985

Merged
yirutang merged 1 commit into googleapis:main from agrawal-siddharth:use_gson
May 28, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

feat: provide append() methods that accept com.google.gson objects #2985

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
595e438
feat: provide append() methods that accept com.google.gson objects
agrawal-siddharth May 27, 2025
File filter
Filter by extension


Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

5 changes: 5 additions & 0 deletions 5 google-cloud-bigquerystorage/pom.xml
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-bigquerystorage-v1</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
36 changes: 36 additions & 0 deletions 36 ...-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.api.gax.core.ExecutorProvider;
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.gson.JsonArray;
import com.google.protobuf.Descriptors;
import java.io.IOException;
import java.time.Duration;
Expand Down Expand Up @@ -83,6 +84,41 @@ public ApiFuture<AppendRowsResponse> append(JSONArray jsonArr, long offset)
return this.schemaAwareStreamWriter.append(jsonArr, offset);
}

private JSONArray gsonToOrgJSON(JsonArray jsonArr) {
return new JSONArray(jsonArr.toString());
}

/**
* Writes a JsonArray that contains JsonObjects to the BigQuery table by first converting the JSON
* data to protobuf messages, then using StreamWriter's append() to write the data at current end
* of stream. If there is a schema update, the current StreamWriter is closed. A new StreamWriter
* is created with the updated TableSchema.
*
* @param jsonArr The JSON array that contains JsonObjects to be written
* @return {@code ApiFuture<AppendRowsResponse>} returns an AppendRowsResponse message wrapped in
* an ApiFuture
*/
public ApiFuture<AppendRowsResponse> append(JsonArray jsonArr)
throws IOException, Descriptors.DescriptorValidationException {
return this.append(jsonArr, -1);
}

/**
* Writes a JsonArray that contains JsonObjects to the BigQuery table by first converting the JSON
* data to protobuf messages, then using StreamWriter's append() to write the data at the
* specified offset. If there is a schema update, the current StreamWriter is closed. A new
* StreamWriter is created with the updated TableSchema.
*
* @param jsonArr The JSON array that contains JSONObjects to be written
* @param offset Offset for deduplication
* @return {@code ApiFuture<AppendRowsResponse>} returns an AppendRowsResponse message wrapped in
* an ApiFuture
*/
public ApiFuture<AppendRowsResponse> append(JsonArray jsonArr, long offset)
throws IOException, Descriptors.DescriptorValidationException {
return this.append(gsonToOrgJSON(jsonArr), offset);
}

public String getStreamName() {
return this.schemaAwareStreamWriter.getStreamName();
}
Expand Down
45 changes: 45 additions & 0 deletions 45 ...querystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriterTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import com.google.cloud.bigquery.storage.v1.Exceptions.AppendSerializationError;
import com.google.cloud.bigquery.storage.v1.TableFieldSchema.Mode;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.protobuf.ByteString;
import com.google.protobuf.Descriptors.DescriptorValidationException;
import com.google.protobuf.Int64Value;
Expand Down Expand Up @@ -251,6 +253,49 @@ public void testSingleAppendSimpleJson() throws Exception {
}
}

@Test
public void testSingleAppendSimpleGson() throws Exception {
FooType expectedProto = FooType.newBuilder().setFoo("allen").build();
JsonObject foo = new JsonObject();
foo.addProperty("foo", "allen");
JsonArray jsonArr = new JsonArray();
jsonArr.add(foo);

try (JsonStreamWriter writer =
getTestJsonStreamWriterBuilder(TEST_STREAM, TABLE_SCHEMA)
.setTraceId("test:empty")
.build()) {

testBigQueryWrite.addResponse(
AppendRowsResponse.newBuilder()
.setAppendResult(
AppendRowsResponse.AppendResult.newBuilder().setOffset(Int64Value.of(0)).build())
.build());

ApiFuture<AppendRowsResponse> appendFuture = writer.append(jsonArr);
assertEquals(0L, appendFuture.get().getAppendResult().getOffset().getValue());
appendFuture.get();
assertEquals(
1,
testBigQueryWrite
.getAppendRequests()
.get(0)
.getProtoRows()
.getRows()
.getSerializedRowsCount());
assertEquals(
testBigQueryWrite
.getAppendRequests()
.get(0)
.getProtoRows()
.getRows()
.getSerializedRows(0),
expectedProto.toByteString());
assertEquals(
"java-jsonwriter test:empty", testBigQueryWrite.getAppendRequests().get(0).getTraceId());
}
}

@Test
public void testFlexibleColumnAppend() throws Exception {
TableFieldSchema field =
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.