Skip to content

Commit 6b37a95

Browse files
authored
feat(write): Support Arrow format for Write API (#3086)
1 parent 69685e5 commit 6b37a95

File tree

11 files changed

+1062
-66
lines changed

11 files changed

+1062
-66
lines changed

google-cloud-bigquerystorage/pom.xml

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@
1616
<properties>
1717
<site.installationModule>google-cloud-bigquerystorage</site.installationModule>
1818
</properties>
19+
<dependencyManagement>
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.apache.arrow</groupId>
23+
<artifactId>arrow-vector</artifactId>
24+
<version>17.0.0</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.apache.arrow</groupId>
28+
<artifactId>arrow-memory-core</artifactId>
29+
<version>17.0.0</version>
30+
</dependency>
31+
</dependencies>
32+
</dependencyManagement>
1933
<build>
2034
<extensions>
2135
<extension>
@@ -63,10 +77,6 @@
6377
<groupId>io.grpc</groupId>
6478
<artifactId>grpc-util</artifactId>
6579
</dependency>
66-
<dependency>
67-
<groupId>io.grpc</groupId>
68-
<artifactId>grpc-util</artifactId>
69-
</dependency>
7080
<dependency>
7181
<groupId>com.google.api</groupId>
7282
<artifactId>api-common</artifactId>
@@ -148,11 +158,11 @@
148158
<dependency>
149159
<groupId>org.json</groupId>
150160
<artifactId>json</artifactId>
151-
</dependency>
152-
<dependency>
153-
<groupId>com.google.auth</groupId>
154-
<artifactId>google-auth-library-credentials</artifactId>
155-
</dependency>
161+
</dependency>
162+
<dependency>
163+
<groupId>com.google.auth</groupId>
164+
<artifactId>google-auth-library-credentials</artifactId>
165+
</dependency>
156166
<dependency>
157167
<groupId>io.opentelemetry</groupId>
158168
<artifactId>opentelemetry-api</artifactId>
@@ -161,6 +171,10 @@
161171
<groupId>io.opentelemetry</groupId>
162172
<artifactId>opentelemetry-context</artifactId>
163173
</dependency>
174+
<dependency>
175+
<groupId>org.apache.arrow</groupId>
176+
<artifactId>arrow-vector</artifactId>
177+
</dependency>
164178

165179
<!-- Test dependencies -->
166180
<dependency>
@@ -195,10 +209,10 @@
195209
<version>1.4.4</version>
196210
<scope>test</scope>
197211
<exclusions>
198-
<exclusion>
199-
<groupId>org.checkerframework</groupId>
200-
<artifactId>checker-qual</artifactId>
201-
</exclusion>
212+
<exclusion>
213+
<groupId>org.checkerframework</groupId>
214+
<artifactId>checker-qual</artifactId>
215+
</exclusion>
202216
</exclusions>
203217
</dependency>
204218
<dependency>
@@ -213,11 +227,6 @@
213227
<version>1.11.4</version>
214228
<scope>test</scope>
215229
</dependency>
216-
<dependency>
217-
<groupId>org.apache.arrow</groupId>
218-
<artifactId>arrow-vector</artifactId>
219-
<scope>test</scope>
220-
</dependency>
221230
<dependency>
222231
<groupId>org.apache.arrow</groupId>
223232
<artifactId>arrow-memory-core</artifactId>
@@ -243,6 +252,10 @@
243252
<groupId>com.google.code.findbugs</groupId>
244253
<artifactId>jsr305</artifactId>
245254
</dependency>
255+
<dependency>
256+
<groupId>com.google.errorprone</groupId>
257+
<artifactId>error_prone_annotations</artifactId>
258+
</dependency>
246259
<dependency>
247260
<groupId>com.google.cloud</groupId>
248261
<artifactId>google-cloud-core</artifactId>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.bigquery.storage.v1;
17+
18+
import com.google.auto.value.AutoValue;
19+
import javax.annotation.Nullable;
20+
21+
/** Adapter class for data formats used in the AppendRows. */
22+
final class AppendFormats {
23+
/** Enum for the data format used in the AppendRows. */
24+
enum DataFormat {
25+
UNKNOWN,
26+
PROTO,
27+
ARROW
28+
}
29+
30+
/** Container class for the schema used in the AppendRows request. */
31+
@AutoValue
32+
abstract static class AppendRowsSchema {
33+
abstract DataFormat format();
34+
35+
@Nullable
36+
abstract ProtoSchema protoSchema();
37+
38+
@Nullable
39+
abstract ArrowSchema arrowSchema();
40+
41+
static AppendRowsSchema of(ProtoSchema protoSchema) {
42+
return new AutoValue_AppendFormats_AppendRowsSchema(
43+
DataFormat.PROTO, protoSchema, /* arrowSchema= */ null);
44+
}
45+
46+
static AppendRowsSchema of(ArrowSchema arrowSchema) {
47+
return new AutoValue_AppendFormats_AppendRowsSchema(
48+
DataFormat.ARROW, /* protoSchema= */ null, arrowSchema);
49+
}
50+
}
51+
52+
/** Container class for the data used in the AppendRows request. */
53+
@AutoValue
54+
abstract static class AppendRowsData {
55+
abstract DataFormat format();
56+
57+
@Nullable
58+
abstract ProtoRows protoRows();
59+
60+
@Nullable
61+
abstract ArrowRecordBatch arrowRecordBatch();
62+
63+
// Row count for arrowRecordBatch. It is defaulted to -1 of not set.
64+
abstract long recordBatchRowCount();
65+
66+
static AppendRowsData of(ProtoRows protoRows) {
67+
return new AutoValue_AppendFormats_AppendRowsData(
68+
DataFormat.PROTO, protoRows, /* arrowRecordBatch= */ null, /* recordBatchRowCount= */ -1);
69+
}
70+
71+
static AppendRowsData of(ArrowRecordBatch arrowRecordBatch) {
72+
return new AutoValue_AppendFormats_AppendRowsData(
73+
DataFormat.ARROW, /* protoRows= */ null, arrowRecordBatch, /* recordBatchRowCount= */ -1);
74+
}
75+
76+
static AppendRowsData of(ArrowRecordBatch arrowRecordBatch, long recordBatchRowCount) {
77+
return new AutoValue_AppendFormats_AppendRowsData(
78+
DataFormat.ARROW, /* protoRows= */ null, arrowRecordBatch, recordBatchRowCount);
79+
}
80+
}
81+
82+
private AppendFormats() {}
83+
}

0 commit comments

Comments
 (0)