Skip to content

Commit 7520b83

Browse files
committed
Add table metadata to operation check error messages
1 parent fff49e3 commit 7520b83

File tree

4 files changed

+53
-33
lines changed

4 files changed

+53
-33
lines changed

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ public enum CoreError implements ScalarDbError {
1717
OPERATION_CHECK_ERROR_INDEX_NON_INDEXED_COLUMN_SPECIFIED(
1818
Category.USER_ERROR,
1919
"0001",
20-
"The column of the specified index key is not indexed. Operation: %s",
20+
"The column of the specified index key is not indexed. Operation: %s; Table metadata: %s",
2121
"",
2222
""),
2323
OPERATION_CHECK_ERROR_INDEX_INDEX_KEY_NOT_PROPERLY_SPECIFIED(
2424
Category.USER_ERROR,
2525
"0002",
26-
"The index key is not properly specified. Operation: %s",
26+
"The index key is not properly specified. Operation: %s; Table metadata: %s",
2727
"",
2828
""),
2929
OPERATION_CHECK_ERROR_INDEX_CLUSTERING_KEY_SPECIFIED(
@@ -57,46 +57,50 @@ public enum CoreError implements ScalarDbError {
5757
OPERATION_CHECK_ERROR_PROJECTION(
5858
Category.USER_ERROR,
5959
"0009",
60-
"The specified projection is not found. Projection: %s, Operation: %s",
60+
"The specified projection is not found. Projection: %s, Operation: %s; Table metadata: %s",
6161
"",
6262
""),
6363
OPERATION_CHECK_ERROR_CLUSTERING_KEY_BOUNDARY(
6464
Category.USER_ERROR,
6565
"0010",
66-
"The clustering key boundary is not properly specified. Operation: %s",
66+
"The clustering key boundary is not properly specified. Operation: %s; Table metadata: %s",
6767
"",
6868
""),
6969
OPERATION_CHECK_ERROR_START_CLUSTERING_KEY(
7070
Category.USER_ERROR,
7171
"0011",
72-
"The start clustering key is not properly specified. Operation: %s",
72+
"The start clustering key is not properly specified. Operation: %s; Table metadata: %s",
7373
"",
7474
""),
7575
OPERATION_CHECK_ERROR_END_CLUSTERING_KEY(
7676
Category.USER_ERROR,
7777
"0012",
78-
"The end clustering key is not properly specified. Operation: %s",
78+
"The end clustering key is not properly specified. Operation: %s; Table metadata: %s",
7979
"",
8080
""),
8181
OPERATION_CHECK_ERROR_ORDERING_NOT_PROPERLY_SPECIFIED(
82-
Category.USER_ERROR, "0013", "Orderings are not properly specified. Operation: %s", "", ""),
82+
Category.USER_ERROR,
83+
"0013",
84+
"Orderings are not properly specified. Operation: %s; Table metadata: %s",
85+
"",
86+
""),
8387
OPERATION_CHECK_ERROR_ORDERING_COLUMN_NOT_FOUND(
8488
Category.USER_ERROR,
8589
"0014",
86-
"The specified ordering column is not found. Ordering: %s, Operation: %s",
90+
"The specified ordering column is not found. Ordering: %s, Operation: %s; Table metadata: %s",
8791
"",
8892
""),
8993
OPERATION_CHECK_ERROR_CONDITION(
9094
Category.USER_ERROR,
9195
"0015",
92-
"The condition is not properly specified. Operation: %s",
96+
"The condition is not properly specified. Operation: %s; Table metadata: %s",
9397
"",
9498
""),
9599
TABLE_NOT_FOUND(Category.USER_ERROR, "0016", "The table does not exist. Table: %s", "", ""),
96100
OPERATION_CHECK_ERROR_INVALID_COLUMN(
97101
Category.USER_ERROR,
98102
"0017",
99-
"The column value is not properly specified. Column: %s, Operation: %s",
103+
"The column value is not properly specified. Column: %s, Operation: %s; Table metadata: %s",
100104
"",
101105
""),
102106
EMPTY_MUTATIONS_SPECIFIED(Category.USER_ERROR, "0018", "The mutations are empty", "", ""),
@@ -109,13 +113,13 @@ public enum CoreError implements ScalarDbError {
109113
OPERATION_CHECK_ERROR_PARTITION_KEY(
110114
Category.USER_ERROR,
111115
"0020",
112-
"The partition key is not properly specified. Operation: %s",
116+
"The partition key is not properly specified. Operation: %s; Table metadata: %s",
113117
"",
114118
""),
115119
OPERATION_CHECK_ERROR_CLUSTERING_KEY(
116120
Category.USER_ERROR,
117121
"0021",
118-
"The clustering key is not properly specified. Operation: %s",
122+
"The clustering key is not properly specified. Operation: %s; Table metadata: %s",
119123
"",
120124
""),
121125
AUTH_NOT_ENABLED(
@@ -1034,6 +1038,12 @@ public enum CoreError implements ScalarDbError {
10341038
"The size of a BLOB column value exceeds the maximum allowed size of %d bytes. Column: %s; Size: %d bytes",
10351039
"",
10361040
""),
1041+
OPERATION_CHECK_ERROR_UPDATE_CONDITION(
1042+
Category.USER_ERROR,
1043+
"0280",
1044+
"The condition for the Update operation must be UpdateIf or UpdateIfExists. Operation: %s",
1045+
"",
1046+
""),
10371047

10381048
//
10391049
// Errors for the concurrency error category

core/src/main/java/com/scalar/db/common/checker/OperationChecker.java

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ public void check(Get get) throws ExecutionException {
6161
String name = get.getPartitionKey().getColumns().get(0).getName();
6262
if (!metadata.getSecondaryIndexNames().contains(name)) {
6363
throw new IllegalArgumentException(
64-
CoreError.OPERATION_CHECK_ERROR_INDEX_NON_INDEXED_COLUMN_SPECIFIED.buildMessage(get));
64+
CoreError.OPERATION_CHECK_ERROR_INDEX_NON_INDEXED_COLUMN_SPECIFIED.buildMessage(
65+
get, metadata));
6566
}
6667

6768
if (!new ColumnChecker(metadata, true, false, false, false)
6869
.check(get.getPartitionKey().getColumns().get(0))) {
6970
throw new IllegalArgumentException(
7071
CoreError.OPERATION_CHECK_ERROR_INDEX_INDEX_KEY_NOT_PROPERLY_SPECIFIED.buildMessage(
71-
get));
72+
get, metadata));
7273
}
7374

7475
// The following check is not needed when we use GetWithIndex. But we need to keep it for
@@ -105,14 +106,15 @@ public void check(Scan scan) throws ExecutionException {
105106
String name = scan.getPartitionKey().getColumns().get(0).getName();
106107
if (!metadata.getSecondaryIndexNames().contains(name)) {
107108
throw new IllegalArgumentException(
108-
CoreError.OPERATION_CHECK_ERROR_INDEX_NON_INDEXED_COLUMN_SPECIFIED.buildMessage(scan));
109+
CoreError.OPERATION_CHECK_ERROR_INDEX_NON_INDEXED_COLUMN_SPECIFIED.buildMessage(
110+
scan, metadata));
109111
}
110112

111113
if (!new ColumnChecker(metadata, true, false, false, false)
112114
.check(scan.getPartitionKey().getColumns().get(0))) {
113115
throw new IllegalArgumentException(
114116
CoreError.OPERATION_CHECK_ERROR_INDEX_INDEX_KEY_NOT_PROPERLY_SPECIFIED.buildMessage(
115-
scan));
117+
scan, metadata));
116118
}
117119

118120
// The following checks are not needed when we use ScanWithIndex. But we need to keep them for
@@ -172,7 +174,8 @@ private void checkProjections(Selection selection, TableMetadata metadata) {
172174
for (String projection : selection.getProjections()) {
173175
if (!metadata.getColumnNames().contains(projection)) {
174176
throw new IllegalArgumentException(
175-
CoreError.OPERATION_CHECK_ERROR_PROJECTION.buildMessage(projection, selection));
177+
CoreError.OPERATION_CHECK_ERROR_PROJECTION.buildMessage(
178+
projection, selection, metadata));
176179
}
177180
}
178181
}
@@ -187,7 +190,8 @@ private void checkClusteringKeys(Scan scan, TableMetadata metadata) {
187190
Key startClusteringKey = scan.getStartClusteringKey().get();
188191
Key endClusteringKey = scan.getEndClusteringKey().get();
189192
Supplier<String> message =
190-
() -> CoreError.OPERATION_CHECK_ERROR_CLUSTERING_KEY_BOUNDARY.buildMessage(scan);
193+
() ->
194+
CoreError.OPERATION_CHECK_ERROR_CLUSTERING_KEY_BOUNDARY.buildMessage(scan, metadata);
191195

192196
if (startClusteringKey.size() != endClusteringKey.size()) {
193197
throw new IllegalArgumentException(message.get());
@@ -209,7 +213,8 @@ private void checkStartClusteringKey(Scan scan, TableMetadata metadata) {
209213
ckey -> {
210214
if (!checkKey(ckey, metadata.getClusteringKeyNames(), true, metadata)) {
211215
throw new IllegalArgumentException(
212-
CoreError.OPERATION_CHECK_ERROR_START_CLUSTERING_KEY.buildMessage(scan));
216+
CoreError.OPERATION_CHECK_ERROR_START_CLUSTERING_KEY.buildMessage(
217+
scan, metadata));
213218
}
214219
});
215220
}
@@ -220,7 +225,8 @@ private void checkEndClusteringKey(Scan scan, TableMetadata metadata) {
220225
ckey -> {
221226
if (!checkKey(ckey, metadata.getClusteringKeyNames(), true, metadata)) {
222227
throw new IllegalArgumentException(
223-
CoreError.OPERATION_CHECK_ERROR_END_CLUSTERING_KEY.buildMessage(scan));
228+
CoreError.OPERATION_CHECK_ERROR_END_CLUSTERING_KEY.buildMessage(
229+
scan, metadata));
224230
}
225231
});
226232
}
@@ -232,7 +238,9 @@ private void checkOrderings(Scan scan, TableMetadata metadata) {
232238
}
233239

234240
Supplier<String> message =
235-
() -> CoreError.OPERATION_CHECK_ERROR_ORDERING_NOT_PROPERLY_SPECIFIED.buildMessage(scan);
241+
() ->
242+
CoreError.OPERATION_CHECK_ERROR_ORDERING_NOT_PROPERLY_SPECIFIED.buildMessage(
243+
scan, metadata);
236244

237245
if (orderings.size() > metadata.getClusteringKeyNames().size()) {
238246
throw new IllegalArgumentException(message.get());
@@ -263,7 +271,7 @@ protected void checkOrderingsForScanAll(ScanAll scanAll, TableMetadata metadata)
263271
if (!metadata.getColumnNames().contains(ordering.getColumnName())) {
264272
throw new IllegalArgumentException(
265273
CoreError.OPERATION_CHECK_ERROR_ORDERING_COLUMN_NOT_FOUND.buildMessage(
266-
ordering, scanAll));
274+
ordering, scanAll, metadata));
267275
}
268276
}
269277
}
@@ -284,7 +292,7 @@ protected void checkConjunctions(Selection selection, TableMetadata metadata) {
284292
}
285293
if (!isValid) {
286294
throw new IllegalArgumentException(
287-
CoreError.OPERATION_CHECK_ERROR_CONDITION.buildMessage(selection));
295+
CoreError.OPERATION_CHECK_ERROR_CONDITION.buildMessage(selection, metadata));
288296
}
289297
}
290298
}
@@ -317,7 +325,7 @@ private void checkColumnsInPut(Put put, TableMetadata metadata) {
317325
for (Column<?> column : put.getColumns().values()) {
318326
if (!new ColumnChecker(metadata, false, false, false, true).check(column)) {
319327
throw new IllegalArgumentException(
320-
CoreError.OPERATION_CHECK_ERROR_INVALID_COLUMN.buildMessage(column, put));
328+
CoreError.OPERATION_CHECK_ERROR_INVALID_COLUMN.buildMessage(column, put, metadata));
321329
}
322330
}
323331
}
@@ -330,7 +338,7 @@ private void checkCondition(Mutation mutation, TableMetadata metadata) {
330338
c -> {
331339
if (!new ConditionChecker(metadata).check(mutation.getCondition().get(), isPut)) {
332340
throw new IllegalArgumentException(
333-
CoreError.OPERATION_CHECK_ERROR_CONDITION.buildMessage(mutation));
341+
CoreError.OPERATION_CHECK_ERROR_CONDITION.buildMessage(mutation, metadata));
334342
}
335343
});
336344
}
@@ -378,17 +386,17 @@ private boolean isOutOfAtomicityUnit(
378386
if (!mutation1.getClusteringKey().equals(mutation2.getClusteringKey())) {
379387
return true; // Different clustering keys
380388
}
381-
// Fall through
389+
// Fall through
382390
case PARTITION:
383391
if (!mutation1.getPartitionKey().equals(mutation2.getPartitionKey())) {
384392
return true; // Different partition keys
385393
}
386-
// Fall through
394+
// Fall through
387395
case TABLE:
388396
if (!mutation1.forTable().equals(mutation2.forTable())) {
389397
return true; // Different tables
390398
}
391-
// Fall through
399+
// Fall through
392400
case NAMESPACE:
393401
if (!mutation1.forNamespace().equals(mutation2.forNamespace())) {
394402
return true; // Different namespaces
@@ -447,13 +455,13 @@ private void checkPrimaryKey(Operation operation, TableMetadata metadata) {
447455
private void checkPartitionKey(Operation operation, TableMetadata metadata) {
448456
if (!checkKey(operation.getPartitionKey(), metadata.getPartitionKeyNames(), false, metadata)) {
449457
throw new IllegalArgumentException(
450-
CoreError.OPERATION_CHECK_ERROR_PARTITION_KEY.buildMessage(operation));
458+
CoreError.OPERATION_CHECK_ERROR_PARTITION_KEY.buildMessage(operation, metadata));
451459
}
452460
}
453461

454462
private void checkClusteringKey(Operation operation, TableMetadata metadata) {
455463
Supplier<String> message =
456-
() -> CoreError.OPERATION_CHECK_ERROR_CLUSTERING_KEY.buildMessage(operation);
464+
() -> CoreError.OPERATION_CHECK_ERROR_CLUSTERING_KEY.buildMessage(operation, metadata);
457465

458466
if (!metadata.getClusteringKeyNames().isEmpty() && !operation.getClusteringKey().isPresent()) {
459467
throw new IllegalArgumentException(message.get());

core/src/main/java/com/scalar/db/storage/objectstorage/SelectStatementHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ private boolean isReverseOrder(Scan scan, TableMetadata metadata) {
158158
String clusteringKeyName = iterator.next();
159159
if (!ordering.getColumnName().equals(clusteringKeyName)) {
160160
throw new IllegalArgumentException(
161-
CoreError.OPERATION_CHECK_ERROR_ORDERING_NOT_PROPERLY_SPECIFIED.buildMessage(scan));
161+
CoreError.OPERATION_CHECK_ERROR_ORDERING_NOT_PROPERLY_SPECIFIED.buildMessage(
162+
scan, metadata));
162163
}
163164
boolean isValidOrder =
164165
ordering.getOrder() != metadata.getClusteringOrder(ordering.getColumnName());
@@ -167,7 +168,8 @@ private boolean isReverseOrder(Scan scan, TableMetadata metadata) {
167168
} else {
168169
if (reverse != isValidOrder) {
169170
throw new IllegalArgumentException(
170-
CoreError.OPERATION_CHECK_ERROR_ORDERING_NOT_PROPERLY_SPECIFIED.buildMessage(scan));
171+
CoreError.OPERATION_CHECK_ERROR_ORDERING_NOT_PROPERLY_SPECIFIED.buildMessage(
172+
scan, metadata));
171173
}
172174
}
173175
}

core/src/main/java/com/scalar/db/util/ScalarDbUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public static void checkUpdate(Update update) {
309309
c -> {
310310
if (!(c instanceof UpdateIf) && !(c instanceof UpdateIfExists)) {
311311
throw new IllegalArgumentException(
312-
CoreError.OPERATION_CHECK_ERROR_CONDITION.buildMessage(update));
312+
CoreError.OPERATION_CHECK_ERROR_UPDATE_CONDITION.buildMessage(update));
313313
}
314314
});
315315
}

0 commit comments

Comments
 (0)