This repository was archived by the owner on Feb 24, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 87
chore: add sample demonstrating sending a nested proto #2945
Merged
agrawal-siddharth
merged 1 commit into
googleapis:main
from
agrawal-siddharth:nested_message
Apr 25, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
samples/snippets/src/main/java/com/example/bigquerystorage/WriteNestedProto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.example.bigquerystorage; | ||
|
|
||
| // [START bigquerystorage_writenestedproto] | ||
| import com.google.api.core.ApiFuture; | ||
| import com.google.cloud.bigquery.storage.v1.AppendRowsResponse; | ||
| import com.google.cloud.bigquery.storage.v1.ProtoRows; | ||
| import com.google.cloud.bigquery.storage.v1.ProtoSchemaConverter; | ||
| import com.google.cloud.bigquery.storage.v1.StreamWriter; | ||
| import com.google.protobuf.Descriptors.DescriptorValidationException; | ||
| import java.io.IOException; | ||
| import java.util.concurrent.ExecutionException; | ||
|
|
||
| public class WriteNestedProto { | ||
|
|
||
| public static void runWriteNestedProto(String projectId, String datasetName, String tableName) | ||
| throws DescriptorValidationException, InterruptedException, IOException { | ||
| StreamWriter streamWriter = | ||
| StreamWriter.newBuilder( | ||
| "projects/" | ||
| + projectId | ||
| + "/datasets/" | ||
| + datasetName | ||
| + "/tables/" | ||
| + tableName | ||
| + "/_default") | ||
| .setWriterSchema(ProtoSchemaConverter.convert(HasNestedMessage.getDescriptor())) | ||
| .build(); | ||
| ProtoRows protoRows = | ||
| ProtoRows.newBuilder() | ||
| .addSerializedRows( | ||
| HasNestedMessage.newBuilder() | ||
| .setFoo("foo") | ||
| .setBar( | ||
| HasNestedMessage.InnerMessage.newBuilder() | ||
| .setMyInt(12345) | ||
| .setMyString("bar") | ||
| .build()) | ||
| .build() | ||
| .toByteString()) | ||
| .addSerializedRows( | ||
| HasSeparateNestedMessage.newBuilder() | ||
| .setFoo("foo2") | ||
| .setBar( | ||
| SeparateMessage.newBuilder().setMyInt(123456).setMyString("bar2").build()) | ||
| .build() | ||
| .toByteString()) | ||
| .build(); | ||
| ApiFuture<AppendRowsResponse> future = streamWriter.append(protoRows); | ||
| try { | ||
| AppendRowsResponse response = future.get(); | ||
| System.out.println("Appended records successfully."); | ||
| } catch (ExecutionException e) { | ||
| System.out.println(e); | ||
| } | ||
| } | ||
| } | ||
| // [END bigquerystorage_writenestedproto] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| syntax = "proto3"; | ||
| package nestedprotos; | ||
|
|
||
| import "separate.proto"; | ||
|
|
||
| option java_multiple_files = true; | ||
| option java_package = "com.example.bigquerystorage"; | ||
| option java_outer_classname = "NestedProtos"; | ||
|
|
||
| message HasNestedMessage { | ||
| optional string foo = 1; | ||
|
|
||
| message InnerMessage { | ||
| optional int64 my_int = 1; | ||
| optional string my_string = 2; | ||
| } | ||
|
|
||
| optional InnerMessage bar = 2; | ||
| } | ||
|
|
||
| message HasSeparateNestedMessage { | ||
| optional string foo = 1; | ||
| optional SeparateMessage bar = 2; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| syntax = "proto3"; | ||
| package nestedprotos; | ||
|
|
||
| option java_multiple_files = true; | ||
| option java_package = "com.example.bigquerystorage"; | ||
| option java_outer_classname = "SeparateProtos"; | ||
|
|
||
| message SeparateMessage { | ||
| optional int64 my_int = 1; | ||
| optional string my_string = 2; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.