Skip to content

Commit efbb632

Browse files
committed
fix(bigquery): address review comments on finalize cleanup and typed Schema parameter
1 parent 8d87bb8 commit efbb632

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ArrowDeserializer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,9 @@ static Schema arrowSchemaToBigQuerySchema(Object arrowSchema) {
190190
* @throws IOException if deserialization of the Arrow record batch fails
191191
*/
192192
static List<FieldValueList> deserializeRecordBatch(
193-
byte[] recordBatchBytes, Schema schema, Object arrowSchema) throws IOException {
194-
List<FieldVector> vectors =
195-
ArrowPojoUtils.createVectors(
196-
(org.apache.arrow.vector.types.pojo.Schema) arrowSchema, ALLOCATOR);
193+
byte[] recordBatchBytes, Schema schema, org.apache.arrow.vector.types.pojo.Schema arrowSchema)
194+
throws IOException {
195+
List<FieldVector> vectors = ArrowPojoUtils.createVectors(arrowSchema, ALLOCATOR);
197196
VectorSchemaRoot root;
198197
try {
199198
root = new VectorSchemaRoot(vectors);

java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,24 @@ public Page<FieldValueList> getNextPage() {
422422
String nextPageToken = hasMore ? String.valueOf(totalRowsReturned) : null;
423423
return new PageImpl<>(this, nextPageToken, rowBatch);
424424
}
425+
426+
@Override
427+
@SuppressWarnings("deprecation")
428+
protected void finalize() throws Throwable {
429+
try {
430+
if (client != null) {
431+
try {
432+
client.close();
433+
} catch (Exception e) {
434+
// ignore
435+
}
436+
client = null;
437+
streamIterator = null;
438+
}
439+
} finally {
440+
super.finalize();
441+
}
442+
}
425443
}
426444

427445
private final HttpBigQueryRpc bigQueryRpc;
@@ -2281,7 +2299,7 @@ public com.google.api.services.bigquery.model.QueryResponse call()
22812299
ArrowDeserializer.deserializeRecordBatch(
22822300
results.getArrowRecordBatch().decodeSerializedRecordBatch(),
22832301
schema,
2284-
arrowSchemaPojo);
2302+
(org.apache.arrow.vector.types.pojo.Schema) arrowSchemaPojo);
22852303
} catch (IOException e) {
22862304
throw new BigQueryException(0, "Failed to deserialize Arrow record batch", e);
22872305
}

java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ArrowDeserializerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void testDeserializeRecordBatchPrimitives() throws IOException {
131131
ImmutableList.of(intVector, nameVector, scoreVector, activeVector, bytesVector, tsVector);
132132

133133
try (VectorSchemaRoot root = new VectorSchemaRoot(vectors)) {
134-
Object arrowSchema = root.getSchema();
134+
org.apache.arrow.vector.types.pojo.Schema arrowSchema = root.getSchema();
135135
Schema bqSchema = ArrowDeserializer.arrowSchemaToBigQuerySchema(arrowSchema);
136136

137137
byte[] recordBatchBytes = serializeVectorSchemaRoot(root, allocator);

0 commit comments

Comments
 (0)