55import static com .databricks .jdbc .common .DatabricksJdbcConstants .QUERY_EXECUTION_TIMEOUT_SQLSTATE ;
66import static com .databricks .jdbc .common .EnvironmentVariables .*;
77import static com .databricks .jdbc .common .util .DatabricksThriftUtil .*;
8+ import static com .databricks .jdbc .common .util .SqlStateClassifier .classifyTransientSqlState ;
89
910import com .databricks .jdbc .api .impl .*;
1011import com .databricks .jdbc .api .internal .IDatabricksConnectionContext ;
2930import com .databricks .sdk .service .sql .StatementState ;
3031import java .sql .SQLException ;
3132import java .util .Arrays ;
33+ import java .util .Objects ;
3234import java .util .concurrent .TimeUnit ;
3335import org .apache .http .HttpException ;
3436import org .apache .thrift .TBase ;
@@ -379,7 +381,16 @@ DatabricksResultSet executeAsync(
379381 "Received error response {} from Thrift Server for request {}" ,
380382 response ,
381383 request .toString ());
382- throw new DatabricksSQLException (response .status .errorMessage , response .status .sqlState );
384+ String originalSqlState = response .status .sqlState ;
385+ String remappedSqlState =
386+ classifyTransientSqlState (response .status .errorMessage , originalSqlState );
387+ if (!Objects .equals (remappedSqlState , originalSqlState )) {
388+ LOGGER .info (
389+ "Remapped SQL state [{}] -> [{}] for transient error pattern in async execute response" ,
390+ originalSqlState ,
391+ remappedSqlState );
392+ }
393+ throw new DatabricksSQLException (response .status .errorMessage , remappedSqlState );
383394 }
384395 } catch (DatabricksSQLException | TException e ) {
385396
@@ -819,7 +830,16 @@ private <T extends TBase<T, F>, F extends TFieldIdEnum> void checkResponseForErr
819830 if (!response .isSet (operationHandleField ) || isErrorStatusCode (status )) {
820831 // if the operationHandle has not been set, it is an error from the server.
821832 LOGGER .error ("Error thrift response {}" , response );
822- throw new DatabricksSQLException (status .getErrorMessage (), status .getSqlState ());
833+ String originalSqlState = status .getSqlState ();
834+ String remappedSqlState =
835+ classifyTransientSqlState (status .getErrorMessage (), originalSqlState );
836+ if (!Objects .equals (remappedSqlState , originalSqlState )) {
837+ LOGGER .info (
838+ "Remapped SQL state [{}] -> [{}] for transient error pattern in thrift response" ,
839+ originalSqlState ,
840+ remappedSqlState );
841+ }
842+ throw new DatabricksSQLException (status .getErrorMessage (), remappedSqlState );
823843 }
824844 }
825845
@@ -840,8 +860,16 @@ private void checkOperationStatusForErrors(TGetOperationStatusResp statusResp, S
840860 + "error: [%s]" ,
841861 statusResp .getStatus ().getStatusCode (), statementId , serverError );
842862 LOGGER .error (errorMsg );
843- throw new DatabricksSQLException (
844- errorMsg , statusResp .isSetSqlState () ? statusResp .getSqlState () : null );
863+ String originalSqlState = statusResp .isSetSqlState () ? statusResp .getSqlState () : null ;
864+ String remappedSqlState = classifyTransientSqlState (serverError , originalSqlState );
865+ if (!Objects .equals (remappedSqlState , originalSqlState )) {
866+ LOGGER .info (
867+ "Remapped SQL state [{}] -> [{}] for transient error pattern in statement [{}]" ,
868+ originalSqlState ,
869+ remappedSqlState ,
870+ statementId );
871+ }
872+ throw new DatabricksSQLException (errorMsg , remappedSqlState );
845873 }
846874
847875 if (statusResp .isSetOperationState ()
@@ -864,7 +892,15 @@ private void checkOperationStatusForErrors(TGetOperationStatusResp statusResp, S
864892 errorMsg , null , DatabricksDriverErrorCode .OPERATION_TIMEOUT_ERROR );
865893 }
866894
867- throw new DatabricksSQLException (errorMsg , sqlState );
895+ String remappedSqlState = classifyTransientSqlState (serverError , sqlState );
896+ if (!Objects .equals (remappedSqlState , sqlState )) {
897+ LOGGER .info (
898+ "Remapped SQL state [{}] -> [{}] for transient error pattern in statement [{}]" ,
899+ sqlState ,
900+ remappedSqlState ,
901+ statementId );
902+ }
903+ throw new DatabricksSQLException (errorMsg , remappedSqlState );
868904 }
869905 }
870906
0 commit comments