From a27f2e109466406071728fa50980b57e303f0464 Mon Sep 17 00:00:00 2001 From: brfrn169 Date: Thu, 11 Dec 2025 23:10:12 +0900 Subject: [PATCH] Add table metadata to operation check error messages --- .../java/com/scalar/db/common/CoreError.java | 34 +++++++++++------ .../db/common/checker/OperationChecker.java | 38 +++++++++++-------- .../objectstorage/SelectStatementHandler.java | 6 ++- .../com/scalar/db/util/ScalarDbUtils.java | 2 +- 4 files changed, 50 insertions(+), 30 deletions(-) diff --git a/core/src/main/java/com/scalar/db/common/CoreError.java b/core/src/main/java/com/scalar/db/common/CoreError.java index d93f19d182..4e06f5aa73 100644 --- a/core/src/main/java/com/scalar/db/common/CoreError.java +++ b/core/src/main/java/com/scalar/db/common/CoreError.java @@ -17,13 +17,13 @@ public enum CoreError implements ScalarDbError { OPERATION_CHECK_ERROR_INDEX_NON_INDEXED_COLUMN_SPECIFIED( Category.USER_ERROR, "0001", - "The column of the specified index key is not indexed. Operation: %s", + "The column of the specified index key is not indexed. Operation: %s; Table metadata: %s", "", ""), OPERATION_CHECK_ERROR_INDEX_INDEX_KEY_NOT_PROPERLY_SPECIFIED( Category.USER_ERROR, "0002", - "The index key is not properly specified. Operation: %s", + "The index key is not properly specified. Operation: %s; Table metadata: %s", "", ""), OPERATION_CHECK_ERROR_INDEX_CLUSTERING_KEY_SPECIFIED( @@ -57,46 +57,50 @@ public enum CoreError implements ScalarDbError { OPERATION_CHECK_ERROR_PROJECTION( Category.USER_ERROR, "0009", - "The specified projection is not found. Projection: %s, Operation: %s", + "The specified projection is not found. Projection: %s, Operation: %s; Table metadata: %s", "", ""), OPERATION_CHECK_ERROR_CLUSTERING_KEY_BOUNDARY( Category.USER_ERROR, "0010", - "The clustering key boundary is not properly specified. Operation: %s", + "The clustering key boundary is not properly specified. Operation: %s; Table metadata: %s", "", ""), OPERATION_CHECK_ERROR_START_CLUSTERING_KEY( Category.USER_ERROR, "0011", - "The start clustering key is not properly specified. Operation: %s", + "The start clustering key is not properly specified. Operation: %s; Table metadata: %s", "", ""), OPERATION_CHECK_ERROR_END_CLUSTERING_KEY( Category.USER_ERROR, "0012", - "The end clustering key is not properly specified. Operation: %s", + "The end clustering key is not properly specified. Operation: %s; Table metadata: %s", "", ""), OPERATION_CHECK_ERROR_ORDERING_NOT_PROPERLY_SPECIFIED( - Category.USER_ERROR, "0013", "Orderings are not properly specified. Operation: %s", "", ""), + Category.USER_ERROR, + "0013", + "Orderings are not properly specified. Operation: %s; Table metadata: %s", + "", + ""), OPERATION_CHECK_ERROR_ORDERING_COLUMN_NOT_FOUND( Category.USER_ERROR, "0014", - "The specified ordering column is not found. Ordering: %s, Operation: %s", + "The specified ordering column is not found. Ordering: %s, Operation: %s; Table metadata: %s", "", ""), OPERATION_CHECK_ERROR_CONDITION( Category.USER_ERROR, "0015", - "The condition is not properly specified. Operation: %s", + "The condition is not properly specified. Operation: %s; Table metadata: %s", "", ""), TABLE_NOT_FOUND(Category.USER_ERROR, "0016", "The table does not exist. Table: %s", "", ""), OPERATION_CHECK_ERROR_INVALID_COLUMN( Category.USER_ERROR, "0017", - "The column value is not properly specified. Column: %s, Operation: %s", + "The column value is not properly specified. Column: %s, Operation: %s; Table metadata: %s", "", ""), EMPTY_MUTATIONS_SPECIFIED(Category.USER_ERROR, "0018", "The mutations are empty", "", ""), @@ -109,13 +113,13 @@ public enum CoreError implements ScalarDbError { OPERATION_CHECK_ERROR_PARTITION_KEY( Category.USER_ERROR, "0020", - "The partition key is not properly specified. Operation: %s", + "The partition key is not properly specified. Operation: %s; Table metadata: %s", "", ""), OPERATION_CHECK_ERROR_CLUSTERING_KEY( Category.USER_ERROR, "0021", - "The clustering key is not properly specified. Operation: %s", + "The clustering key is not properly specified. Operation: %s; Table metadata: %s", "", ""), AUTH_NOT_ENABLED( @@ -1034,6 +1038,12 @@ public enum CoreError implements ScalarDbError { "The size of a BLOB column value exceeds the maximum allowed size of %d bytes. Column: %s; Size: %d bytes", "", ""), + OPERATION_CHECK_ERROR_UPDATE_CONDITION( + Category.USER_ERROR, + "0280", + "The condition for the Update operation must be UpdateIf or UpdateIfExists. Operation: %s", + "", + ""), // // Errors for the concurrency error category diff --git a/core/src/main/java/com/scalar/db/common/checker/OperationChecker.java b/core/src/main/java/com/scalar/db/common/checker/OperationChecker.java index 0cc122656d..79c6632354 100644 --- a/core/src/main/java/com/scalar/db/common/checker/OperationChecker.java +++ b/core/src/main/java/com/scalar/db/common/checker/OperationChecker.java @@ -61,14 +61,15 @@ public void check(Get get) throws ExecutionException { String name = get.getPartitionKey().getColumns().get(0).getName(); if (!metadata.getSecondaryIndexNames().contains(name)) { throw new IllegalArgumentException( - CoreError.OPERATION_CHECK_ERROR_INDEX_NON_INDEXED_COLUMN_SPECIFIED.buildMessage(get)); + CoreError.OPERATION_CHECK_ERROR_INDEX_NON_INDEXED_COLUMN_SPECIFIED.buildMessage( + get, metadata)); } if (!new ColumnChecker(metadata, true, false, false, false) .check(get.getPartitionKey().getColumns().get(0))) { throw new IllegalArgumentException( CoreError.OPERATION_CHECK_ERROR_INDEX_INDEX_KEY_NOT_PROPERLY_SPECIFIED.buildMessage( - get)); + get, metadata)); } // 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 { String name = scan.getPartitionKey().getColumns().get(0).getName(); if (!metadata.getSecondaryIndexNames().contains(name)) { throw new IllegalArgumentException( - CoreError.OPERATION_CHECK_ERROR_INDEX_NON_INDEXED_COLUMN_SPECIFIED.buildMessage(scan)); + CoreError.OPERATION_CHECK_ERROR_INDEX_NON_INDEXED_COLUMN_SPECIFIED.buildMessage( + scan, metadata)); } if (!new ColumnChecker(metadata, true, false, false, false) .check(scan.getPartitionKey().getColumns().get(0))) { throw new IllegalArgumentException( CoreError.OPERATION_CHECK_ERROR_INDEX_INDEX_KEY_NOT_PROPERLY_SPECIFIED.buildMessage( - scan)); + scan, metadata)); } // 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) { for (String projection : selection.getProjections()) { if (!metadata.getColumnNames().contains(projection)) { throw new IllegalArgumentException( - CoreError.OPERATION_CHECK_ERROR_PROJECTION.buildMessage(projection, selection)); + CoreError.OPERATION_CHECK_ERROR_PROJECTION.buildMessage( + projection, selection, metadata)); } } } @@ -187,7 +190,8 @@ private void checkClusteringKeys(Scan scan, TableMetadata metadata) { Key startClusteringKey = scan.getStartClusteringKey().get(); Key endClusteringKey = scan.getEndClusteringKey().get(); Supplier message = - () -> CoreError.OPERATION_CHECK_ERROR_CLUSTERING_KEY_BOUNDARY.buildMessage(scan); + () -> + CoreError.OPERATION_CHECK_ERROR_CLUSTERING_KEY_BOUNDARY.buildMessage(scan, metadata); if (startClusteringKey.size() != endClusteringKey.size()) { throw new IllegalArgumentException(message.get()); @@ -209,7 +213,8 @@ private void checkStartClusteringKey(Scan scan, TableMetadata metadata) { ckey -> { if (!checkKey(ckey, metadata.getClusteringKeyNames(), true, metadata)) { throw new IllegalArgumentException( - CoreError.OPERATION_CHECK_ERROR_START_CLUSTERING_KEY.buildMessage(scan)); + CoreError.OPERATION_CHECK_ERROR_START_CLUSTERING_KEY.buildMessage( + scan, metadata)); } }); } @@ -220,7 +225,8 @@ private void checkEndClusteringKey(Scan scan, TableMetadata metadata) { ckey -> { if (!checkKey(ckey, metadata.getClusteringKeyNames(), true, metadata)) { throw new IllegalArgumentException( - CoreError.OPERATION_CHECK_ERROR_END_CLUSTERING_KEY.buildMessage(scan)); + CoreError.OPERATION_CHECK_ERROR_END_CLUSTERING_KEY.buildMessage( + scan, metadata)); } }); } @@ -232,7 +238,9 @@ private void checkOrderings(Scan scan, TableMetadata metadata) { } Supplier message = - () -> CoreError.OPERATION_CHECK_ERROR_ORDERING_NOT_PROPERLY_SPECIFIED.buildMessage(scan); + () -> + CoreError.OPERATION_CHECK_ERROR_ORDERING_NOT_PROPERLY_SPECIFIED.buildMessage( + scan, metadata); if (orderings.size() > metadata.getClusteringKeyNames().size()) { throw new IllegalArgumentException(message.get()); @@ -263,7 +271,7 @@ protected void checkOrderingsForScanAll(ScanAll scanAll, TableMetadata metadata) if (!metadata.getColumnNames().contains(ordering.getColumnName())) { throw new IllegalArgumentException( CoreError.OPERATION_CHECK_ERROR_ORDERING_COLUMN_NOT_FOUND.buildMessage( - ordering, scanAll)); + ordering, scanAll, metadata)); } } } @@ -284,7 +292,7 @@ protected void checkConjunctions(Selection selection, TableMetadata metadata) { } if (!isValid) { throw new IllegalArgumentException( - CoreError.OPERATION_CHECK_ERROR_CONDITION.buildMessage(selection)); + CoreError.OPERATION_CHECK_ERROR_CONDITION.buildMessage(selection, metadata)); } } } @@ -317,7 +325,7 @@ private void checkColumnsInPut(Put put, TableMetadata metadata) { for (Column column : put.getColumns().values()) { if (!new ColumnChecker(metadata, false, false, false, true).check(column)) { throw new IllegalArgumentException( - CoreError.OPERATION_CHECK_ERROR_INVALID_COLUMN.buildMessage(column, put)); + CoreError.OPERATION_CHECK_ERROR_INVALID_COLUMN.buildMessage(column, put, metadata)); } } } @@ -330,7 +338,7 @@ private void checkCondition(Mutation mutation, TableMetadata metadata) { c -> { if (!new ConditionChecker(metadata).check(mutation.getCondition().get(), isPut)) { throw new IllegalArgumentException( - CoreError.OPERATION_CHECK_ERROR_CONDITION.buildMessage(mutation)); + CoreError.OPERATION_CHECK_ERROR_CONDITION.buildMessage(mutation, metadata)); } }); } @@ -447,13 +455,13 @@ private void checkPrimaryKey(Operation operation, TableMetadata metadata) { private void checkPartitionKey(Operation operation, TableMetadata metadata) { if (!checkKey(operation.getPartitionKey(), metadata.getPartitionKeyNames(), false, metadata)) { throw new IllegalArgumentException( - CoreError.OPERATION_CHECK_ERROR_PARTITION_KEY.buildMessage(operation)); + CoreError.OPERATION_CHECK_ERROR_PARTITION_KEY.buildMessage(operation, metadata)); } } private void checkClusteringKey(Operation operation, TableMetadata metadata) { Supplier message = - () -> CoreError.OPERATION_CHECK_ERROR_CLUSTERING_KEY.buildMessage(operation); + () -> CoreError.OPERATION_CHECK_ERROR_CLUSTERING_KEY.buildMessage(operation, metadata); if (!metadata.getClusteringKeyNames().isEmpty() && !operation.getClusteringKey().isPresent()) { throw new IllegalArgumentException(message.get()); diff --git a/core/src/main/java/com/scalar/db/storage/objectstorage/SelectStatementHandler.java b/core/src/main/java/com/scalar/db/storage/objectstorage/SelectStatementHandler.java index b25b218391..2d5fd52523 100644 --- a/core/src/main/java/com/scalar/db/storage/objectstorage/SelectStatementHandler.java +++ b/core/src/main/java/com/scalar/db/storage/objectstorage/SelectStatementHandler.java @@ -158,7 +158,8 @@ private boolean isReverseOrder(Scan scan, TableMetadata metadata) { String clusteringKeyName = iterator.next(); if (!ordering.getColumnName().equals(clusteringKeyName)) { throw new IllegalArgumentException( - CoreError.OPERATION_CHECK_ERROR_ORDERING_NOT_PROPERLY_SPECIFIED.buildMessage(scan)); + CoreError.OPERATION_CHECK_ERROR_ORDERING_NOT_PROPERLY_SPECIFIED.buildMessage( + scan, metadata)); } boolean isValidOrder = ordering.getOrder() != metadata.getClusteringOrder(ordering.getColumnName()); @@ -167,7 +168,8 @@ private boolean isReverseOrder(Scan scan, TableMetadata metadata) { } else { if (reverse != isValidOrder) { throw new IllegalArgumentException( - CoreError.OPERATION_CHECK_ERROR_ORDERING_NOT_PROPERLY_SPECIFIED.buildMessage(scan)); + CoreError.OPERATION_CHECK_ERROR_ORDERING_NOT_PROPERLY_SPECIFIED.buildMessage( + scan, metadata)); } } } diff --git a/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java b/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java index 5f70da4f50..a6ee9823da 100644 --- a/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java +++ b/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java @@ -309,7 +309,7 @@ public static void checkUpdate(Update update) { c -> { if (!(c instanceof UpdateIf) && !(c instanceof UpdateIfExists)) { throw new IllegalArgumentException( - CoreError.OPERATION_CHECK_ERROR_CONDITION.buildMessage(update)); + CoreError.OPERATION_CHECK_ERROR_UPDATE_CONDITION.buildMessage(update)); } }); }