Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public abstract class BigQueryBaseResultSet extends BigQueryNoOpsResultSet
protected final Schema schema;
protected final FieldList schemaFieldList;
protected final boolean isNested;
protected boolean isClosed = false;
protected volatile boolean isClosed = false;
protected boolean wasNull = false;
// getMetaData() is commonly called inside row loops; cache the immutable wrapper and record
// the adoption signal once per result set. ResultSet is single-threaded by JDBC contract.
Expand Down Expand Up @@ -156,12 +156,8 @@ public String getQueryId() {

@Override
public void close() {
try {
if (statement != null && statement.isCloseOnCompletion() && !statement.hasMoreResults()) {
statement.close();
}
} catch (SQLException ex) {
LOG.warning("Exception during ResultState.close() operation: %s", ex.getMessage());
if (this.statement != null) {
this.statement.onResultSetClosed(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ private ArrayList<BigQueryJdbcParameter> deepCopyParameterList(
@Override
public int[] executeBatch() throws SQLException {
validateExecution();
prepareForExecution();
int[] result = new int[this.batchParameters.size()];
if (this.batchParameters.isEmpty()) {
return result;
Expand All @@ -424,6 +425,8 @@ public int[] executeBatch() throws SQLException {
}

if (useWriteAPI()) {
checkNotClosedOrCanceled();
BigQueryConnection activeConn = requireOpenConnection();
long startTime = System.currentTimeMillis();
StatementExecution.Builder writeApiExecutionBuilder =
StatementExecution.newBuilder()
Expand All @@ -434,10 +437,10 @@ public int[] executeBatch() throws SQLException {
.QUERY_API_TYPE_WRITE_API);
try {
int[] insertArray;
try (BigQueryWriteClient writeClient = this.connection.getBigQueryWriteClient()) {
try (BigQueryWriteClient writeClient = activeConn.getBigQueryWriteClient()) {
LOG.info("Using Write API for bulk INSERT operation.");

long rowCount = bulkInsertWithWriteAPI(writeClient);
long rowCount = bulkInsertWithWriteAPI(writeClient, activeConn);
insertArray = new int[Math.toIntExact(rowCount)];
Arrays.fill(insertArray, 1);
}
Expand Down Expand Up @@ -506,13 +509,14 @@ public int[] executeBatch() throws SQLException {
}
}

private long bulkInsertWithWriteAPI(BigQueryWriteClient bigQueryWriteClient)
private long bulkInsertWithWriteAPI(
BigQueryWriteClient bigQueryWriteClient, BigQueryConnection activeConn)
throws DescriptorValidationException,
IOException,
InterruptedException,
BigQueryJdbcException {
LOG.finer("++enter++");
RetrySettings retrySettings = this.connection.getRetrySettings();
RetrySettings retrySettings = activeConn.getRetrySettings();

BigQueryJdbcBulkInsertWriter bulkInsertWriter = new BigQueryJdbcBulkInsertWriter();
bulkInsertWriter.initialize(this.insertTableName, bigQueryWriteClient, retrySettings);
Expand Down
Loading
Loading