Skip to content

Commit 7f2c032

Browse files
feeblefakiebrfrn169josh-wong
authored
Backport to branch(3) : Use CoreError for messages of RuntimeExceptions in DynamoAdmin (#3008)
Co-authored-by: Toshihiro Suzuki <[email protected]> Co-authored-by: Josh Wong <[email protected]>
1 parent 4687f97 commit 7f2c032

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

core/src/main/java/com/scalar/db/common/CoreError.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,30 @@ public enum CoreError implements ScalarDbError {
712712
"Db2 does not support renaming primary key or index key columns",
713713
"",
714714
""),
715+
DYNAMO_IMPORT_NOT_SUPPORTED(
716+
Category.USER_ERROR,
717+
"0223",
718+
"Import-related functionality is not supported in DynamoDB",
719+
"",
720+
""),
721+
DYNAMO_PARTITION_KEY_BLOB_TYPE_NOT_SUPPORTED(
722+
Category.USER_ERROR,
723+
"0224",
724+
"The BLOB type is supported only for the last column in the partition key in DynamoDB. Column: %s",
725+
"",
726+
""),
727+
DYNAMO_CLUSTERING_KEY_BLOB_TYPE_NOT_SUPPORTED(
728+
Category.USER_ERROR,
729+
"0225",
730+
"The BLOB type is not supported for clustering keys in DynamoDB. Column: %s",
731+
"",
732+
""),
733+
DYNAMO_INDEX_COLUMN_BOOLEAN_TYPE_NOT_SUPPORTED(
734+
Category.USER_ERROR,
735+
"0226",
736+
"The BOOLEAN type is not supported for index columns in DynamoDB. Column: %s",
737+
"",
738+
""),
715739

716740
//
717741
// Errors for the concurrency error category

core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -285,24 +285,23 @@ private void checkMetadata(TableMetadata metadata) {
285285
}
286286
if (metadata.getColumnDataType(partitionKeyName) == DataType.BLOB) {
287287
throw new IllegalArgumentException(
288-
"BLOB type is supported only for the last column in partition key in DynamoDB: "
289-
+ partitionKeyName);
288+
CoreError.DYNAMO_PARTITION_KEY_BLOB_TYPE_NOT_SUPPORTED.buildMessage(partitionKeyName));
290289
}
291290
}
292291

293292
for (String clusteringKeyName : metadata.getClusteringKeyNames()) {
294293
if (metadata.getColumnDataType(clusteringKeyName) == DataType.BLOB) {
295294
throw new IllegalArgumentException(
296-
"Currently, BLOB type is not supported for clustering keys in DynamoDB: "
297-
+ clusteringKeyName);
295+
CoreError.DYNAMO_CLUSTERING_KEY_BLOB_TYPE_NOT_SUPPORTED.buildMessage(
296+
clusteringKeyName));
298297
}
299298
}
300299

301300
for (String secondaryIndexName : metadata.getSecondaryIndexNames()) {
302301
if (metadata.getColumnDataType(secondaryIndexName) == DataType.BOOLEAN) {
303302
throw new IllegalArgumentException(
304-
"Currently, BOOLEAN type is not supported for a secondary index in DynamoDB: "
305-
+ secondaryIndexName);
303+
CoreError.DYNAMO_INDEX_COLUMN_BOOLEAN_TYPE_NOT_SUPPORTED.buildMessage(
304+
secondaryIndexName));
306305
}
307306
}
308307
}
@@ -814,16 +813,11 @@ public void createIndex(
814813
throws ExecutionException {
815814
Namespace namespace = Namespace.of(namespacePrefix, nonPrefixedNamespace);
816815
TableMetadata metadata = getTableMetadata(nonPrefixedNamespace, table);
817-
818-
if (metadata == null) {
819-
throw new IllegalArgumentException(
820-
"Table " + getFullTableName(namespace, table) + " does not exist");
821-
}
816+
assert metadata != null;
822817

823818
if (metadata.getColumnDataType(columnName) == DataType.BOOLEAN) {
824819
throw new IllegalArgumentException(
825-
"Currently, BOOLEAN type is not supported for a secondary index in DynamoDB: "
826-
+ columnName);
820+
CoreError.DYNAMO_INDEX_COLUMN_BOOLEAN_TYPE_NOT_SUPPORTED.buildMessage(columnName));
827821
}
828822

829823
long ru = Long.parseLong(options.getOrDefault(REQUEST_UNIT, DEFAULT_REQUEST_UNIT));
@@ -1259,15 +1253,13 @@ public void renameColumn(
12591253
@Override
12601254
public TableMetadata getImportTableMetadata(
12611255
String namespace, String table, Map<String, DataType> overrideColumnsType) {
1262-
throw new UnsupportedOperationException(
1263-
"Import-related functionality is not supported in DynamoDB");
1256+
throw new UnsupportedOperationException(CoreError.DYNAMO_IMPORT_NOT_SUPPORTED.buildMessage());
12641257
}
12651258

12661259
@Override
12671260
public void addRawColumnToTable(
12681261
String namespace, String table, String columnName, DataType columnType) {
1269-
throw new UnsupportedOperationException(
1270-
"Import-related functionality is not supported in DynamoDB");
1262+
throw new UnsupportedOperationException(CoreError.DYNAMO_IMPORT_NOT_SUPPORTED.buildMessage());
12711263
}
12721264

12731265
@Override
@@ -1276,8 +1268,7 @@ public void importTable(
12761268
String table,
12771269
Map<String, String> options,
12781270
Map<String, DataType> overrideColumnsType) {
1279-
throw new UnsupportedOperationException(
1280-
"Import-related functionality is not supported in DynamoDB");
1271+
throw new UnsupportedOperationException(CoreError.DYNAMO_IMPORT_NOT_SUPPORTED.buildMessage());
12811272
}
12821273

12831274
@Override

0 commit comments

Comments
 (0)