Skip to content
Merged
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 @@ -16,18 +16,14 @@

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(BigQueryJdbcExceptionUtils.formatMessage(message, cause), cause);
LOG.severe(this.getMessage(), this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@
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 @@ -35,6 +32,5 @@ public class BigQueryJdbcCoercionException extends RuntimeException {
*/
public BigQueryJdbcCoercionException(Exception cause) {
super(BigQueryJdbcExceptionUtils.formatMessage("Coercion error", cause), cause);
LOG.severe(this.getMessage(), this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@
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 @@ -39,6 +36,5 @@ 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,12 +17,9 @@
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 @@ -32,7 +29,6 @@ public class BigQueryJdbcException extends SQLException {
*/
public BigQueryJdbcException(String message) {
super(message);
LOG.severe(message, this);
}

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

/**
Expand All @@ -54,7 +49,6 @@ public BigQueryJdbcException(InterruptedException ex) {
public BigQueryJdbcException(String message, BigQueryException ex) {
super(BigQueryJdbcExceptionUtils.formatMessage(message, ex), ex);
this.bigQueryException = ex;
LOG.severe(this.getMessage(), this);
}

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

/**
Expand All @@ -76,7 +69,6 @@ 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,21 +16,15 @@

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 @@ -40,7 +34,6 @@ public BigQueryJdbcRuntimeException(String message) {
*/
public BigQueryJdbcRuntimeException(Throwable ex) {
super(ex);
LOG.severe(ex.getMessage(), this);
}

/**
Expand All @@ -50,12 +43,10 @@ public BigQueryJdbcRuntimeException(Throwable ex) {
* @param ex Throwable to be thrown.
*/
public BigQueryJdbcRuntimeException(String message, InterruptedException ex) {
super(BigQueryJdbcExceptionUtils.formatMessage(message, ex), ex);
LOG.severe(this.getMessage(), this);
super(message, ex);
}

public BigQueryJdbcRuntimeException(String message, Throwable ex) {
super(BigQueryJdbcExceptionUtils.formatMessage(message, ex), ex);
LOG.severe(this.getMessage(), this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
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.
Expand All @@ -31,7 +28,6 @@ public class BigQueryJdbcSqlFeatureNotSupportedException extends SQLFeatureNotSu
*/
public BigQueryJdbcSqlFeatureNotSupportedException(String message) {
super(message);
LOG.severe(message, this);
}

/**
Expand All @@ -41,6 +37,5 @@ 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,7 +17,6 @@
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 @@ -26,8 +25,6 @@
* rules.
*/
public class BigQueryJdbcSqlSyntaxErrorException extends SQLSyntaxErrorException {
private static final BigQueryJdbcCustomLogger LOG =
new BigQueryJdbcCustomLogger(BigQueryJdbcSqlSyntaxErrorException.class.getName());

/**
* Constructs a new BigQueryJdbcSqlSyntaxErrorException from BigQueryException
Expand All @@ -36,11 +33,9 @@ public class BigQueryJdbcSqlSyntaxErrorException extends SQLSyntaxErrorException
*/
public BigQueryJdbcSqlSyntaxErrorException(BigQueryException ex) {
super(ex.getMessage(), "Incorrect SQL syntax.");
LOG.severe(ex.getMessage(), this);
}

public BigQueryJdbcSqlSyntaxErrorException(String message, BigQueryException ex) {
super(BigQueryJdbcExceptionUtils.formatMessage(message, ex), ex);
LOG.severe(this.getMessage(), this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,8 @@ public boolean next() throws SQLException {
checkClosed();
if (this.isNested) {
if (this.currentNestedBatch == null || this.currentNestedBatch.getNestedRecords() == null) {
IllegalStateException ex =
new IllegalStateException(
"currentNestedBatch/JsonStringArrayList can not be null working with the nested record");
LOG.severe(ex.getMessage(), ex);
throw ex;
throw new IllegalStateException(
"currentNestedBatch/JsonStringArrayList can not be null working with the nested record");
}
if (this.nestedRowIndex < (this.toIndexExclusive - 1)) {
/* Check if there's a next record in the array which can be read */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@

public abstract class BigQueryBaseResultSet extends BigQueryNoOpsResultSet
implements BigQueryResultSet {
protected final BigQueryJdbcCustomLogger LOG = new BigQueryJdbcCustomLogger(this.toString());
protected final BigQueryJdbcCustomLogger LOG =
new BigQueryJdbcCustomLogger(this.getClass().getName());
Comment thread
logachev marked this conversation as resolved.
private BigQuery bigQuery;
private JobId jobId;
private String queryId;
Expand Down Expand Up @@ -107,6 +108,25 @@ public void close() {
}
}

protected SQLException logAndCreateException(SQLException ex) {
if (this.statement == null) {
return ex;
}
try (BigQueryJdbcMdc.MdcCloseable mdc =
BigQueryJdbcMdc.registerInstance(this.statement.connectionId)) {
LOG.severe(ex.getMessage(), ex);
}
return ex;
}

protected SQLException logAndCreateException(String message) {
return logAndCreateException(new SQLException(message));
}

protected SQLException logAndCreateException(String message, Throwable cause) {
return logAndCreateException(new SQLException(message, cause));
}

protected SQLException createCoercionException(
int columnIndex, Class<?> targetClass, Exception cause) throws SQLException {
checkClosed();
Expand All @@ -115,29 +135,31 @@ protected SQLException createCoercionException(

if (isNested) {
if (columnIndex == 1) {
return new BigQueryConversionException(
String.format("Cannot convert index column to type %s.", targetClass.getSimpleName()),
cause);
return logAndCreateException(
new BigQueryConversionException(
String.format(
"Cannot convert index column to type %s.", targetClass.getSimpleName()),
cause));
} else if (columnIndex == 2) {
Field arrayField = this.schema.getFields().get(0);
type = arrayField.getType().getStandardType();
typeName = type.name();
} else {
SQLException ex =
throw logAndCreateException(
new SQLException(
"For a nested ResultSet from an Array, columnIndex must be 1 or 2.", cause);
LOG.severe(ex.getMessage(), ex);
throw ex;
"For a nested ResultSet from an Array, columnIndex must be 1 or 2.", cause));
}
} else {
Field field = this.schemaFieldList.get(columnIndex - 1);
type = field.getType().getStandardType();
typeName = type.name();
}
return new BigQueryConversionException(
String.format(
"Cannot convert value of type %s to type %s.", typeName, targetClass.getSimpleName()),
cause);
return logAndCreateException(
new BigQueryConversionException(
String.format(
"Cannot convert value of type %s to type %s.",
typeName, targetClass.getSimpleName()),
cause));
}

private StandardSQLTypeName getStandardSQLTypeName(int columnIndex) throws SQLException {
Expand All @@ -147,25 +169,19 @@ private StandardSQLTypeName getStandardSQLTypeName(int columnIndex) throws SQLEx
return StandardSQLTypeName.INT64;
} 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("Schema not available for nested result set.", ex);
throw ex;
throw logAndCreateException("Schema not available for nested result set.");
}
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("For a nested ResultSet from an Array, columnIndex must be 1 or 2.", ex);
throw ex;
throw logAndCreateException(
"For a nested ResultSet from an Array, columnIndex must be 1 or 2.");
}
} else {
if (this.schemaFieldList == null
|| columnIndex > this.schemaFieldList.size()
|| columnIndex < 1) {
SQLException ex = new SQLException("Invalid column index: " + columnIndex);
LOG.severe("Invalid column index: " + columnIndex, ex);
throw ex;
throw logAndCreateException("Invalid column index: " + columnIndex);
}
Field field = this.schemaFieldList.get(columnIndex - 1);
return field.getType().getStandardType();
Expand All @@ -185,11 +201,16 @@ public boolean wasNull() throws SQLException {
@Override
public ResultSetMetaData getMetaData() throws SQLException {
checkClosed();
if (this.isNested) {
return BigQueryResultSetMetadata.of(this.schemaFieldList, this.statement);
} else {
return BigQueryResultSetMetadata.of(this.schema.getFields(), this.statement);
String connectionId = this.statement != null ? this.statement.connectionId : null;
ResultSetMetaData metaData;
try (BigQueryJdbcMdc.MdcCloseable mdc = BigQueryJdbcMdc.registerInstance(connectionId)) {
if (this.isNested) {
metaData = BigQueryResultSetMetadata.of(this.schemaFieldList, this.statement);
} else {
metaData = BigQueryResultSetMetadata.of(this.schema.getFields(), this.statement);
}
}
return BigQueryJdbcContextProxy.wrap(metaData, ResultSetMetaData.class, connectionId);
}

@Override
Expand Down Expand Up @@ -227,9 +248,7 @@ protected int getColumnIndex(String columnLabel) throws SQLException {
LOG.finest("++enter++");
checkClosed();
if (columnLabel == null) {
SQLException ex = new SQLException("Column label cannot be null");
LOG.severe(ex.getMessage(), ex);
throw ex;
throw logAndCreateException("Column label cannot be null");
}
// use schema to get the column index, add 1 for SQL index
return this.schemaFieldList.getIndex(columnLabel) + 1;
Expand Down
Loading
Loading