Skip to content

Commit 8ee3a70

Browse files
committed
Error handling v2 changes required for athena-jdbc
1 parent 95c86a8 commit 8ee3a70

File tree

10 files changed

+50
-44
lines changed

10 files changed

+50
-44
lines changed

Diff for: athena-federation-sdk/src/main/java/com/amazonaws/athena/connector/credentials/DefaultCredentialsProvider.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
package com.amazonaws.athena.connector.credentials;
2121

2222
import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException;
23-
import com.amazonaws.services.glue.model.ErrorDetails;
24-
import com.amazonaws.services.glue.model.FederationSourceErrorCode;
23+
2524
import com.fasterxml.jackson.databind.ObjectMapper;
2625
import org.slf4j.Logger;
2726
import org.slf4j.LoggerFactory;
27+
import software.amazon.awssdk.services.glue.model.ErrorDetails;
28+
import software.amazon.awssdk.services.glue.model.FederationSourceErrorCode;
2829

2930
import java.io.IOException;
3031
import java.util.HashMap;
@@ -62,7 +63,7 @@ public DefaultCredentialsProvider(final String secretString)
6263
}
6364
catch (IOException ioException) {
6465
throw new AthenaConnectorException("Could not deserialize RDS credentials into HashMap: ",
65-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.InternalServiceException.toString()).withErrorMessage(ioException.getMessage()));
66+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.INTERNAL_SERVICE_EXCEPTION.toString()).errorMessage(ioException.getMessage()).build());
6667
}
6768

6869
this.defaultCredentials = new DefaultCredentials(rdsSecrets.get("username"), rdsSecrets.get("password"));

Diff for: athena-federation-sdk/src/main/java/com/amazonaws/athena/connector/credentials/StaticCredentialsProvider.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
package com.amazonaws.athena.connector.credentials;
2121

2222
import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException;
23-
import com.amazonaws.services.glue.model.ErrorDetails;
24-
import com.amazonaws.services.glue.model.FederationSourceErrorCode;
23+
2524
import org.apache.commons.lang3.StringUtils;
2625
import org.apache.commons.lang3.Validate;
26+
import software.amazon.awssdk.services.glue.model.ErrorDetails;
27+
import software.amazon.awssdk.services.glue.model.FederationSourceErrorCode;
2728

2829
/**
2930
* Static credential provider.
@@ -42,7 +43,7 @@ public StaticCredentialsProvider(final DefaultCredentials defaultCredentials)
4243

4344
if (StringUtils.isAnyBlank(jdbcCredential.getUser(), jdbcCredential.getPassword())) {
4445
throw new AthenaConnectorException("User or password must not be blank.",
45-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidInputException.toString()));
46+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_INPUT_EXCEPTION.toString()).build());
4647
}
4748
}
4849

Diff for: athena-jdbc/src/main/java/com/amazonaws/athena/connectors/jdbc/connection/DatabaseConnectionConfigBuilder.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
package com.amazonaws.athena.connectors.jdbc.connection;
2121

2222
import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException;
23-
import com.amazonaws.services.glue.model.ErrorDetails;
24-
import com.amazonaws.services.glue.model.FederationSourceErrorCode;
23+
2524
import org.apache.commons.lang3.StringUtils;
2625
import org.apache.commons.lang3.Validate;
26+
import software.amazon.awssdk.services.glue.model.ErrorDetails;
27+
import software.amazon.awssdk.services.glue.model.FederationSourceErrorCode;
2728

2829
import java.util.ArrayList;
2930
import java.util.List;
@@ -119,7 +120,7 @@ else if (key.endsWith(CONNECTION_STRING_PROPERTY_SUFFIX)) {
119120
}
120121
if (numberOfCatalogs > MUX_CATALOG_LIMIT) {
121122
throw new AthenaConnectorException("Too many database instances in mux. Max supported is " + MUX_CATALOG_LIMIT,
122-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidInputException.toString()));
123+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_INPUT_EXCEPTION.toString()).build());
123124
}
124125
}
125126

@@ -137,7 +138,7 @@ private DatabaseConnectionConfig extractDatabaseConnectionConfig(final String ca
137138
}
138139
else {
139140
throw new AthenaConnectorException("Invalid connection String for Catalog " + catalogName,
140-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidInputException.toString()));
141+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_INPUT_EXCEPTION.toString()).build());
141142
}
142143

143144
Validate.notBlank(dbType, "Database type must not be blank.");

Diff for: athena-jdbc/src/main/java/com/amazonaws/athena/connectors/jdbc/connection/GenericJdbcConnectionFactory.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.apache.commons.lang3.Validate;
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
26+
import software.amazon.awssdk.services.glue.model.ErrorDetails;
27+
import software.amazon.awssdk.services.glue.model.FederationSourceErrorCode;
2628

2729
import java.io.UnsupportedEncodingException;
2830
import java.net.URLEncoder;
@@ -95,10 +97,10 @@ public Connection getConnection(final CredentialsProvider credentialsProvider)
9597
}
9698
catch (SQLException e) {
9799
if (e.getMessage().contains("Name or service not known")) {
98-
throw new AthenaConnectorException(e.getMessage(), new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidInputException.toString()));
100+
throw new AthenaConnectorException(e.getMessage(), ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_INPUT_EXCEPTION.toString()).build());
99101
}
100102
else if (e.getMessage().contains("Incorrect username or password was specified.")) {
101-
throw new AthenaConnectorException(e.getMessage(), new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidCredentialsException.toString()));
103+
throw new AthenaConnectorException(e.getMessage(), ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_CREDENTIALS_EXCEPTION.toString()).build());
102104
}
103105
}
104106
return connection;
@@ -111,7 +113,7 @@ private String encodeValue(String value)
111113
}
112114
catch (UnsupportedEncodingException ex) {
113115
throw new AthenaConnectorException("Unsupported Encoding Exception: ",
114-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.OperationNotSupportedException.toString()).withErrorMessage(ex.getMessage()));
116+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.OPERATION_NOT_SUPPORTED_EXCEPTION.toString()).errorMessage(ex.getMessage()).build());
115117
}
116118
}
117119
}

Diff for: athena-jdbc/src/main/java/com/amazonaws/athena/connectors/jdbc/manager/DefaultJdbcFederationExpressionParser.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121

2222
import com.amazonaws.athena.connector.lambda.domain.predicate.functions.FunctionName;
2323
import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException;
24-
import com.amazonaws.services.glue.model.ErrorDetails;
25-
import com.amazonaws.services.glue.model.FederationSourceErrorCode;
24+
2625
import org.apache.arrow.vector.types.pojo.ArrowType;
26+
import software.amazon.awssdk.services.glue.model.ErrorDetails;
27+
import software.amazon.awssdk.services.glue.model.FederationSourceErrorCode;
2728

2829
import java.util.List;
2930

@@ -33,7 +34,7 @@ public class DefaultJdbcFederationExpressionParser extends FederationExpressionP
3334
public String mapFunctionToDataSourceSyntax(FunctionName functionName, ArrowType type, List<String> arguments)
3435
{
3536
throw new AthenaConnectorException("Subclass does not yet support complex expressions.",
36-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.OperationNotSupportedException.toString()));
37+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.OPERATION_NOT_SUPPORTED_EXCEPTION.toString()).build());
3738
}
3839

3940
}

Diff for: athena-jdbc/src/main/java/com/amazonaws/athena/connectors/jdbc/manager/FederationExpressionParser.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import com.amazonaws.athena.connector.lambda.domain.predicate.expression.VariableExpression;
2828
import com.amazonaws.athena.connector.lambda.domain.predicate.functions.FunctionName;
2929
import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException;
30-
import com.amazonaws.services.glue.model.ErrorDetails;
31-
import com.amazonaws.services.glue.model.FederationSourceErrorCode;
3230
import com.google.common.annotations.VisibleForTesting;
3331
import com.google.common.base.Joiner;
3432
import com.google.common.collect.ImmutableList;
@@ -37,6 +35,8 @@
3735
import org.apache.arrow.vector.types.pojo.Field;
3836
import org.slf4j.Logger;
3937
import org.slf4j.LoggerFactory;
38+
import software.amazon.awssdk.services.glue.model.ErrorDetails;
39+
import software.amazon.awssdk.services.glue.model.FederationSourceErrorCode;
4040

4141
import java.util.Collections;
4242
import java.util.List;
@@ -92,7 +92,7 @@ else if (argument instanceof FunctionCallExpression) {
9292
return parseFunctionCallExpression((FunctionCallExpression) argument, accumulator);
9393
}
9494
throw new AthenaConnectorException("Should not reach this case - a new subclass was introduced and is not handled.",
95-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.OperationNotSupportedException.toString()));
95+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.OPERATION_NOT_SUPPORTED_EXCEPTION.toString()).build());
9696
}).collect(Collectors.toList());
9797

9898
return mapFunctionToDataSourceSyntax(functionName, functionCallExpression.getType(), arguments);

Diff for: athena-jdbc/src/main/java/com/amazonaws/athena/connectors/jdbc/manager/JDBCUtil.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException;
2424
import com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig;
2525
import com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfigBuilder;
26-
import com.amazonaws.services.glue.model.ErrorDetails;
27-
import com.amazonaws.services.glue.model.FederationSourceErrorCode;
2826
import com.google.common.collect.ImmutableList;
2927
import com.google.common.collect.ImmutableMap;
3028
import org.apache.commons.lang3.Validate;
3129
import org.slf4j.Logger;
3230
import org.slf4j.LoggerFactory;
31+
import software.amazon.awssdk.services.glue.model.ErrorDetails;
32+
import software.amazon.awssdk.services.glue.model.FederationSourceErrorCode;
3333

3434
import java.sql.Connection;
3535
import java.sql.PreparedStatement;
@@ -65,7 +65,7 @@ public static DatabaseConnectionConfig getSingleDatabaseConfigFromEnv(String dat
6565

6666
throw new AthenaConnectorException(String.format("Must provide default connection string parameter %s for database type %s",
6767
DatabaseConnectionConfigBuilder.DEFAULT_CONNECTION_STRING_PROPERTY, databaseEngine),
68-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidInputException.toString()));
68+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_INPUT_EXCEPTION.toString()).build());
6969
}
7070

7171
/**
@@ -85,7 +85,7 @@ public static Map<String, JdbcMetadataHandler> createJdbcMetadataHandlerMap(
8585

8686
if (databaseConnectionConfigs.isEmpty()) {
8787
throw new AthenaConnectorException("At least one connection string required.",
88-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidInputException.toString()));
88+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_INPUT_EXCEPTION.toString()).build());
8989
}
9090

9191
boolean defaultPresent = false;
@@ -103,7 +103,7 @@ public static Map<String, JdbcMetadataHandler> createJdbcMetadataHandlerMap(
103103
if (!defaultPresent) {
104104
throw new AthenaConnectorException("Must provide connection parameters for default database instance " +
105105
DatabaseConnectionConfigBuilder.DEFAULT_CONNECTION_STRING_PROPERTY,
106-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidInputException.toString()));
106+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_INPUT_EXCEPTION.toString()).build());
107107
}
108108

109109
return metadataHandlerMap.build();
@@ -125,7 +125,7 @@ public static Map<String, JdbcRecordHandler> createJdbcRecordHandlerMap(Map<Stri
125125

126126
if (databaseConnectionConfigs.isEmpty()) {
127127
throw new AthenaConnectorException("At least one connection string required.",
128-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidInputException.toString()));
128+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_INPUT_EXCEPTION.toString()).build());
129129
}
130130

131131
boolean defaultPresent = false;
@@ -143,7 +143,7 @@ public static Map<String, JdbcRecordHandler> createJdbcRecordHandlerMap(Map<Stri
143143
if (!defaultPresent) {
144144
throw new AthenaConnectorException("Must provide connection parameters for default database instance " +
145145
DatabaseConnectionConfigBuilder.DEFAULT_CONNECTION_STRING_PROPERTY,
146-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidInputException.toString()));
146+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_INPUT_EXCEPTION.toString()).build());
147147
}
148148

149149
return recordHandlerMap.build();
@@ -161,7 +161,7 @@ public static TableName informationSchemaCaseInsensitiveTableMatch(Connection co
161161
}
162162
else {
163163
throw new AthenaConnectorException(String.format("During SCHEMA Case Insensitive look up could not find Database '%s'", databaseName),
164-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.EntityNotFoundException.toString()));
164+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.ENTITY_NOT_FOUND_EXCEPTION.toString()).build());
165165
}
166166
}
167167

@@ -173,13 +173,13 @@ public static TableName informationSchemaCaseInsensitiveTableMatch(Connection co
173173
resolvedName = resultSet.getString("table_name");
174174
if (resultSet.next()) {
175175
throw new AthenaConnectorException(String.format("More than one table that matches '%s' was returned from Database %s", tableName, databaseName),
176-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidInputException.toString()));
176+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_INPUT_EXCEPTION.toString()).build());
177177
}
178178
LOGGER.info("Resolved name from Case Insensitive look up : {}", resolvedName);
179179
}
180180
else {
181181
throw new AthenaConnectorException(String.format("During TABLE Case Insensitive look up could not find Table '%s' in Database '%s'", tableName, databaseName),
182-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.EntityNotFoundException.toString()));
182+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.ENTITY_NOT_FOUND_EXCEPTION.toString()).build());
183183
}
184184
}
185185

Diff for: athena-jdbc/src/main/java/com/amazonaws/athena/connectors/jdbc/manager/JdbcFederationExpressionParser.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import com.amazonaws.athena.connector.lambda.domain.predicate.functions.OperatorType;
2525
import com.amazonaws.athena.connector.lambda.domain.predicate.functions.StandardFunctions;
2626
import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException;
27-
import com.amazonaws.services.glue.model.ErrorDetails;
28-
import com.amazonaws.services.glue.model.FederationSourceErrorCode;
2927
import com.google.common.base.Joiner;
3028
import org.apache.arrow.vector.types.pojo.ArrowType;
29+
import software.amazon.awssdk.services.glue.model.ErrorDetails;
30+
import software.amazon.awssdk.services.glue.model.FederationSourceErrorCode;
3131

3232
import java.util.List;
3333

@@ -62,26 +62,26 @@ public String mapFunctionToDataSourceSyntax(FunctionName functionName, ArrowType
6262

6363
if (arguments == null || arguments.size() == 0) {
6464
throw new AthenaConnectorException("Arguments cannot be null or empty.",
65-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidInputException.toString()));
65+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_INPUT_EXCEPTION.toString()).build());
6666
}
6767
switch (operatorType) {
6868
case UNARY:
6969
if (arguments.size() != 1) {
7070
throw new AthenaConnectorException("Unary function type " + functionName.getFunctionName() + " was provided with " + arguments.size() + " arguments.",
71-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidInputException.toString()));
71+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_INPUT_EXCEPTION.toString()).build());
7272
}
7373
break;
7474
case BINARY:
7575
if (arguments.size() != 2) {
7676
throw new AthenaConnectorException("Binary function type " + functionName.getFunctionName() + " was provided with " + arguments.size() + " arguments.",
77-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidInputException.toString()));
77+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_INPUT_EXCEPTION.toString()).build());
7878
}
7979
break;
8080
case VARARG:
8181
break;
8282
default:
8383
throw new AthenaConnectorException("A new operator type was introduced without adding support for it.",
84-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.OperationNotSupportedException.toString()));
84+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.OPERATION_NOT_SUPPORTED_EXCEPTION.toString()).build());
8585
}
8686

8787
String clause = "";
@@ -156,7 +156,7 @@ public String mapFunctionToDataSourceSyntax(FunctionName functionName, ArrowType
156156
break;
157157
default:
158158
throw new AthenaConnectorException("The function " + functionName.getFunctionName() + " does not have an implementation",
159-
new ErrorDetails().withErrorCode(FederationSourceErrorCode.OperationNotSupportedException.toString()));
159+
ErrorDetails.builder().errorCode(FederationSourceErrorCode.OPERATION_NOT_SUPPORTED_EXCEPTION.toString()).build());
160160
}
161161
if (clause == null) {
162162
return "";

Diff for: athena-jdbc/src/main/java/com/amazonaws/athena/connectors/jdbc/manager/JdbcMetadataHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private Set<String> listDatabaseNames(final Connection jdbcConnection)
169169
return schemaNames.build();
170170
}
171171
catch (RuntimeException ex) {
172-
throw new AthenaConnectorException("Invalid credentials was specified", new ErrorDetails().withErrorCode(FederationSourceErrorCode.InvalidCredentialsException.toString()));
172+
throw new AthenaConnectorException("Invalid credentials was specified", ErrorDetails.builder().errorCode(FederationSourceErrorCode.INVALID_CREDENTIALS_EXCEPTION.toString()).build());
173173
}
174174
}
175175

0 commit comments

Comments
 (0)