Skip to content
3 changes: 2 additions & 1 deletion java-bigquery/google-cloud-bigquery-jdbc/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
drivers/**
target-it/**
*logs*/**
*logs*/**
**/ITBigQueryJDBCLocalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@

package com.google.cloud.bigquery.exception;

import com.google.cloud.bigquery.jdbc.BigQueryJdbcCustomLogger;
import java.sql.SQLException;

/**
* Exception for errors that occur when the driver cannot convert a value from one type to another.
*/
public class BigQueryConversionException extends SQLException {
private static final BigQueryJdbcCustomLogger LOG =
new BigQueryJdbcCustomLogger(BigQueryConversionException.class.getName());

public BigQueryConversionException(String message, Throwable cause) {
super(message, cause);
LOG.severe(message, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
package com.google.cloud.bigquery.exception;

import com.google.api.core.InternalApi;
import com.google.cloud.bigquery.jdbc.BigQueryJdbcCustomLogger;

/**
* Thrown to indicate that the coercion was attempted but couldn't be performed successfully because
* of some error.
*/
@InternalApi
public class BigQueryJdbcCoercionException extends RuntimeException {
private static final BigQueryJdbcCustomLogger LOG =
new BigQueryJdbcCustomLogger(BigQueryJdbcCoercionException.class.getName());

/**
* Construct a new exception with the specified cause.
Expand All @@ -32,5 +35,6 @@ public class BigQueryJdbcCoercionException extends RuntimeException {
*/
public BigQueryJdbcCoercionException(Exception cause) {
super("Coercion error", cause);
LOG.severe("Coercion error", this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
package com.google.cloud.bigquery.exception;

import com.google.api.core.InternalApi;
import com.google.cloud.bigquery.jdbc.BigQueryJdbcCustomLogger;

/**
* Thrown to indicate that the current TypeCoercer can not perform the coercion as the Coercion
* implementation is not registered for the mentioned source and target type.
*/
@InternalApi
public class BigQueryJdbcCoercionNotFoundException extends RuntimeException {
private static final BigQueryJdbcCustomLogger LOG =
new BigQueryJdbcCustomLogger(BigQueryJdbcCoercionNotFoundException.class.getName());

/**
* Construct a new exception.
Expand All @@ -36,5 +39,6 @@ public BigQueryJdbcCoercionNotFoundException(Class<?> source, Class<?> target) {
String.format(
"Coercion not found for [%s -> %s] conversion",
source.getCanonicalName(), target.getCanonicalName()));
LOG.severe(this.getMessage(), this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
package com.google.cloud.bigquery.exception;

import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.jdbc.BigQueryJdbcCustomLogger;
import java.sql.SQLException;

public class BigQueryJdbcException extends SQLException {
private static final BigQueryJdbcCustomLogger LOG =
new BigQueryJdbcCustomLogger(BigQueryJdbcException.class.getName());
private BigQueryException bigQueryException = null;

/**
Expand All @@ -29,6 +32,7 @@ public class BigQueryJdbcException extends SQLException {
*/
public BigQueryJdbcException(String message) {
super(message);
LOG.severe(message, this);
}

/**
Expand All @@ -38,16 +42,19 @@ public BigQueryJdbcException(String message) {
*/
public BigQueryJdbcException(InterruptedException ex) {
super(ex);
LOG.severe(ex.getMessage(), this);
}

/**
* Constructs a new BigQueryJdbcException from BigQueryException
*
* @param message Specific message that is being added to the Exception.
* @param ex The BigQueryException to be thrown.
*/
public BigQueryJdbcException(BigQueryException ex) {
super(ex);
public BigQueryJdbcException(String message, BigQueryException ex) {
super(message, ex);
this.bigQueryException = ex;
LOG.severe(ex.getMessage(), this);
}

/**
Expand All @@ -58,6 +65,7 @@ public BigQueryJdbcException(BigQueryException ex) {
*/
public BigQueryJdbcException(String message, Throwable cause) {
super(message, cause);
LOG.severe(message, this);
}

/**
Expand All @@ -68,6 +76,7 @@ public BigQueryJdbcException(String message, Throwable cause) {
*/
public BigQueryJdbcException(Throwable cause) {
super(cause);
LOG.severe(cause.getMessage(), this);
}

public BigQueryException getBigQueryException() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@

package com.google.cloud.bigquery.exception;

import com.google.cloud.bigquery.jdbc.BigQueryJdbcCustomLogger;

public class BigQueryJdbcRuntimeException extends RuntimeException {

private static final BigQueryJdbcCustomLogger LOG =
new BigQueryJdbcCustomLogger(BigQueryJdbcRuntimeException.class.getName());

/**
* Constructs a new BigQueryJdbcRuntimeException with the given message.
*
* @param message The detail message.
*/
public BigQueryJdbcRuntimeException(String message) {
super(message);
LOG.severe(message, this);
}

/**
Expand All @@ -34,6 +40,7 @@ public BigQueryJdbcRuntimeException(String message) {
*/
public BigQueryJdbcRuntimeException(Throwable ex) {
super(ex);
LOG.severe(ex.getMessage(), this);
}

/**
Expand All @@ -44,5 +51,11 @@ public BigQueryJdbcRuntimeException(Throwable ex) {
*/
public BigQueryJdbcRuntimeException(String message, InterruptedException ex) {
super(message, ex);
LOG.severe(message, this);
}

public BigQueryJdbcRuntimeException(String message, Throwable ex) {
super(message, ex);
LOG.severe(message, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@
package com.google.cloud.bigquery.exception;

import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.jdbc.BigQueryJdbcCustomLogger;
import java.sql.SQLFeatureNotSupportedException;

public class BigQueryJdbcSqlFeatureNotSupportedException extends SQLFeatureNotSupportedException {
private static final BigQueryJdbcCustomLogger LOG =
new BigQueryJdbcCustomLogger(BigQueryJdbcSqlFeatureNotSupportedException.class.getName());

/**
* Constructs a new BigQueryJdbcSqlFeatureNotSupportedException with the given message.
*
* @param message The detail message.
*/
public BigQueryJdbcSqlFeatureNotSupportedException(String message) {
super(message);
LOG.severe(message, this);
}

/**
Expand All @@ -36,5 +41,6 @@ public BigQueryJdbcSqlFeatureNotSupportedException(String message) {
*/
public BigQueryJdbcSqlFeatureNotSupportedException(BigQueryException ex) {
super(ex);
LOG.severe(ex.getMessage(), this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.bigquery.exception;

import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.jdbc.BigQueryJdbcCustomLogger;
import java.sql.SQLSyntaxErrorException;

/**
Expand All @@ -25,12 +26,21 @@
* rules.
*/
public class BigQueryJdbcSqlSyntaxErrorException extends SQLSyntaxErrorException {
private static final BigQueryJdbcCustomLogger LOG =
new BigQueryJdbcCustomLogger(BigQueryJdbcSqlSyntaxErrorException.class.getName());

/**
* Constructs a new BigQueryJdbcSqlSyntaxErrorException from BigQueryException
*
* @param ex The BigQueryException to be thrown.
*/
public BigQueryJdbcSqlSyntaxErrorException(BigQueryException ex) {
super(ex.getMessage(), "Incorrect SQL syntax.");
LOG.severe(ex.getMessage(), this);
}

public BigQueryJdbcSqlSyntaxErrorException(String message, BigQueryException ex) {
super(message, ex);
LOG.severe(message, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private BigQueryArrowResultSet(
try {
this.arrowDeserializer = new ArrowDeserializer(arrowSchema);
} catch (IOException ex) {
throw new BigQueryJdbcException(ex);
throw new BigQueryJdbcException("IOException during ArrowDeserializer creation", ex);
}
}
}
Expand Down Expand Up @@ -215,8 +215,11 @@ public boolean next() throws SQLException {
checkClosed();
if (this.isNested) {
if (this.currentNestedBatch == null || this.currentNestedBatch.getNestedRecords() == null) {
throw new IllegalStateException(
"currentNestedBatch/JsonStringArrayList can not be null working with the nested record");
IllegalStateException ex =
new IllegalStateException(
"currentNestedBatch/JsonStringArrayList can not be null working with the nested record");
LOG.severe(ex.getMessage(), ex);
throw ex;
}
if (this.nestedRowIndex < (this.toIndexExclusive - 1)) {
/* Check if there's a next record in the array which can be read */
Expand Down Expand Up @@ -283,12 +286,16 @@ private Object getObjectInternal(int columnIndex) throws SQLException {
// BigQuery doesn't support multidimensional arrays, so
// just the default row num column (1) and the actual column (2) is supposed to be read
if (!(columnIndex == 1 || columnIndex == 2)) {

throw new IllegalArgumentException(
"Column index is required to be 1 or 2 for nested arrays");
IllegalArgumentException ex =
new IllegalArgumentException("Column index is required to be 1 or 2 for nested arrays");
LOG.severe(ex.getMessage(), ex);
throw ex;
}
if (this.currentNestedBatch.getNestedRecords() == null) {
throw new IllegalStateException("JsonStringArrayList cannot be null for nested records.");
IllegalStateException ex =
new IllegalStateException("JsonStringArrayList cannot be null for nested records.");
LOG.severe(ex.getMessage(), ex);
throw ex;
}
// For Arrays the first column is Index, ref:
// https://docs.oracle.com/javase/7/docs/api/java/sql/Array.html#getResultSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,36 +71,24 @@ public final int getBaseType() {

@Override
public final Object getArray(Map<String, Class<?>> map) throws SQLException {
BigQueryJdbcSqlFeatureNotSupportedException ex =
new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
LOG.severe(ex, CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
throw ex;
throw new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
}

@Override
public final Object getArray(long index, int count, Map<String, Class<?>> map)
throws SQLException {
BigQueryJdbcSqlFeatureNotSupportedException ex =
new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
LOG.severe(ex, CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
throw ex;
throw new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
}

@Override
public final ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
BigQueryJdbcSqlFeatureNotSupportedException ex =
new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
LOG.severe(ex, CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
throw ex;
throw new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
}

@Override
public final ResultSet getResultSet(long index, int count, Map<String, Class<?>> map)
throws SQLException {
BigQueryJdbcSqlFeatureNotSupportedException ex =
new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
LOG.severe(ex, CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
throw ex;
throw new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
}

protected Object getArrayInternal(int fromIndex, int toIndexExclusive) {
Expand All @@ -119,7 +107,7 @@ protected void ensureValid() throws IllegalStateException {
LOG.finest("++enter++");
if (!this.valid) {
IllegalStateException ex = new IllegalStateException(INVALID_ARRAY);
LOG.severe(ex, INVALID_ARRAY);
LOG.severe(INVALID_ARRAY, ex);
throw ex;
}
}
Expand All @@ -146,7 +134,7 @@ protected Tuple<Integer, Integer> createRange(long index, int count, int size)
String.format(
"The array index is out of range: %d, number of elements: %d.",
index + count, size));
LOG.severe(ex, ex.getMessage());
LOG.severe(ex.getMessage(), ex);
throw ex;
}
long toIndex = normalisedFromIndex + count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public void close() {

protected SQLException createCoercionException(
int columnIndex, Class<?> targetClass, Exception cause) throws SQLException {
LOG.severe(cause, "Coercion failed");
checkClosed();
StandardSQLTypeName type;
String typeName;
Expand All @@ -127,7 +126,7 @@ protected SQLException createCoercionException(
SQLException ex =
new SQLException(
"For a nested ResultSet from an Array, columnIndex must be 1 or 2.", cause);
LOG.severe(ex, "For a nested ResultSet from an Array, columnIndex must be 1 or 2.");
LOG.severe(ex.getMessage(), ex);
throw ex;
}
} else {
Expand All @@ -149,23 +148,23 @@ private StandardSQLTypeName getStandardSQLTypeName(int columnIndex) throws SQLEx
} else if (columnIndex == 2) {
if (this.schema == null || this.schema.getFields().isEmpty()) {
SQLException ex = new SQLException("Schema not available for nested result set.");
LOG.severe(ex, "Schema not available for nested result set.");
LOG.severe("Schema not available for nested result set.", ex);
throw ex;
}
Field arrayField = this.schema.getFields().get(0);
return arrayField.getType().getStandardType();
} else {
SQLException ex =
new SQLException("For a nested ResultSet from an Array, columnIndex must be 1 or 2.");
LOG.severe(ex, "For a nested ResultSet from an Array, columnIndex must be 1 or 2.");
LOG.severe("For a nested ResultSet from an Array, columnIndex must be 1 or 2.", ex);
throw ex;
}
} else {
if (this.schemaFieldList == null
|| columnIndex > this.schemaFieldList.size()
|| columnIndex < 1) {
SQLException ex = new SQLException("Invalid column index: " + columnIndex);
LOG.severe(ex, "Invalid column index: " + columnIndex);
LOG.severe("Invalid column index: " + columnIndex, ex);
throw ex;
}
Field field = this.schemaFieldList.get(columnIndex - 1);
Expand Down Expand Up @@ -228,7 +227,9 @@ protected int getColumnIndex(String columnLabel) throws SQLException {
LOG.finest("++enter++");
checkClosed();
if (columnLabel == null) {
throw new SQLException("Column label cannot be null");
SQLException ex = new SQLException("Column label cannot be null");
LOG.severe(ex.getMessage(), ex);
throw ex;
}
// use schema to get the column index, add 1 for SQL index
return this.schemaFieldList.getIndex(columnLabel) + 1;
Expand Down
Loading
Loading