aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
diff options
context:
space:
mode:
authorGeir Storli <geirst@yahooinc.com>2023-08-25 10:07:35 +0000
committerGeir Storli <geirst@yahooinc.com>2023-08-25 10:07:35 +0000
commit6fd175bcb3e1b61323214380d6f23324a3056043 (patch)
tree6644e278e75daff81491a265ced5ccdc3cd4413a /document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
parent39420e6f2331825568605cfeb2975844de99de3a (diff)
Add "create non-existing cells" flag to TensorModifyUpdate.
When this is true, non-existing cells in the input tensor is created before applying the modify update. The default cell value is 0.0 for REPLACE and ADD operations, and 1.0 for MULTIPLY operation.
Diffstat (limited to 'document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java')
-rw-r--r--document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java31
1 files changed, 30 insertions, 1 deletions
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 96b5d2c1fb5..4140a9eee02 100644
--- a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
+++ b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
@@ -1681,6 +1681,26 @@ public class JsonReaderTestCase {
}
@Test
+ public void tensor_modify_update_with_create_non_existing_cells_true() {
+ assertTensorModifyUpdate("{{x:a,y:b}:2.0}", TensorModifyUpdate.Operation.ADD, true, "sparse_tensor",
+ inputJson("{",
+ " 'operation': 'add',",
+ " 'create': true,",
+ " 'cells': [",
+ " { 'address': { 'x': 'a', 'y': 'b' }, 'value': 2.0 } ]}"));
+ }
+
+ @Test
+ public void tensor_modify_update_with_create_non_existing_cells_false() {
+ assertTensorModifyUpdate("{{x:a,y:b}:2.0}", TensorModifyUpdate.Operation.ADD, false, "sparse_tensor",
+ inputJson("{",
+ " 'operation': 'add',",
+ " 'create': false,",
+ " 'cells': [",
+ " { 'address': { 'x': 'a', 'y': 'b' }, 'value': 2.0 } ]}"));
+ }
+
+ @Test
public void tensor_modify_update_treats_the_input_tensor_as_sparse() {
// Note that the type of the tensor in the modify update is sparse (it only has mapped dimensions).
assertTensorModifyUpdate("tensor(x{},y{}):{{x:0,y:0}:2.0, {x:1,y:2}:3.0}",
@@ -2155,16 +2175,25 @@ public class JsonReaderTestCase {
private void assertTensorModifyUpdate(String expectedTensor, TensorModifyUpdate.Operation expectedOperation,
String tensorFieldName, String modifyJson) {
- assertTensorModifyUpdate(expectedTensor, expectedOperation, tensorFieldName,
+ assertTensorModifyUpdate(expectedTensor, expectedOperation, false, tensorFieldName,
+ createTensorModifyUpdate(modifyJson, tensorFieldName));
+ }
+
+ private void assertTensorModifyUpdate(String expectedTensor, TensorModifyUpdate.Operation expectedOperation,
+ boolean expectedCreateNonExistingCells,
+ String tensorFieldName, String modifyJson) {
+ assertTensorModifyUpdate(expectedTensor, expectedOperation, expectedCreateNonExistingCells, tensorFieldName,
createTensorModifyUpdate(modifyJson, tensorFieldName));
}
private static void assertTensorModifyUpdate(String expectedTensor, TensorModifyUpdate.Operation expectedOperation,
+ boolean expectedCreateNonExistingCells,
String tensorFieldName, DocumentUpdate update) {
assertTensorFieldUpdate(update, tensorFieldName);
TensorModifyUpdate modifyUpdate = (TensorModifyUpdate) update.getFieldUpdate(tensorFieldName).getValueUpdate(0);
assertEquals(expectedOperation, modifyUpdate.getOperation());
assertEquals(Tensor.from(expectedTensor), modifyUpdate.getValue().getTensor().get());
+ assertEquals(expectedCreateNonExistingCells, modifyUpdate.getCreateNonExistingCells());
}
private DocumentUpdate createTensorModifyUpdate(String modifyJson, String tensorFieldName) {