summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-02-07 11:26:39 +0100
committerGeir Storli <geirst@verizonmedia.com>2019-02-07 11:30:17 +0100
commit3fd70f1a3e5f26cf260dfbe6fa7672e1df9b2602 (patch)
treefe5af0deb366e9dc73d9922486dad8909e38651d
parentcae4778c3e1f5f113964631a96b708e1df77c9f0 (diff)
Implement serialization and de-serialization for TensorAddUpdate.
-rw-r--r--document/abi-spec.json14
-rw-r--r--document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java12
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/DocumentUpdateWriter.java2
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer6.java8
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java12
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java8
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java8
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializerHead.java6
-rw-r--r--document/src/main/java/com/yahoo/document/update/TensorAddUpdate.java3
-rw-r--r--document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java19
10 files changed, 83 insertions, 9 deletions
diff --git a/document/abi-spec.json b/document/abi-spec.json
index 7d7aad64bca..449a2663c0b 100644
--- a/document/abi-spec.json
+++ b/document/abi-spec.json
@@ -4493,7 +4493,8 @@
"public abstract void write(com.yahoo.document.update.AssignValueUpdate, com.yahoo.document.DataType)",
"public abstract void write(com.yahoo.document.update.RemoveValueUpdate, com.yahoo.document.DataType)",
"public abstract void write(com.yahoo.document.update.ClearValueUpdate, com.yahoo.document.DataType)",
- "public abstract void write(com.yahoo.document.update.TensorModifyUpdate)"
+ "public abstract void write(com.yahoo.document.update.TensorModifyUpdate)",
+ "public abstract void write(com.yahoo.document.update.TensorAddUpdate)"
],
"fields": []
},
@@ -4747,7 +4748,8 @@
"public void read(com.yahoo.document.annotation.Span)",
"public void read(com.yahoo.document.annotation.SpanList)",
"public void read(com.yahoo.document.annotation.AlternateSpanList)",
- "protected com.yahoo.document.update.ValueUpdate readTensorModifyUpdate(com.yahoo.document.DataType)"
+ "protected com.yahoo.document.update.ValueUpdate readTensorModifyUpdate(com.yahoo.document.DataType)",
+ "protected com.yahoo.document.update.ValueUpdate readTensorAddUpdate(com.yahoo.document.DataType)"
],
"fields": []
},
@@ -4759,7 +4761,8 @@
],
"methods": [
"public void <init>(com.yahoo.document.DocumentTypeManager, com.yahoo.io.GrowableByteBuffer)",
- "protected com.yahoo.document.update.ValueUpdate readTensorModifyUpdate(com.yahoo.document.DataType)"
+ "protected com.yahoo.document.update.ValueUpdate readTensorModifyUpdate(com.yahoo.document.DataType)",
+ "protected com.yahoo.document.update.ValueUpdate readTensorAddUpdate(com.yahoo.document.DataType)"
],
"fields": []
},
@@ -4810,6 +4813,7 @@
"public void write(com.yahoo.document.update.RemoveValueUpdate, com.yahoo.document.DataType)",
"public void write(com.yahoo.document.update.ClearValueUpdate, com.yahoo.document.DataType)",
"public void write(com.yahoo.document.update.TensorModifyUpdate)",
+ "public void write(com.yahoo.document.update.TensorAddUpdate)",
"public static long getSerializedSize(com.yahoo.document.Document)"
],
"fields": []
@@ -4864,6 +4868,7 @@
"public void write(com.yahoo.document.update.RemoveValueUpdate, com.yahoo.document.DataType)",
"public void write(com.yahoo.document.update.ClearValueUpdate, com.yahoo.document.DataType)",
"public void write(com.yahoo.document.update.TensorModifyUpdate)",
+ "public void write(com.yahoo.document.update.TensorAddUpdate)",
"public static long getSerializedSize(com.yahoo.document.Document)"
],
"fields": []
@@ -4876,7 +4881,8 @@
],
"methods": [
"public void <init>(com.yahoo.io.GrowableByteBuffer)",
- "public void write(com.yahoo.document.update.TensorModifyUpdate)"
+ "public void write(com.yahoo.document.update.TensorModifyUpdate)",
+ "public void write(com.yahoo.document.update.TensorAddUpdate)"
],
"fields": []
},
diff --git a/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java b/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java
index e472f87e7bf..e9b5a136cf9 100644
--- a/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java
+++ b/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java
@@ -40,6 +40,7 @@ import com.yahoo.document.update.ClearValueUpdate;
import com.yahoo.document.update.FieldUpdate;
import com.yahoo.document.update.MapValueUpdate;
import com.yahoo.document.update.RemoveValueUpdate;
+import com.yahoo.document.update.TensorAddUpdate;
import com.yahoo.document.update.TensorModifyUpdate;
import com.yahoo.document.update.ValueUpdate;
import com.yahoo.vespa.objects.FieldBase;
@@ -275,6 +276,17 @@ public class DocumentUpdateJsonSerializer
}
@Override
+ public void write(TensorAddUpdate update) {
+ wrapIOException(() -> {
+ generator.writeObjectFieldStart("add");
+ if (update.getValue().getTensor().isPresent()) {
+ serializeTensorCells(generator, update.getValue().getTensor().get());
+ }
+ generator.writeEndObject();
+ });
+ }
+
+ @Override
public void write(FieldBase field, FieldValue value) {
throw new JsonSerializationException(String.format("Serialization of field values of type %s is not supported", value.getClass().getName()));
}
diff --git a/document/src/main/java/com/yahoo/document/serialization/DocumentUpdateWriter.java b/document/src/main/java/com/yahoo/document/serialization/DocumentUpdateWriter.java
index b4635070262..22b13d57aea 100644
--- a/document/src/main/java/com/yahoo/document/serialization/DocumentUpdateWriter.java
+++ b/document/src/main/java/com/yahoo/document/serialization/DocumentUpdateWriter.java
@@ -10,6 +10,7 @@ import com.yahoo.document.update.ClearValueUpdate;
import com.yahoo.document.update.FieldUpdate;
import com.yahoo.document.update.MapValueUpdate;
import com.yahoo.document.update.RemoveValueUpdate;
+import com.yahoo.document.update.TensorAddUpdate;
import com.yahoo.document.update.TensorModifyUpdate;
/**
@@ -28,4 +29,5 @@ public interface DocumentUpdateWriter {
public void write(RemoveValueUpdate update, DataType superType);
public void write(ClearValueUpdate clearValueUpdate, DataType superType);
public void write(TensorModifyUpdate update);
+ public void write(TensorAddUpdate update);
}
diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer6.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer6.java
index 6241bc66588..2943f6a8b22 100644
--- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer6.java
+++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer6.java
@@ -655,6 +655,8 @@ public class VespaDocumentDeserializer6 extends BufferSerializer implements Docu
return new RemoveValueUpdate(fval);
case TENSORMODIFY:
return readTensorModifyUpdate(superType);
+ case TENSORADD:
+ return readTensorAddUpdate(superType);
default:
throw new DeserializationException(
"Could not deserialize ValueUpdate, unknown valueUpdateClassID type " + vuTypeId);
@@ -880,7 +882,11 @@ public class VespaDocumentDeserializer6 extends BufferSerializer implements Docu
}
protected ValueUpdate readTensorModifyUpdate(DataType type) {
- throw new DeserializationException("Cannot deserialize tensor modify update, not implemented for Vespa 6");
+ throw new DeserializationException("Cannot deserialize TensorModifyUpdate, not implemented for Vespa 6");
+ }
+
+ protected ValueUpdate readTensorAddUpdate(DataType type) {
+ throw new DeserializationException("Cannot deserialize TensorAddUpdate, not implemented for Vespa 6");
}
}
diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java
index 40f4c39cd26..0f19937db41 100644
--- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java
+++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java
@@ -6,6 +6,7 @@ import com.yahoo.document.DocumentTypeManager;
import com.yahoo.document.TensorDataType;
import com.yahoo.document.datatypes.FieldValue;
import com.yahoo.document.datatypes.TensorFieldValue;
+import com.yahoo.document.update.TensorAddUpdate;
import com.yahoo.document.update.TensorModifyUpdate;
import com.yahoo.document.update.ValueUpdate;
import com.yahoo.io.GrowableByteBuffer;
@@ -37,4 +38,15 @@ public class VespaDocumentDeserializerHead extends VespaDocumentDeserializer6 {
tensor.deserialize(this);
return new TensorModifyUpdate(operation, tensor);
}
+
+ @Override
+ protected ValueUpdate readTensorAddUpdate(DataType type) {
+ if (!(type instanceof TensorDataType)) {
+ throw new DeserializationException("Expected tensor data type, got " + type);
+ }
+ TensorDataType tensorDataType = (TensorDataType)type;
+ TensorFieldValue tensor = new TensorFieldValue(tensorDataType.getTensorType());
+ tensor.deserialize(this);
+ return new TensorAddUpdate(tensor);
+ }
}
diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java
index 124cc94bb41..28ae1c3db90 100644
--- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java
+++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer42.java
@@ -45,6 +45,7 @@ import com.yahoo.document.update.ClearValueUpdate;
import com.yahoo.document.update.FieldUpdate;
import com.yahoo.document.update.MapValueUpdate;
import com.yahoo.document.update.RemoveValueUpdate;
+import com.yahoo.document.update.TensorAddUpdate;
import com.yahoo.document.update.TensorModifyUpdate;
import com.yahoo.document.update.ValueUpdate;
import com.yahoo.io.GrowableByteBuffer;
@@ -647,7 +648,12 @@ public class VespaDocumentSerializer42 extends BufferSerializer implements Docum
@Override
public void write(TensorModifyUpdate update) {
- throw new IllegalArgumentException("Write of TensorModifyUpdate not yet implemeneted");
+ throw new IllegalArgumentException("Write of TensorModifyUpdate not implemeneted for Vespa 4.2");
+ }
+
+ @Override
+ public void write(TensorAddUpdate update) {
+ throw new IllegalArgumentException("Write of TensorAddUpdate not implemeneted for Vespa 4.2");
}
/**
diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java
index b610f3a19e7..22f71bb3f65 100644
--- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java
+++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializer6.java
@@ -48,6 +48,7 @@ import com.yahoo.document.update.ClearValueUpdate;
import com.yahoo.document.update.FieldUpdate;
import com.yahoo.document.update.MapValueUpdate;
import com.yahoo.document.update.RemoveValueUpdate;
+import com.yahoo.document.update.TensorAddUpdate;
import com.yahoo.document.update.TensorModifyUpdate;
import com.yahoo.document.update.ValueUpdate;
import com.yahoo.io.GrowableByteBuffer;
@@ -685,7 +686,12 @@ public class VespaDocumentSerializer6 extends BufferSerializer implements Docume
@Override
public void write(TensorModifyUpdate update) {
- throw new IllegalArgumentException("Write of TensorModifyUpdate not yet implemeneted");
+ throw new IllegalArgumentException("Write of TensorModifyUpdate not implemeneted for Vespa 6");
+ }
+
+ @Override
+ public void write(TensorAddUpdate update) {
+ throw new IllegalArgumentException("Write of TensorAddUpdate not implemeneted for Vespa 6");
}
/**
diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializerHead.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializerHead.java
index 753e2fb0986..144d3f768ab 100644
--- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializerHead.java
+++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentSerializerHead.java
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.serialization;
+import com.yahoo.document.update.TensorAddUpdate;
import com.yahoo.document.update.TensorModifyUpdate;
import com.yahoo.io.GrowableByteBuffer;
@@ -21,4 +22,9 @@ public class VespaDocumentSerializerHead extends VespaDocumentSerializer6 {
update.getValue().serialize(this);
}
+ @Override
+ public void write(TensorAddUpdate update) {
+ update.getValue().serialize(this);
+ }
+
}
diff --git a/document/src/main/java/com/yahoo/document/update/TensorAddUpdate.java b/document/src/main/java/com/yahoo/document/update/TensorAddUpdate.java
index 3703ffc17a2..3a67e2e9de8 100644
--- a/document/src/main/java/com/yahoo/document/update/TensorAddUpdate.java
+++ b/document/src/main/java/com/yahoo/document/update/TensorAddUpdate.java
@@ -32,8 +32,7 @@ public class TensorAddUpdate extends ValueUpdate<TensorFieldValue> {
@Override
public void serialize(DocumentUpdateWriter data, DataType superType) {
- // TODO: implement
- throw new UnsupportedOperationException("Not implemented yet");
+ data.write(this);
}
@Override
diff --git a/document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java b/document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java
index f5626f90301..5f486e9a670 100644
--- a/document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java
+++ b/document/src/test/java/com/yahoo/document/json/DocumentUpdateJsonSerializerTest.java
@@ -316,6 +316,25 @@ public class DocumentUpdateJsonSerializerTest {
}
@Test
+ public void test_tensor_add_update() {
+ roundtripSerializeJsonAndMatch(inputJson(
+ "{",
+ " 'update': 'DOCUMENT_ID',",
+ " 'fields': {",
+ " 'sparse_tensor': {",
+ " 'add': {",
+ " 'cells': [",
+ " { 'address': { 'x': '0', 'y': '0' }, 'value': 2.0 },",
+ " { 'address': { 'x': '1', 'y': '2' }, 'value': 3.0 }",
+ " ]",
+ " }",
+ " }",
+ " }",
+ "}"
+ ));
+ }
+
+ @Test
public void reference_field_id_can_be_update_assigned_non_empty_id() {
roundtripSerializeJsonAndMatch(inputJson(
"{",