Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions core/src/main/java/com/scalar/db/common/CoreError.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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", "", ""),
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
}
}
Expand All @@ -187,7 +190,8 @@ private void checkClusteringKeys(Scan scan, TableMetadata metadata) {
Key startClusteringKey = scan.getStartClusteringKey().get();
Key endClusteringKey = scan.getEndClusteringKey().get();
Supplier<String> 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());
Expand All @@ -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));
}
});
}
Expand All @@ -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));
}
});
}
Expand All @@ -232,7 +238,9 @@ private void checkOrderings(Scan scan, TableMetadata metadata) {
}

Supplier<String> 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());
Expand Down Expand Up @@ -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));
}
}
}
Expand All @@ -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));
}
}
}
Expand Down Expand Up @@ -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));
}
}
}
Expand All @@ -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));
}
});
}
Expand Down Expand Up @@ -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<String> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/scalar/db/util/ScalarDbUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
});
}
Expand Down