Skip to content

Commit fe63988

Browse files
committed
fix(bqjdbc): Log exception messages - part 3
1 parent 5846197 commit fe63988

21 files changed

Lines changed: 385 additions & 159 deletions

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryArrowResultSet.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ private BigQueryArrowResultSet(
108108
try {
109109
this.arrowDeserializer = new ArrowDeserializer(arrowSchema);
110110
} catch (IOException ex) {
111+
LOG.severe(ex, "IOException during ArrowDeserializer creation");
111112
throw new BigQueryJdbcException(ex);
112113
}
113114
}
@@ -215,8 +216,11 @@ public boolean next() throws SQLException {
215216
checkClosed();
216217
if (this.isNested) {
217218
if (this.currentNestedBatch == null || this.currentNestedBatch.getNestedRecords() == null) {
218-
throw new IllegalStateException(
219-
"currentNestedBatch/JsonStringArrayList can not be null working with the nested record");
219+
IllegalStateException ex =
220+
new IllegalStateException(
221+
"currentNestedBatch/JsonStringArrayList can not be null working with the nested record");
222+
LOG.severe(ex, ex.getMessage());
223+
throw ex;
220224
}
221225
if (this.nestedRowIndex < (this.toIndexExclusive - 1)) {
222226
/* Check if there's a next record in the array which can be read */
@@ -238,7 +242,10 @@ public boolean next() throws SQLException {
238242
// Advance the cursor. Potentially blocking operation.
239243
BigQueryArrowBatchWrapper batchWrapper = this.buffer.take();
240244
if (batchWrapper.getException() != null) {
241-
throw new BigQueryJdbcRuntimeException(batchWrapper.getException());
245+
BigQueryJdbcRuntimeException ex =
246+
new BigQueryJdbcRuntimeException(batchWrapper.getException());
247+
LOG.severe(ex, ex.getMessage());
248+
throw ex;
242249
}
243250
if (batchWrapper.isLast()) {
244251
/* Marks the end of the records */
@@ -267,6 +274,9 @@ else if (this.currentBatchRowIndex < this.vectorSchemaRoot.getRowCount()) {
267274
return true;
268275
}
269276
} catch (InterruptedException | SQLException ex) {
277+
LOG.severe(
278+
ex,
279+
"Error occurred while advancing the cursor. This could happen when connection is closed while the next method is being called.");
270280
throw new BigQueryJdbcException(
271281
"Error occurred while advancing the cursor. This could happen when connection is closed while the next method is being called.",
272282
ex);
@@ -283,12 +293,16 @@ private Object getObjectInternal(int columnIndex) throws SQLException {
283293
// BigQuery doesn't support multidimensional arrays, so
284294
// just the default row num column (1) and the actual column (2) is supposed to be read
285295
if (!(columnIndex == 1 || columnIndex == 2)) {
286-
287-
throw new IllegalArgumentException(
288-
"Column index is required to be 1 or 2 for nested arrays");
296+
IllegalArgumentException ex =
297+
new IllegalArgumentException("Column index is required to be 1 or 2 for nested arrays");
298+
LOG.severe(ex, ex.getMessage());
299+
throw ex;
289300
}
290301
if (this.currentNestedBatch.getNestedRecords() == null) {
291-
throw new IllegalStateException("JsonStringArrayList cannot be null for nested records.");
302+
IllegalStateException ex =
303+
new IllegalStateException("JsonStringArrayList cannot be null for nested records.");
304+
LOG.severe(ex, ex.getMessage());
305+
throw ex;
292306
}
293307
// For Arrays the first column is Index, ref:
294308
// https://docs.oracle.com/javase/7/docs/api/java/sql/Array.html#getResultSet()

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryBaseResultSet.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ protected int getColumnIndex(String columnLabel) throws SQLException {
228228
LOG.finest("++enter++");
229229
checkClosed();
230230
if (columnLabel == null) {
231-
throw new SQLException("Column label cannot be null");
231+
SQLException ex = new SQLException("Column label cannot be null");
232+
LOG.severe(ex, ex.getMessage());
233+
throw ex;
232234
}
233235
// use schema to get the column index, add 1 for SQL index
234236
return this.schemaFieldList.getIndex(columnLabel) + 1;

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,9 @@ public void registerOutParameter(int paramIndex, int sqlType) throws SQLExceptio
940940
BigQueryParameterHandler.BigQueryStatementParameterType.OUT,
941941
-1);
942942
} catch (Exception e) {
943-
throw new SQLException(e);
943+
SQLException ex = new SQLException(e);
944+
LOG.severe(ex, "Failed to registerOutParameter");
945+
throw ex;
944946
}
945947
}
946948

@@ -957,7 +959,9 @@ public void registerOutParameter(String paramName, int sqlType) throws SQLExcept
957959
BigQueryParameterHandler.BigQueryStatementParameterType.OUT,
958960
-1);
959961
} catch (Exception e) {
960-
throw new SQLException(e);
962+
SQLException ex = new SQLException(e);
963+
LOG.severe(ex, "Failed to registerOutParameter");
964+
throw ex;
961965
}
962966
}
963967

@@ -979,7 +983,9 @@ public void registerOutParameter(int paramIndex, int sqlType, int scale) throws
979983
BigQueryParameterHandler.BigQueryStatementParameterType.OUT,
980984
scale);
981985
} catch (Exception e) {
982-
throw new SQLException(e);
986+
SQLException ex = new SQLException(e);
987+
LOG.severe(ex, "Failed to registerOutParameter");
988+
throw ex;
983989
}
984990
}
985991

@@ -1012,7 +1018,9 @@ public void registerOutParameter(String paramName, int sqlType, int scale) throw
10121018
BigQueryParameterHandler.BigQueryStatementParameterType.OUT,
10131019
scale);
10141020
} catch (Exception e) {
1015-
throw new SQLException(e);
1021+
SQLException ex = new SQLException(e);
1022+
LOG.severe(ex, "Failed to registerOutParameter");
1023+
throw ex;
10161024
}
10171025
}
10181026

@@ -1236,12 +1244,18 @@ public void setObject(String arg0, Object arg1, int arg2) throws SQLException {
12361244
if (BigQueryJdbcTypeMappings.standardSQLToJavaSqlTypesMapping.containsKey(sqlType)) {
12371245
int javaSqlType = BigQueryJdbcTypeMappings.standardSQLToJavaSqlTypesMapping.get(sqlType);
12381246
if (javaSqlType != arg2) {
1239-
throw new BigQueryJdbcSqlFeatureNotSupportedException(
1240-
String.format("Unsupported sql type:%s ", arg2));
1247+
BigQueryJdbcSqlFeatureNotSupportedException ex =
1248+
new BigQueryJdbcSqlFeatureNotSupportedException(
1249+
String.format("Unsupported sql type:%s ", arg2));
1250+
LOG.severe(ex, ex.getMessage());
1251+
throw ex;
12411252
}
12421253
} else {
1243-
throw new BigQueryJdbcSqlFeatureNotSupportedException(
1244-
String.format("parameter sql type not supported: %s", sqlType));
1254+
BigQueryJdbcSqlFeatureNotSupportedException ex =
1255+
new BigQueryJdbcSqlFeatureNotSupportedException(
1256+
String.format("parameter sql type not supported: %s", sqlType));
1257+
LOG.severe(ex, ex.getMessage());
1258+
throw ex;
12451259
}
12461260
}
12471261

@@ -1253,12 +1267,18 @@ public void setObject(String arg0, Object arg1, int arg2, int arg3) throws SQLEx
12531267
if (BigQueryJdbcTypeMappings.standardSQLToJavaSqlTypesMapping.containsKey(sqlType)) {
12541268
int javaSqlType = BigQueryJdbcTypeMappings.standardSQLToJavaSqlTypesMapping.get(sqlType);
12551269
if (javaSqlType != arg2) {
1256-
throw new BigQueryJdbcSqlFeatureNotSupportedException(
1257-
String.format("Unsupported sql type:%s ", arg2));
1270+
BigQueryJdbcSqlFeatureNotSupportedException ex =
1271+
new BigQueryJdbcSqlFeatureNotSupportedException(
1272+
String.format("Unsupported sql type:%s ", arg2));
1273+
LOG.severe(ex, ex.getMessage());
1274+
throw ex;
12581275
}
12591276
} else {
1260-
throw new BigQueryJdbcSqlFeatureNotSupportedException(
1261-
String.format("parameter sql type not supported: %s", sqlType));
1277+
BigQueryJdbcSqlFeatureNotSupportedException ex =
1278+
new BigQueryJdbcSqlFeatureNotSupportedException(
1279+
String.format("parameter sql type not supported: %s", sqlType));
1280+
LOG.severe(ex, ex.getMessage());
1281+
throw ex;
12621282
}
12631283
}
12641284

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,12 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
191191
} else if (parts.length == 1) {
192192
this.defaultDataset = DatasetId.of(parts[0]);
193193
} else {
194-
throw new IllegalArgumentException(
195-
"DefaultDataset format is invalid. Supported options are datasetId or"
196-
+ " projectId.datasetId");
194+
IllegalArgumentException ex =
195+
new IllegalArgumentException(
196+
"DefaultDataset format is invalid. Supported options are datasetId or"
197+
+ " projectId.datasetId");
198+
LOG.severe(ex, ex.getMessage());
199+
throw ex;
197200
}
198201
}
199202
this.location = ds.getLocation();
@@ -267,6 +270,7 @@ String getLibraryVersion(Class<?> libraryClass) {
267270
version = props.getProperty("version.jdbc");
268271
}
269272
} catch (IOException e) {
273+
LOG.severe(e, "Failed to load dependencies.properties");
270274
return DEFAULT_VERSION;
271275
}
272276

@@ -297,8 +301,10 @@ BigQueryReadClient getBigQueryReadClient() {
297301
this.bigQueryReadClient = getBigQueryReadClientConnection();
298302
}
299303
} catch (IOException e) {
300-
LOG.severe(e, "Failed to initialize BigQueryReadClient");
301-
throw new BigQueryJdbcRuntimeException(e);
304+
BigQueryJdbcRuntimeException ex =
305+
new BigQueryJdbcRuntimeException("Failed to initialize BigQueryReadClient", e);
306+
LOG.severe(ex, ex.getMessage());
307+
throw ex;
302308
}
303309
return this.bigQueryReadClient;
304310
}
@@ -309,8 +315,10 @@ BigQueryWriteClient getBigQueryWriteClient() {
309315
this.bigQueryWriteClient = getBigQueryWriteClientConnection();
310316
}
311317
} catch (IOException e) {
312-
LOG.severe(e, "Failed to initialize BigQueryWriteClient");
313-
throw new BigQueryJdbcRuntimeException(e);
318+
BigQueryJdbcRuntimeException ex =
319+
new BigQueryJdbcRuntimeException("Failed to initialize BigQueryWriteClient", e);
320+
LOG.severe(ex, ex.getMessage());
321+
throw ex;
314322
}
315323
return this.bigQueryWriteClient;
316324
}
@@ -357,7 +365,10 @@ public Statement createStatement(int resultSetType, int resultSetConcurrency)
357365
checkClosed();
358366
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY
359367
|| resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
360-
throw new BigQueryJdbcSqlFeatureNotSupportedException("Unsupported createStatement feature.");
368+
BigQueryJdbcSqlFeatureNotSupportedException ex =
369+
new BigQueryJdbcSqlFeatureNotSupportedException("Unsupported createStatement feature.");
370+
LOG.severe(ex, ex.getMessage());
371+
throw ex;
361372
}
362373
return createStatement();
363374
}
@@ -383,7 +394,10 @@ public Statement createStatement(
383394
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY
384395
|| resultSetConcurrency != ResultSet.CONCUR_READ_ONLY
385396
|| resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) {
386-
throw new BigQueryJdbcSqlFeatureNotSupportedException("Unsupported createStatement feature");
397+
BigQueryJdbcSqlFeatureNotSupportedException ex =
398+
new BigQueryJdbcSqlFeatureNotSupportedException("Unsupported createStatement feature");
399+
LOG.severe(ex, ex.getMessage());
400+
throw ex;
387401
}
388402
return createStatement();
389403
}
@@ -400,14 +414,20 @@ public PreparedStatement prepareStatement(String sql) throws SQLException {
400414
@Override
401415
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
402416
if (autoGeneratedKeys != Statement.NO_GENERATED_KEYS) {
403-
throw new BigQueryJdbcSqlFeatureNotSupportedException("autoGeneratedKeys is not supported");
417+
BigQueryJdbcSqlFeatureNotSupportedException ex =
418+
new BigQueryJdbcSqlFeatureNotSupportedException("autoGeneratedKeys is not supported");
419+
LOG.severe(ex, ex.getMessage());
420+
throw ex;
404421
}
405422
return prepareStatement(sql);
406423
}
407424

408425
@Override
409426
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
410-
throw new BigQueryJdbcSqlFeatureNotSupportedException("autoGeneratedKeys is not supported");
427+
BigQueryJdbcSqlFeatureNotSupportedException ex =
428+
new BigQueryJdbcSqlFeatureNotSupportedException("autoGeneratedKeys is not supported");
429+
LOG.severe(ex, ex.getMessage());
430+
throw ex;
411431
}
412432

413433
@Override
@@ -417,7 +437,10 @@ public PreparedStatement prepareStatement(
417437
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY
418438
|| resultSetConcurrency != ResultSet.CONCUR_READ_ONLY
419439
|| resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) {
420-
throw new BigQueryJdbcSqlFeatureNotSupportedException("Unsupported prepareStatement feature");
440+
BigQueryJdbcSqlFeatureNotSupportedException ex =
441+
new BigQueryJdbcSqlFeatureNotSupportedException("Unsupported prepareStatement feature");
442+
LOG.severe(ex, ex.getMessage());
443+
throw ex;
421444
}
422445
return prepareStatement(sql);
423446
}
@@ -428,7 +451,10 @@ public PreparedStatement prepareStatement(String sql, int resultSetType, int res
428451
LOG.finest("++enter++");
429452
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY
430453
|| resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
431-
throw new BigQueryJdbcSqlFeatureNotSupportedException("Unsupported prepareStatement feature");
454+
BigQueryJdbcSqlFeatureNotSupportedException ex =
455+
new BigQueryJdbcSqlFeatureNotSupportedException("Unsupported prepareStatement feature");
456+
LOG.severe(ex, ex.getMessage());
457+
throw ex;
432458
}
433459
return prepareStatement(sql);
434460
}
@@ -538,8 +564,10 @@ private void beginTransaction() {
538564
}
539565
this.transactionStarted = true;
540566
} catch (InterruptedException ex) {
541-
LOG.severe(ex, "Failed to begin transaction");
542-
throw new BigQueryJdbcRuntimeException(ex);
567+
BigQueryJdbcRuntimeException e =
568+
new BigQueryJdbcRuntimeException("Failed to begin transaction", ex);
569+
LOG.severe(e, e.getMessage());
570+
throw e;
543571
}
544572
}
545573

@@ -646,7 +674,9 @@ Long getListenerPoolSize() {
646674
@Override
647675
public boolean isValid(int timeout) throws SQLException {
648676
if (timeout < 0) {
649-
throw new BigQueryJdbcException("timeout must be >= 0");
677+
BigQueryJdbcException ex = new BigQueryJdbcException("timeout must be >= 0");
678+
LOG.severe(ex, ex.getMessage());
679+
throw ex;
650680
}
651681
if (!isClosed()) {
652682
try (Statement statement = createStatement();
@@ -776,8 +806,9 @@ public void rollback() throws SQLException {
776806
beginTransaction();
777807
}
778808
} catch (InterruptedException | BigQueryException ex) {
779-
LOG.severe(ex, "Failed to rollback transaction");
780-
throw new BigQueryJdbcException(ex);
809+
BigQueryJdbcException e = new BigQueryJdbcException("Failed to rollback transaction", ex);
810+
LOG.severe(e, e.getMessage());
811+
throw e;
781812
}
782813
}
783814

@@ -852,11 +883,15 @@ public void close() throws SQLException {
852883
}
853884
this.openStatements.clear();
854885
} catch (ConcurrentModificationException ex) {
855-
LOG.severe(ex, "Concurrent modification during close");
856-
throw new BigQueryJdbcException(ex);
886+
BigQueryJdbcException e =
887+
new BigQueryJdbcException("Concurrent modification during close", ex);
888+
LOG.severe(e, e.getMessage());
889+
throw e;
857890
} catch (InterruptedException e) {
858-
LOG.severe(e, "Interrupted during close");
859-
throw new BigQueryJdbcRuntimeException(e);
891+
BigQueryJdbcRuntimeException ex =
892+
new BigQueryJdbcRuntimeException("Interrupted during close", e);
893+
LOG.severe(ex, ex.getMessage());
894+
throw ex;
860895
}
861896
this.isClosed = true;
862897
}
@@ -868,14 +903,20 @@ public boolean isClosed() {
868903

869904
private void checkClosed() {
870905
if (isClosed()) {
871-
throw new IllegalStateException("This " + getClass().getName() + " has been closed");
906+
IllegalStateException ex =
907+
new IllegalStateException("This " + getClass().getName() + " has been closed");
908+
LOG.severe(ex, ex.getMessage());
909+
throw ex;
872910
}
873911
}
874912

875913
private void checkIfEnabledSession(String methodName) {
876914
if (!this.enableSession) {
877-
throw new IllegalStateException(
878-
String.format("Session needs to be enabled to use %s method.", methodName));
915+
IllegalStateException ex =
916+
new IllegalStateException(
917+
String.format("Session needs to be enabled to use %s method.", methodName));
918+
LOG.severe(ex, ex.getMessage());
919+
throw ex;
879920
}
880921
}
881922

@@ -1060,7 +1101,10 @@ private void commitTransaction() {
10601101
commitJob.waitFor();
10611102
this.transactionStarted = false;
10621103
} catch (InterruptedException ex) {
1063-
throw new BigQueryJdbcRuntimeException(ex);
1104+
BigQueryJdbcRuntimeException e =
1105+
new BigQueryJdbcRuntimeException("Interrupted during commitTransaction", ex);
1106+
LOG.severe(e, e.getMessage());
1107+
throw e;
10641108
}
10651109
}
10661110

0 commit comments

Comments
 (0)