Skip to content
Merged
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
2 changes: 1 addition & 1 deletion common/src/main/java/com/skyflow/logs/ErrorLogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public enum ErrorLogs {
EMPTY_OR_NULL_VALUE_IN_VALUES("Invalid %s1 request. Value can not be null or empty in values for key \"%s2\"."),
EMPTY_OR_NULL_KEY_IN_VALUES("Invalid %s1 request. Key can not be null or empty in values"),
NULL_VALUE_ENTRY_IN_VALUES("Invalid %s1 request. Value entry in 'values' can not be null at index %s2."),
TOKENS_VALUES_SIZE_MISMATCH("Invalid %s1 request. 'tokens' and 'values' must contain the same number of entries."),
TOKENS_VALUES_SIZE_MISMATCH("Invalid %s1 request. 'tokens' contains more entries than 'values'."),
NULL_TOKENS_OR_VALUES_ENTRY("Invalid %s1 request. Entry in 'tokens' or 'values' can not be null at index %s2."),
EMPTY_UPSERT("Invalid %s1 request. Upsert can not be empty."),
INVALID_UPSERT_UPDATE_TYPE("Invalid %s1 request. Upsert updateType must be either UPDATE or REPLACE."),
Expand Down
2 changes: 1 addition & 1 deletion flowvault/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</parent>

<artifactId>skyflow-flowvault-java</artifactId>
<version>1.2.0-dev.3657b62d</version>
<version>1.2.0-dev.14ede71e</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<description>Skyflow FlowVault SDK for the Java programming language</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public enum ErrorMessage {
NoTokensWithTokenMode("%s0 Validation error. Tokens weren't specified for records while 'tokenMode' was %s1. Specify tokens."),
MismatchOfFieldsAndTokens("%s0 Validation error. 'fields' and 'tokens' have different columns names. Verify that 'fields' and 'tokens' columns match."),
InsufficientTokensPassedForTokenModeEnableStrict("%s0 Validation error. 'tokenMode' is set to 'ENABLE_STRICT', but some fields are missing tokens. Specify tokens for all fields."),
TokensValuesSizeMismatch("%s0 Validation error. 'tokens' and 'values' must contain the same number of entries."),
TokensValuesSizeMismatch("%s0 Validation error. 'tokens' contains more entries than 'values'. Specify at most one tokens entry per values entry."),
NullTokensOrValuesEntry("%s0 Validation error. Entry in 'tokens' or 'values' is null. Specify a valid entry."),
BatchInsertPartialSuccess("%s0 Insert operation completed with partial success."),
BatchInsertFailure("%s0 Insert operation failed."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,14 +771,17 @@ private static void validateTokensForInsertRequest(
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyTokens.getMessage());
}

if (tokens.size() != values.size()) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.TOKENS_VALUES_SIZE_MISMATCH.getLog(), InterfaceName.INSERT.getName()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TokensValuesSizeMismatch.getMessage());
}

// Fewer token maps than records is allowed for ENABLE (the server validates record by record, and
// continueOnError inserts the records that have tokens), matching the Node, Go and Python SDKs.
// ENABLE_STRICT already requires equal counts in validateInsertRequest. More token maps than records
// can never be paired, so it is rejected here instead of failing with IndexOutOfBoundsException.
for (int index = 0; index < tokens.size(); index++) {
if (index >= values.size()) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.TOKENS_VALUES_SIZE_MISMATCH.getLog(), InterfaceName.INSERT.getName()
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TokensValuesSizeMismatch.getMessage());
}
HashMap<String, Object> tokensMap = tokens.get(index);
HashMap<String, Object> valuesMap = values.get(index);
if (tokensMap == null || valuesMap == null) {
Expand Down
39 changes: 38 additions & 1 deletion skyvault/src/test/java/com/skyflow/vault/data/InsertTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,27 @@ public void testNullValueEntryInValuesInInsertRequestValidations() {
}

@Test
public void testTokensValuesSizeMismatchWithTokenModeEnableInInsertRequestValidations() {
public void testFewerTokensThanValuesIsAllowedWithTokenModeEnableInInsertRequestValidations() {
// ENABLE lets the server validate record by record (and continueOnError insert the records that
// have tokens), as in the Node, Go and Python SDKs; only ENABLE_STRICT requires equal counts.
values.add(valueMap);
values.add(valueMap);
tokens.add(tokenMap);
InsertRequest request = InsertRequest.builder()
.table(table).values(values).tokens(tokens).tokenMode(TokenMode.ENABLE)
.build();
try {
Validations.validateInsertRequest(request);
} catch (SkyflowException e) {
Assert.fail(INVALID_EXCEPTION_THROWN);
}
}

@Test
public void testMoreTokensThanValuesIsRejectedWithTokenModeEnableInInsertRequestValidations() {
values.add(valueMap);
tokens.add(tokenMap);
tokens.add(tokenMap);
InsertRequest request = InsertRequest.builder()
.table(table).values(values).tokens(tokens).tokenMode(TokenMode.ENABLE)
.build();
Expand All @@ -444,6 +461,26 @@ public void testTokensValuesSizeMismatchWithTokenModeEnableInInsertRequestValida
}
}

@Test
public void testFewerTokensThanValuesIsRejectedWithTokenModeEnableStrictInInsertRequestValidations() {
values.add(valueMap);
values.add(valueMap);
tokens.add(tokenMap);
InsertRequest request = InsertRequest.builder()
.table(table).values(values).tokens(tokens).tokenMode(TokenMode.ENABLE_STRICT)
.build();
try {
Validations.validateInsertRequest(request);
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
Assert.assertEquals(
Utils.parameterizedString(ErrorMessage.InsufficientTokensPassedForTokenModeEnableStrict.getMessage(), Constants.SDK_PREFIX),
e.getMessage()
);
}
}

@Test
public void testNullEntryInTokensOrValuesInInsertRequestValidations() {
values.add(valueMap);
Expand Down
Loading