diff --git a/common/src/main/java/com/skyflow/logs/ErrorLogs.java b/common/src/main/java/com/skyflow/logs/ErrorLogs.java
index 2051cedc..921defaf 100644
--- a/common/src/main/java/com/skyflow/logs/ErrorLogs.java
+++ b/common/src/main/java/com/skyflow/logs/ErrorLogs.java
@@ -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."),
diff --git a/flowvault/pom.xml b/flowvault/pom.xml
index f66c66c2..f9db081c 100644
--- a/flowvault/pom.xml
+++ b/flowvault/pom.xml
@@ -12,7 +12,7 @@
skyflow-flowvault-java
- 1.2.0-dev.3657b62d
+ 1.2.0-dev.14ede71e
jar
${project.groupId}:${project.artifactId}
Skyflow FlowVault SDK for the Java programming language
diff --git a/skyvault/src/main/java/com/skyflow/errors/ErrorMessage.java b/skyvault/src/main/java/com/skyflow/errors/ErrorMessage.java
index d49a4641..16c3fcf4 100644
--- a/skyvault/src/main/java/com/skyflow/errors/ErrorMessage.java
+++ b/skyvault/src/main/java/com/skyflow/errors/ErrorMessage.java
@@ -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."),
diff --git a/skyvault/src/main/java/com/skyflow/utils/validations/Validations.java b/skyvault/src/main/java/com/skyflow/utils/validations/Validations.java
index 48b9b34d..6f87b2a6 100644
--- a/skyvault/src/main/java/com/skyflow/utils/validations/Validations.java
+++ b/skyvault/src/main/java/com/skyflow/utils/validations/Validations.java
@@ -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 tokensMap = tokens.get(index);
HashMap valuesMap = values.get(index);
if (tokensMap == null || valuesMap == null) {
diff --git a/skyvault/src/test/java/com/skyflow/vault/data/InsertTests.java b/skyvault/src/test/java/com/skyflow/vault/data/InsertTests.java
index 966deb04..baa2d90d 100644
--- a/skyvault/src/test/java/com/skyflow/vault/data/InsertTests.java
+++ b/skyvault/src/test/java/com/skyflow/vault/data/InsertTests.java
@@ -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();
@@ -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);