diff options
author | Geir Storli <geirst@verizonmedia.com> | 2019-02-05 13:48:13 +0100 |
---|---|---|
committer | Geir Storli <geirst@verizonmedia.com> | 2019-02-05 13:48:13 +0100 |
commit | 88a3b2ff49502695b0078b557070cba3ee9fba39 (patch) | |
tree | 431499ebd187d6085624ab06898eec6f84179535 /document | |
parent | 8c5f65691ae02e34b54965f66305b0ecb7b29b52 (diff) |
A modify update cannot be applied to tensor types with mixed dimensions.
Diffstat (limited to 'document')
-rw-r--r-- | document/src/main/java/com/yahoo/document/json/readers/TensorModifyUpdateReader.java | 11 | ||||
-rw-r--r-- | document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java | 11 |
2 files changed, 22 insertions, 0 deletions
diff --git a/document/src/main/java/com/yahoo/document/json/readers/TensorModifyUpdateReader.java b/document/src/main/java/com/yahoo/document/json/readers/TensorModifyUpdateReader.java index 3767eb88a14..41748454ae6 100644 --- a/document/src/main/java/com/yahoo/document/json/readers/TensorModifyUpdateReader.java +++ b/document/src/main/java/com/yahoo/document/json/readers/TensorModifyUpdateReader.java @@ -29,6 +29,7 @@ public class TensorModifyUpdateReader { expectFieldIsOfTypeTensor(field); expectTensorTypeHasNoneIndexedUnboundDimensions(field); + expectTensorTypeIsNotMixed(field); expectObjectStart(buffer.currentToken()); ModifyUpdateResult result = createModifyUpdateResult(buffer, field); @@ -54,6 +55,16 @@ public class TensorModifyUpdateReader { } } + private static void expectTensorTypeIsNotMixed(Field field) { + TensorType tensorType = ((TensorDataType)field.getDataType()).getTensorType(); + long numMappedDimensions = tensorType.dimensions().stream().filter(dim -> dim.type().equals(TensorType.Dimension.Type.mapped)).count(); + long numIndexedDimensions = tensorType.dimensions().stream().filter(dim -> dim.isIndexed()).count(); + if (numMappedDimensions > 0 && numIndexedDimensions > 0) { + throw new IllegalArgumentException("A modify update cannot be applied to tensor types with mixed dimensions. " + + "Field '" + field.getName() + "' has mixed tensor type '" + tensorType + "'"); + } + } + private static void expectOperationSpecified(TensorModifyUpdate.Operation operation, String fieldName) { if (operation == null) { throw new IllegalArgumentException("Modify update for field '" + fieldName + "' does not contain an operation"); diff --git a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java index 1ef671d90c0..2588d56e24f 100644 --- a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java +++ b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java @@ -155,6 +155,8 @@ public class JsonReaderTestCase { new TensorDataType(new TensorType.Builder().indexed("x", 2).indexed("y", 3).build()))); x.addField(new Field("dense_unbound_tensor", new TensorDataType(new TensorType.Builder().indexed("x").indexed("y").build()))); + x.addField(new Field("mixed_tensor", + new TensorDataType(new TensorType.Builder().mapped("x").indexed("y", 3).build()))); types.registerDocumentType(x); } { @@ -1383,6 +1385,15 @@ public class JsonReaderTestCase { } @Test + public void tensor_modify_update_on_mixed_tensor_throws() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("A modify update cannot be applied to tensor types with mixed dimensions. Field 'mixed_tensor' has mixed tensor type 'tensor(x{},y[3])'"); + createTensorModifyUpdate(inputJson("{", + " 'operation': 'replace',", + " 'cells': [] }"), "mixed_tensor"); + } + + @Test public void tensor_modify_update_with_unknown_operation_throws() { exception.expect(IllegalArgumentException.class); exception.expectMessage("Unknown operation 'unknown' in modify update for field 'sparse_tensor'"); |