From 8a14db26841f95337e44e9d3d5979736af33468c Mon Sep 17 00:00:00 2001
From: Will Noble <78444363+wnob@users.noreply.github.com>
Date: Tue, 17 Aug 2021 11:21:18 -0700
Subject: [PATCH] Allow totalBytesProcessed and cacheHit to be null (#109)
* Allow totalBytesProcessed and cacheHit to be null
* Make logic equivalent to preexisting
* Fix tests
* Also get ready for release
---
pom.xml | 2 +-
.../clouddb/jdbc/BQForwardOnlyResultSet.java | 27 +++++++----
.../clouddb/jdbc/BQScrollableResultSet.java | 11 +++--
.../starschema/clouddb/jdbc/BQStatement.java | 35 +++++++-------
.../clouddb/jdbc/BQStatementRoot.java | 4 +-
.../BQForwardOnlyResultSetFunctionTest.java | 47 +++++++++++++++++-
.../BQScrollableResultSetFunctionTest.java | 48 ++++++++++++++++++-
7 files changed, 137 insertions(+), 37 deletions(-)
diff --git a/pom.xml b/pom.xml
index d58be2c..d8c241b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
to a groupId that we have ownership over -->
com.github.jonathanswenson
bqjdbc
- 2.3.11-SNAPSHOT
+ 2.3.11
Big Query over JDBC
A simple JDBC driver, to reach Google's BigQuery
diff --git a/src/main/java/net/starschema/clouddb/jdbc/BQForwardOnlyResultSet.java b/src/main/java/net/starschema/clouddb/jdbc/BQForwardOnlyResultSet.java
index 82cd03b..89934cd 100644
--- a/src/main/java/net/starschema/clouddb/jdbc/BQForwardOnlyResultSet.java
+++ b/src/main/java/net/starschema/clouddb/jdbc/BQForwardOnlyResultSet.java
@@ -35,6 +35,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.annotation.Nullable;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -88,11 +89,11 @@ public class BQForwardOnlyResultSet implements java.sql.ResultSet {
/** the ProjectId */
private String projectId;
/** Reference for the Job */
- private Job completedJob;
+ private @Nullable Job completedJob;
/** The total number of bytes processed while creating this ResultSet */
- private final long totalBytesProcessed;
+ private final @Nullable Long totalBytesProcessed;
/** Whether the ResultSet came from BigQuery's cache */
- private final boolean cacheHit;
+ private final @Nullable Boolean cacheHit;
/** Cursor position which goes from -1 to FETCH_SIZE then 0 to FETCH_SIZE
* The -1 is needed because of the while(Result.next() == true) { } iterating method*/
private int Cursor = -1;
@@ -102,8 +103,8 @@ public class BQForwardOnlyResultSet implements java.sql.ResultSet {
.withZone(ZoneId.of("UTC"));
public BQForwardOnlyResultSet(Bigquery bigquery, String projectId,
- Job completedJob, BQStatementRoot bqStatementRoot) throws SQLException {
- this(bigquery, projectId, completedJob, bqStatementRoot, null, false, null, 0, false);
+ @Nullable Job completedJob, BQStatementRoot bqStatementRoot) throws SQLException {
+ this(bigquery, projectId, completedJob, bqStatementRoot, null, false, null, 0L, false);
}
/**
@@ -117,10 +118,10 @@ public BQForwardOnlyResultSet(Bigquery bigquery, String projectId,
* @throws SQLException - if we fail to get the results
*/
public BQForwardOnlyResultSet(Bigquery bigquery, String projectId,
- Job completedJob, BQStatementRoot bqStatementRoot,
+ @Nullable Job completedJob, BQStatementRoot bqStatementRoot,
List prefetchedRows, boolean prefetchedAllRows,
TableSchema schema,
- long totalBytesProcessed, boolean cacheHit
+ @Nullable Long totalBytesProcessed, @Nullable Boolean cacheHit
) throws SQLException {
logger.debug("Created forward only resultset TYPE_FORWARD_ONLY");
this.Statementreference = (Statement) bqStatementRoot;
@@ -138,6 +139,9 @@ public BQForwardOnlyResultSet(Bigquery bigquery, String projectId,
this.cacheHit = cacheHit;
} else {
// initial load
+ if (completedJob == null) {
+ throw new BQSQLException("Cannot poll results without a job reference");
+ }
GetQueryResultsResponse result;
try {
result = BQSupportFuncts.getQueryResultsDivided(bigquery,
@@ -158,7 +162,7 @@ public BQForwardOnlyResultSet(Bigquery bigquery, String projectId,
fetchPos = fetchPos.add(BigInteger.valueOf(this.rowsofResult.size()));
}
this.totalBytesProcessed = result.getTotalBytesProcessed();
- this.cacheHit = Boolean.TRUE.equals(result.getCacheHit()); // coerce Boolean nullable object to boolean primitive
+ this.cacheHit = result.getCacheHit();
}
}
}
@@ -1466,6 +1470,9 @@ public boolean next() throws SQLException {
return false;
}
+ if (completedJob == null) {
+ throw new BQSQLException("Cannot poll results without a job reference");
+ }
GetQueryResultsResponse result;
try {
result = BQSupportFuncts.getQueryResultsDivided(bigquery,
@@ -2729,11 +2736,11 @@ public boolean wasNull() throws SQLException {
return this.wasnull;
}
- public long getTotalBytesProcessed() {
+ public @Nullable Long getTotalBytesProcessed() {
return totalBytesProcessed;
}
- public boolean getCacheHit() {
+ public @Nullable Boolean getCacheHit() {
return cacheHit;
}
}
diff --git a/src/main/java/net/starschema/clouddb/jdbc/BQScrollableResultSet.java b/src/main/java/net/starschema/clouddb/jdbc/BQScrollableResultSet.java
index 0b50030..4b0cc15 100644
--- a/src/main/java/net/starschema/clouddb/jdbc/BQScrollableResultSet.java
+++ b/src/main/java/net/starschema/clouddb/jdbc/BQScrollableResultSet.java
@@ -32,6 +32,7 @@
import com.google.api.services.bigquery.model.TableRow;
import com.google.api.services.bigquery.model.TableSchema;
+import javax.annotation.Nullable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.ResultSetMetaData;
@@ -63,10 +64,10 @@ public class BQScrollableResultSet extends ScrollableResultset