summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2018-09-18 12:54:21 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2018-10-25 20:23:16 +0200
commit85b08b29cc2bc6355fb896ee63786b01beebeba5 (patch)
tree6146a6e12b4bdce08ed62a4dd384f95e71f375a2
parent6a6f6f8f6695ff8f39132303ca460665882ccaf6 (diff)
Use hashmap for faster access.
-rw-r--r--docproc/src/main/java/com/yahoo/docproc/proxy/ProxyDocumentUpdate.java13
-rw-r--r--docproc/src/test/java/com/yahoo/docproc/ProcessingUpdateTestCase.java10
-rw-r--r--docproc/src/test/java/com/yahoo/docproc/proxy/SchemaMappingAndAccessesTest.java9
-rw-r--r--docprocs/src/main/java/com/yahoo/docprocs/indexing/DocumentScript.java4
-rw-r--r--docprocs/src/test/java/com/yahoo/docprocs/indexing/DocumentScriptTestCase.java12
-rw-r--r--docprocs/src/test/java/com/yahoo/docprocs/indexing/IndexingProcessorTestCase.java11
-rw-r--r--document/src/main/java/com/yahoo/document/DocumentUpdate.java133
-rw-r--r--document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java7
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java2
-rw-r--r--document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java2
-rw-r--r--document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java80
-rw-r--r--document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java8
-rw-r--r--document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java4
-rwxr-xr-xdocument/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java44
-rw-r--r--document/src/tests/data/serializeupdatejava.datbin112 -> 112 bytes
-rw-r--r--indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/SimpleAdapterFactory.java2
-rw-r--r--indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentToPathUpdateTestCase.java16
-rw-r--r--indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentToValueUpdateTestCase.java44
-rw-r--r--indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentUpdateTestCase.java6
-rw-r--r--indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GuardTestCase.java6
-rw-r--r--vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java2
21 files changed, 255 insertions, 160 deletions
diff --git a/docproc/src/main/java/com/yahoo/docproc/proxy/ProxyDocumentUpdate.java b/docproc/src/main/java/com/yahoo/docproc/proxy/ProxyDocumentUpdate.java
index a0516a62bd9..517f44cb983 100644
--- a/docproc/src/main/java/com/yahoo/docproc/proxy/ProxyDocumentUpdate.java
+++ b/docproc/src/main/java/com/yahoo/docproc/proxy/ProxyDocumentUpdate.java
@@ -10,6 +10,7 @@ import com.yahoo.document.Field;
import com.yahoo.document.serialization.DocumentUpdateWriter;
import com.yahoo.document.update.FieldUpdate;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -18,6 +19,7 @@ import java.util.Map;
*
* @author vegardh
*/
+// TODO Vespa 7 Remove all deprecated methods
public class ProxyDocumentUpdate extends DocumentUpdate implements DocumentOperationWrapper {
private DocumentUpdate docU;
@@ -41,10 +43,12 @@ public class ProxyDocumentUpdate extends DocumentUpdate implements DocumentOpera
@Override
public FieldUpdate getFieldUpdate(Field field) {
- return getFieldUpdate(field.getName());
+ return docU.getFieldUpdate(field);
}
@Override
+ @Deprecated
+ @SuppressWarnings( "deprecation" )
public FieldUpdate getFieldUpdate(int index) {
return docU.getFieldUpdate(index);
}
@@ -60,10 +64,15 @@ public class ProxyDocumentUpdate extends DocumentUpdate implements DocumentOpera
}
@Override
+ @Deprecated
+ @SuppressWarnings( "deprecation" )
public List<FieldUpdate> getFieldUpdates() {
return docU.getFieldUpdates();
}
-
+ @Override
+ public Collection<FieldUpdate> fieldUpdates() {
+ return docU.fieldUpdates();
+ }
@Override
public DocumentId getId() {
return docU.getId();
diff --git a/docproc/src/test/java/com/yahoo/docproc/ProcessingUpdateTestCase.java b/docproc/src/test/java/com/yahoo/docproc/ProcessingUpdateTestCase.java
index 9a3a29e55b1..a89dbfcc782 100644
--- a/docproc/src/test/java/com/yahoo/docproc/ProcessingUpdateTestCase.java
+++ b/docproc/src/test/java/com/yahoo/docproc/ProcessingUpdateTestCase.java
@@ -37,8 +37,10 @@ public class ProcessingUpdateTestCase {
@Test
public void testProcessingUpdates() {
DocumentType articleType = new DocumentType("article");
- articleType.addField(new Field("body", DataType.STRING, true));
- articleType.addField(new Field("title", DataType.STRING, true));
+ Field bodyField = new Field("body", DataType.STRING, true);
+ Field titleField = new Field("title", DataType.STRING, true);
+ articleType.addField(bodyField);
+ articleType.addField(titleField);
dtm = new DocumentTypeManager();
dtm.registerDocumentType(articleType);
@@ -69,12 +71,12 @@ public class ProcessingUpdateTestCase {
assertEquals(new StringFieldValue("body blah blah blah "), first.getFieldValue("title"));
DocumentUpdate second = (DocumentUpdate) operations.get(1);
- FieldUpdate firstUpd = second.getFieldUpdate(0);
+ FieldUpdate firstUpd = second.getFieldUpdate(bodyField);
assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, firstUpd.getValueUpdate(0).getValueUpdateClassID());
assertEquals(new StringFieldValue("this is the updated body of the article, blahdi blahdi blahdi"), firstUpd.getValueUpdate(0)
.getValue());
- FieldUpdate secondUpd = second.getFieldUpdate(1);
+ FieldUpdate secondUpd = second.getFieldUpdate(titleField);
assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, secondUpd.getValueUpdate(0).getValueUpdateClassID());
assertEquals(new StringFieldValue("body blahdi blahdi blahdi "), secondUpd.getValueUpdate(0).getValue());
}
diff --git a/docproc/src/test/java/com/yahoo/docproc/proxy/SchemaMappingAndAccessesTest.java b/docproc/src/test/java/com/yahoo/docproc/proxy/SchemaMappingAndAccessesTest.java
index 05a03480173..e6de3190156 100644
--- a/docproc/src/test/java/com/yahoo/docproc/proxy/SchemaMappingAndAccessesTest.java
+++ b/docproc/src/test/java/com/yahoo/docproc/proxy/SchemaMappingAndAccessesTest.java
@@ -328,16 +328,17 @@ public class SchemaMappingAndAccessesTest {
Document doc = getDoc();
DocumentType type = doc.getDataType();
DocumentUpdate dud = new DocumentUpdate(type, new DocumentId("doc:map:test:1"));
- FieldUpdate assignSingle = FieldUpdate.createAssign(type.getField("title"), new StringFieldValue("something"));
+ com.yahoo.document.Field title = type.getField("title");
+ FieldUpdate assignSingle = FieldUpdate.createAssign(title, new StringFieldValue("something"));
Map<String, String> fieldMap = new HashMap<>();
fieldMap.put("t", "title");
fieldMap.put("a", "artist");
ProxyDocumentUpdate pup = new ProxyDocumentUpdate(dud, fieldMap);
pup.addFieldUpdate(assignSingle);
- assertEquals(pup.getFieldUpdates(), dud.getFieldUpdates());
+ assertEquals(pup.fieldUpdates().toString(), dud.fieldUpdates().toString());
assertEquals(pup.getDocumentType(), dud.getDocumentType());
- assertEquals(pup.getFieldUpdate(new com.yahoo.document.Field("title")).size(), 1);
- assertEquals(pup.getFieldUpdate(0), dud.getFieldUpdate(0));
+ assertEquals(pup.getFieldUpdate(title).size(), 1);
+ assertEquals(pup.getFieldUpdate(title), dud.fieldUpdates().iterator().next());
assertEquals(pup.getFieldUpdate("title"), dud.getFieldUpdate("title"));
assertEquals(pup.getId(), dud.getId());
assertEquals(pup.getType(), dud.getType());
diff --git a/docprocs/src/main/java/com/yahoo/docprocs/indexing/DocumentScript.java b/docprocs/src/main/java/com/yahoo/docprocs/indexing/DocumentScript.java
index a2321e912e1..4905f3d9dad 100644
--- a/docprocs/src/main/java/com/yahoo/docprocs/indexing/DocumentScript.java
+++ b/docprocs/src/main/java/com/yahoo/docprocs/indexing/DocumentScript.java
@@ -51,13 +51,13 @@ public class DocumentScript {
}
public DocumentUpdate execute(AdapterFactory adapterFactory, DocumentUpdate update) {
- for (FieldUpdate fieldUpdate : update.getFieldUpdates()) {
+ for (FieldUpdate fieldUpdate : update.fieldUpdates()) {
requireThatFieldIsDeclaredInDocument(fieldUpdate.getField());
for (ValueUpdate<?> valueUpdate : fieldUpdate.getValueUpdates()) {
removeAnyLinguisticsSpanTree(valueUpdate);
}
}
- for (FieldPathUpdate fieldUpdate : update.getFieldPathUpdates()) {
+ for (FieldPathUpdate fieldUpdate : update.fieldPathUpdates()) {
requireThatFieldIsDeclaredInDocument(fieldUpdate.getFieldPath().get(0).getFieldRef());
if (fieldUpdate instanceof AssignFieldPathUpdate) {
removeAnyLinguisticsSpanTree(((AssignFieldPathUpdate)fieldUpdate).getFieldValue());
diff --git a/docprocs/src/test/java/com/yahoo/docprocs/indexing/DocumentScriptTestCase.java b/docprocs/src/test/java/com/yahoo/docprocs/indexing/DocumentScriptTestCase.java
index a47762bfbf3..cfaee10a07d 100644
--- a/docprocs/src/test/java/com/yahoo/docprocs/indexing/DocumentScriptTestCase.java
+++ b/docprocs/src/test/java/com/yahoo/docprocs/indexing/DocumentScriptTestCase.java
@@ -187,8 +187,8 @@ public class DocumentScriptTestCase {
FieldPathUpdate executeWithUpdateAndExpectFieldPath(String fieldName, FieldPathUpdate updateIn) {
DocumentUpdate update = executeWithUpdate(fieldName, updateIn);
- assertEquals(1, update.getFieldPathUpdates().size());
- return update.getFieldPathUpdates().get(0);
+ assertEquals(1, update.fieldPathUpdates().size());
+ return update.fieldPathUpdates().iterator().next();
}
}
@@ -229,10 +229,10 @@ public class DocumentScriptTestCase {
StringFieldValue newTitleValue = new StringFieldValue("iron moose 4, moose with a vengeance");
DocumentUpdate update = f.executeWithUpdate("structfield", new AssignFieldPathUpdate(f.type, "structfield.title", newTitleValue));
- assertEquals(1, update.getFieldPathUpdates().size());
- assertEquals(0, update.getFieldUpdates().size());
- assertTrue(update.getFieldPathUpdates().get(0) instanceof AssignFieldPathUpdate);
- AssignFieldPathUpdate assignUpdate = (AssignFieldPathUpdate)update.getFieldPathUpdates().get(0);
+ assertEquals(1, update.fieldPathUpdates().size());
+ assertEquals(0, update.fieldUpdates().size());
+ assertTrue(update.fieldPathUpdates().iterator().next() instanceof AssignFieldPathUpdate);
+ AssignFieldPathUpdate assignUpdate = (AssignFieldPathUpdate)update.fieldPathUpdates().iterator().next();
assertEquals("structfield.title", assignUpdate.getOriginalFieldPath());
assertEquals(newTitleValue, assignUpdate.getFieldValue());
}
diff --git a/docprocs/src/test/java/com/yahoo/docprocs/indexing/IndexingProcessorTestCase.java b/docprocs/src/test/java/com/yahoo/docprocs/indexing/IndexingProcessorTestCase.java
index cef020cd828..5979672524d 100644
--- a/docprocs/src/test/java/com/yahoo/docprocs/indexing/IndexingProcessorTestCase.java
+++ b/docprocs/src/test/java/com/yahoo/docprocs/indexing/IndexingProcessorTestCase.java
@@ -13,7 +13,6 @@ import com.yahoo.document.datatypes.StringFieldValue;
import com.yahoo.document.update.AssignValueUpdate;
import com.yahoo.document.update.FieldUpdate;
import com.yahoo.document.update.ValueUpdate;
-import com.yahoo.language.Linguistics;
import com.yahoo.language.simple.SimpleLinguistics;
import com.yahoo.vespa.configdefinition.IlscriptsConfig;
import org.junit.Test;
@@ -63,15 +62,15 @@ public class IndexingProcessorTestCase {
assertTrue(output instanceof DocumentUpdate);
DocumentUpdate docUpdate = (DocumentUpdate) output;
- assertEquals(3, docUpdate.getFieldUpdates().size());
+ assertEquals(3, docUpdate.fieldUpdates().size());
{
- FieldUpdate fieldUpdate = docUpdate.getFieldUpdate(0);
+ FieldUpdate fieldUpdate = docUpdate.getFieldUpdate("song");
assertEquals("song", fieldUpdate.getField().getName());
assertEquals(1, fieldUpdate.getValueUpdates().size());
ValueUpdate<?> valueUpdate = fieldUpdate.getValueUpdate(0);
assertTrue(valueUpdate instanceof AssignValueUpdate);
assertEquals(new StringFieldValue("isbnmarker"), valueUpdate.getValue());
- fieldUpdate = docUpdate.getFieldUpdate(1);
+ fieldUpdate = docUpdate.getFieldUpdate("title");
assertEquals("title", fieldUpdate.getField().getName());
assertEquals(1, fieldUpdate.getValueUpdates().size());
valueUpdate = fieldUpdate.getValueUpdate(0);
@@ -80,14 +79,14 @@ public class IndexingProcessorTestCase {
}
{
- FieldUpdate fieldUpdate = docUpdate.getFieldUpdate(1);
+ FieldUpdate fieldUpdate = docUpdate.getFieldUpdate("title");
ValueUpdate<?> valueUpdate = fieldUpdate.getValueUpdate(0);
assertEquals("title", fieldUpdate.getField().getName());
assertTrue(valueUpdate instanceof AssignValueUpdate);
assertEquals(new StringFieldValue("69"), valueUpdate.getValue());
}
{
- FieldUpdate fieldUpdate = docUpdate.getFieldUpdate(2);
+ FieldUpdate fieldUpdate = docUpdate.getFieldUpdate("isbn");
ValueUpdate<?> valueUpdate = fieldUpdate.getValueUpdate(0);
assertEquals("isbn", fieldUpdate.getField().getName());
assertTrue(valueUpdate instanceof AssignValueUpdate);
diff --git a/document/src/main/java/com/yahoo/document/DocumentUpdate.java b/document/src/main/java/com/yahoo/document/DocumentUpdate.java
index ad93942c1c0..1a84a14939e 100644
--- a/document/src/main/java/com/yahoo/document/DocumentUpdate.java
+++ b/document/src/main/java/com/yahoo/document/DocumentUpdate.java
@@ -13,9 +13,12 @@ import com.yahoo.document.update.ValueUpdate;
import com.yahoo.io.GrowableByteBuffer;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
/**
@@ -37,14 +40,17 @@ import java.util.Optional;
* @see com.yahoo.document.update.FieldUpdate
* @see com.yahoo.document.update.ValueUpdate
*/
+//TODO Vespa 7 Remove all deprecated methods
+
public class DocumentUpdate extends DocumentOperation implements Iterable<FieldPathUpdate> {
//see src/vespa/document/util/identifiableid.h
public static final int CLASSID = 0x1000 + 6;
private DocumentId docId;
- private List<FieldUpdate> fieldUpdates;
- private List<FieldPathUpdate> fieldPathUpdates;
+ private final List<FieldUpdate> fieldUpdates;
+ private final Map<Integer, FieldUpdate> id2FieldUpdateMap;
+ private final List<FieldPathUpdate> fieldPathUpdates;
private DocumentType documentType;
private Optional<Boolean> createIfNonExistent = Optional.empty();
@@ -55,7 +61,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
* @param docType the document type that this update is valid for
*/
public DocumentUpdate(DocumentType docType, DocumentId docId) {
- this(docType, docId, new ArrayList<FieldUpdate>());
+ this(docType, docId, new HashMap<>());
}
/**
@@ -65,6 +71,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
docId = null;
documentType = null;
fieldUpdates = new ArrayList<>();
+ id2FieldUpdateMap = new HashMap<>();
fieldPathUpdates = new ArrayList<>();
reader.read(this);
}
@@ -79,10 +86,11 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
this(docType, new DocumentId(docId));
}
- private DocumentUpdate(DocumentType docType, DocumentId docId, List<FieldUpdate> fieldUpdates) {
+ private DocumentUpdate(DocumentType docType, DocumentId docId, Map<Integer, FieldUpdate> id2fieldUpdateMap) {
this.docId = docId;
this.documentType = docType;
- this.fieldUpdates = fieldUpdates;
+ this.fieldUpdates = new ArrayList<>(id2fieldUpdateMap.values());
+ id2FieldUpdateMap = id2fieldUpdateMap;
this.fieldPathUpdates = new ArrayList<>();
}
@@ -114,7 +122,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
public DocumentUpdate applyTo(Document doc) {
verifyType(doc);
- for (FieldUpdate fieldUpdate : fieldUpdates) {
+ for (FieldUpdate fieldUpdate : id2FieldUpdateMap.values()) {
fieldUpdate.applyTo(doc);
}
for (FieldPathUpdate fieldPathUpdate : fieldPathUpdates) {
@@ -132,8 +140,9 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
public DocumentUpdate prune(Document doc) {
verifyType(doc);
- for (Iterator<FieldUpdate> iter = fieldUpdates.iterator(); iter.hasNext();) {
- FieldUpdate update = iter.next();
+ for (Iterator<Map.Entry<Integer, FieldUpdate>> iter = id2FieldUpdateMap.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry<Integer, FieldUpdate> entry = iter.next();
+ FieldUpdate update = entry.getValue();
if (!update.isEmpty()) {
ValueUpdate last = update.getValueUpdate(update.size() - 1);
if (last instanceof AssignValueUpdate) {
@@ -162,20 +171,42 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
* Get an unmodifiable list of all field updates that this document update specifies.
*
* @return a list of all FieldUpdates in this DocumentUpdate
+ * @deprecated Use fieldUpdates() instead.
*/
+ @Deprecated
public List<FieldUpdate> getFieldUpdates() {
- return Collections.unmodifiableList(fieldUpdates);
+ return Collections.unmodifiableList(new ArrayList<>(id2FieldUpdateMap.values()));
+ }
+
+ /**
+ * Get an unmodifiable collection of all field updates that this document update specifies.
+ *
+ * @return a collection of all FieldUpdates in this DocumentUpdate
+ */
+ public Collection<FieldUpdate> fieldUpdates() {
+ return Collections.unmodifiableCollection(id2FieldUpdateMap.values());
}
/**
* Get an unmodifiable list of all field path updates this document update specifies.
*
* @return Returns a list of all field path updates in this document update.
+ * @deprecated Use fieldPathUpdates() instead.
*/
+ @Deprecated
public List<FieldPathUpdate> getFieldPathUpdates() {
return Collections.unmodifiableList(fieldPathUpdates);
}
+ /**
+ * Get an unmodifiable collection of all field path updates that this document update specifies.
+ *
+ * @return a collection of all FieldPathUpdates in this DocumentUpdate
+ */
+ public Collection<FieldPathUpdate> fieldPathUpdates() {
+ return Collections.unmodifiableCollection(fieldPathUpdates);
+ }
+
/** Returns the type of the document this updates
*
* @return The documentype of the document
@@ -198,7 +229,9 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
* @param index the index of the FieldUpdate to return
* @return the FieldUpdate at the specified index
* @throws IndexOutOfBoundsException if index is out of range
+ * @deprecated use getFieldUpdate(Field field) instead.
*/
+ @Deprecated
public FieldUpdate getFieldUpdate(int index) {
return fieldUpdates.get(index);
}
@@ -210,9 +243,16 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
* @param upd the FieldUpdate to be stored at the specified position
* @return the FieldUpdate previously at the specified position
* @throws IndexOutOfBoundsException if index is out of range
+ * @deprecated Use removeFieldUpdate/addFieldUpdate instead
*/
+ @Deprecated
public FieldUpdate setFieldUpdate(int index, FieldUpdate upd) {
- return fieldUpdates.set(index, upd);
+ FieldUpdate old = fieldUpdates.get(index);
+ fieldUpdates.set(index, upd);
+ id2FieldUpdateMap.remove(old.getField().getId());
+ id2FieldUpdateMap.put(upd.getField().getId(), upd);
+
+ return old;
}
/**
@@ -222,12 +262,13 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
* @return the update for the field, or null if that field has no update in this
*/
public FieldUpdate getFieldUpdate(Field field) {
- return getFieldUpdate(field.getName());
+ return getFieldUpdateById(field.getId());
}
/** Removes all field updates from the list for field updates. */
public void clearFieldUpdates() {
fieldUpdates.clear();
+ id2FieldUpdateMap.clear();
}
/**
@@ -237,27 +278,34 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
* @return the update for the field, or null if that field has no update in this
*/
public FieldUpdate getFieldUpdate(String fieldName) {
- for (FieldUpdate fieldUpdate : fieldUpdates) {
- if (fieldUpdate.getField().getName().equals(fieldName)) {
- return fieldUpdate;
- }
- }
- return null;
+ Field field = documentType.getField(fieldName);
+ return field != null ? getFieldUpdate(field) : null;
+ }
+ private FieldUpdate getFieldUpdateById(Integer fieldId) {
+ return id2FieldUpdateMap.get(fieldId);
}
/**
* Assigns the field updates of this document update.
* This document update receives ownership of the list - it can not be subsequently used
- * by the caller. The list may not be unmodifiable.
+ * by the caller. Also note that there no assumptions can be made on the order of items
+ * after this call. They might have been joined if for the same field or reordered.
*
* @param fieldUpdates the new list of updates of this
* @throws NullPointerException if the argument passed is null
*/
- public void setFieldUpdates(List<FieldUpdate> fieldUpdates) {
+ public void setFieldUpdates(Collection<FieldUpdate> fieldUpdates) {
if (fieldUpdates == null) {
throw new NullPointerException("The field updates of a document update can not be null");
}
- this.fieldUpdates = fieldUpdates;
+ clearFieldUpdates();
+ addFieldUpdates(fieldUpdates);
+ }
+
+ public void addFieldUpdates(Collection<FieldUpdate> fieldUpdates) {
+ for (FieldUpdate fieldUpdate : fieldUpdates) {
+ addFieldUpdate(fieldUpdate);
+ }
}
/**
@@ -266,7 +314,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
* @return the size of the List of FieldUpdates
*/
public int size() {
- return fieldUpdates.size();
+ return id2FieldUpdateMap.size();
}
/**
@@ -279,17 +327,17 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
* field.
*/
public DocumentUpdate addFieldUpdate(FieldUpdate update) {
- String fieldName = update.getField().getName();
- if (!documentType.hasField(fieldName)) {
- throw new IllegalArgumentException("Document type '" + documentType.getName() + "' does not have field '" +
- fieldName + "'.");
+ Integer fieldId = update.getField().getId();
+ if (documentType.getField(fieldId) == null) {
+ throw new IllegalArgumentException("Document type '" + documentType.getName() + "' does not have field '" + update.getField().getName() + "'.");
}
- FieldUpdate prevUpdate = getFieldUpdate(fieldName);
+ FieldUpdate prevUpdate = getFieldUpdateById(fieldId);
if (prevUpdate != update) {
if (prevUpdate != null) {
prevUpdate.addAll(update);
} else {
fieldUpdates.add(update);
+ id2FieldUpdateMap.put(fieldId, update);
}
}
return this;
@@ -305,12 +353,6 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
return this;
}
- // TODO: Remove this when we figure out correct behaviour.
-
- public void addFieldUpdateNoCheck(FieldUpdate fieldUpdate) {
- fieldUpdates.add(fieldUpdate);
- }
-
/**
* Adds all the field- and field path updates of the given document update to this. If the given update refers to a
* different document or document type than this, this method throws an exception.
@@ -329,9 +371,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
if (!documentType.equals(update.documentType)) {
throw new IllegalArgumentException("Expected " + documentType + ", got " + update.documentType + ".");
}
- for (FieldUpdate fieldUpd : update.fieldUpdates) {
- addFieldUpdate(fieldUpd);
- }
+ addFieldUpdates(update.fieldUpdates());
for (FieldPathUpdate pathUpd : update.fieldPathUpdates) {
addFieldPathUpdate(pathUpd);
}
@@ -343,9 +383,22 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
* @param index the index of the FieldUpdate to remove
* @return the FieldUpdate previously at the specified position
* @throws IndexOutOfBoundsException if index is out of range
+ * @deprecated use removeFieldUpdate(Field field) instead.
*/
+ @Deprecated
public FieldUpdate removeFieldUpdate(int index) {
- return fieldUpdates.remove(index);
+ FieldUpdate prev = getFieldUpdate(index);
+ fieldUpdates.remove(index);
+ return removeFieldUpdate(prev.getField());
+ }
+
+ public FieldUpdate removeFieldUpdate(Field field) {
+ return id2FieldUpdateMap.remove(field.getId());
+ }
+
+ public FieldUpdate removeFieldUpdate(String fieldName) {
+ Field field = documentType.getField(fieldName);
+ return field != null ? removeFieldUpdate(field) : null;
}
/**
@@ -376,7 +429,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
if (documentType != null ? !documentType.equals(that.documentType) : that.documentType != null) return false;
if (fieldPathUpdates != null ? !fieldPathUpdates.equals(that.fieldPathUpdates) : that.fieldPathUpdates != null)
return false;
- if (fieldUpdates != null ? !fieldUpdates.equals(that.fieldUpdates) : that.fieldUpdates != null) return false;
+ if (id2FieldUpdateMap != null ? !id2FieldUpdateMap.equals(that.id2FieldUpdateMap) : that.id2FieldUpdateMap != null) return false;
if (this.getCreateIfNonExistent() != ((DocumentUpdate) o).getCreateIfNonExistent()) return false;
return true;
@@ -385,7 +438,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
@Override
public int hashCode() {
int result = docId != null ? docId.hashCode() : 0;
- result = 31 * result + (fieldUpdates != null ? fieldUpdates.hashCode() : 0);
+ result = 31 * result + (id2FieldUpdateMap != null ? id2FieldUpdateMap.hashCode() : 0);
result = 31 * result + (fieldPathUpdates != null ? fieldPathUpdates.hashCode() : 0);
result = 31 * result + (documentType != null ? documentType.hashCode() : 0);
return result;
@@ -402,7 +455,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
string.append(": ");
string.append("[");
- for (Iterator<FieldUpdate> i = fieldUpdates.iterator(); i.hasNext();) {
+ for (Iterator<FieldUpdate> i = id2FieldUpdateMap.values().iterator(); i.hasNext();) {
FieldUpdate fieldUpdate = i.next();
string.append(fieldUpdate);
if (i.hasNext()) {
@@ -432,7 +485,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP
* @return True if this update is empty.
*/
public boolean isEmpty() {
- return fieldUpdates.isEmpty() && fieldPathUpdates.isEmpty();
+ return id2FieldUpdateMap.isEmpty() && fieldPathUpdates.isEmpty();
}
/**
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 b9b273d691f..6adae27cadc 100644
--- a/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java
+++ b/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java
@@ -47,6 +47,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
@@ -105,11 +106,11 @@ public class DocumentUpdateJsonSerializer
}
generator.writeObjectFieldStart("fields");
- for (FieldUpdate up : update.getFieldUpdates()) {
+ for (FieldUpdate up : update.fieldUpdates()) {
up.serialize(this);
}
- update.getFieldPathUpdates().stream()
+ update.fieldPathUpdates().stream()
.collect(Collectors.groupingBy(FieldPathUpdate::getFieldPath))
.forEach((fieldPath, fieldPathUpdates) ->
wrapIOException(() -> write(fieldPath, fieldPathUpdates, generator)));
@@ -120,7 +121,7 @@ public class DocumentUpdateJsonSerializer
});
}
- private void write(FieldPath fieldPath, List<FieldPathUpdate> fieldPathUpdates, JsonGenerator generator) throws IOException {
+ private void write(FieldPath fieldPath, Collection<FieldPathUpdate> fieldPathUpdates, JsonGenerator generator) throws IOException {
generator.writeObjectFieldStart(fieldPath.toString());
for (FieldPathUpdate update : fieldPathUpdates) {
diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java
index a048ea349eb..3f885844987 100644
--- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java
+++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java
@@ -472,7 +472,7 @@ public class VespaDocumentDeserializer42 extends VespaDocumentSerializer42 imple
for (int i = 0; i < size; i++) {
// TODO: Should use checked method, but doesn't work according to test now.
- update.addFieldUpdateNoCheck(new FieldUpdate(this, update.getDocumentType(), serializationVersion));
+ update.addFieldUpdate(new FieldUpdate(this, update.getDocumentType(), serializationVersion));
}
}
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 7bdc6fd5355..4f8a26d3777 100644
--- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java
+++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java
@@ -29,7 +29,7 @@ public class VespaDocumentDeserializerHead extends VespaDocumentDeserializer42 {
for (int i = 0; i < size; i++) {
// TODO: Should use checked method, but doesn't work according to test now.
- update.addFieldUpdateNoCheck(new FieldUpdate(this, update.getDocumentType(), 8));
+ update.addFieldUpdate(new FieldUpdate(this, update.getDocumentType(), 8));
}
int sizeAndFlags = getInt(null);
diff --git a/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java b/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java
index 15319985591..a9f77cb5eb0 100644
--- a/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java
+++ b/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java
@@ -1,10 +1,19 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document;
-import com.yahoo.document.datatypes.*;
+import com.yahoo.document.datatypes.Array;
+import com.yahoo.document.datatypes.FloatFieldValue;
+import com.yahoo.document.datatypes.IntegerFieldValue;
+import com.yahoo.document.datatypes.StringFieldValue;
+import com.yahoo.document.datatypes.TensorFieldValue;
+import com.yahoo.document.datatypes.WeightedSet;
import com.yahoo.document.fieldpathupdate.FieldPathUpdate;
-import com.yahoo.document.select.parser.ParseException;
-import com.yahoo.document.serialization.*;
+import com.yahoo.document.serialization.DocumentDeserializer;
+import com.yahoo.document.serialization.DocumentDeserializerFactory;
+import com.yahoo.document.serialization.DocumentSerializer;
+import com.yahoo.document.serialization.DocumentSerializerFactory;
+import com.yahoo.document.serialization.DocumentUpdateFlags;
+import com.yahoo.document.serialization.DocumentUpdateWriter;
import com.yahoo.document.update.AssignValueUpdate;
import com.yahoo.document.update.FieldUpdate;
import com.yahoo.document.update.ValueUpdate;
@@ -259,8 +268,8 @@ public class DocumentUpdateTestCase {
update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(1)));
update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(2)));
- assertEquals(1, update.getFieldUpdates().size());
- FieldUpdate fieldUpdate = update.getFieldUpdate(0);
+ assertEquals(1, update.fieldUpdates().size());
+ FieldUpdate fieldUpdate = update.getFieldUpdate(field);
assertNotNull(fieldUpdate);
assertEquals(field, fieldUpdate.getField());
assertEquals(2, fieldUpdate.getValueUpdates().size());
@@ -342,13 +351,16 @@ public class DocumentUpdateTestCase {
assertEquals(new DocumentId("doc:update:test"), upd.getId());
assertEquals(type, upd.getType());
- FieldUpdate serAssignFU = upd.getFieldUpdate(0);
+ FieldUpdate serAssignFU = upd.getFieldUpdate(type.getField("intfield"));
assertEquals(type.getField("intfield"), serAssignFU.getField());
ValueUpdate serAssign = serAssignFU.getValueUpdate(0);
assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, serAssign.getValueUpdateClassID());
assertEquals(new IntegerFieldValue(4), serAssign.getValue());
- FieldUpdate serAddFU = upd.getFieldUpdate(2);
+ ValueUpdate serArith = serAssignFU.getValueUpdate(1);
+ assertEquals(ValueUpdate.ValueUpdateClassID.ARITHMETIC, serArith.getValueUpdateClassID());
+
+ FieldUpdate serAddFU = upd.getFieldUpdate(type.getField("arrayoffloatfield"));
assertEquals(type.getField("arrayoffloatfield"), serAddFU.getField());
ValueUpdate serAdd1 = serAddFU.getValueUpdate(0);
assertEquals(ValueUpdate.ValueUpdateClassID.ADD, serAdd1.getValueUpdateClassID());
@@ -363,12 +375,7 @@ public class DocumentUpdateTestCase {
FloatFieldValue addparam3 = (FloatFieldValue)serAdd3.getValue();
assertEquals(new FloatFieldValue(-1.00f), addparam3);
- FieldUpdate arithFU = upd.getFieldUpdate(3);
- assertEquals(type.getField("intfield"), serAssignFU.getField());
- ValueUpdate serArith = arithFU.getValueUpdate(0);
- assertEquals(ValueUpdate.ValueUpdateClassID.ARITHMETIC, serArith.getValueUpdateClassID());
-
- FieldUpdate wsetFU = upd.getFieldUpdate(4);
+ FieldUpdate wsetFU = upd.getFieldUpdate(type.getField("wsfield"));
assertEquals(type.getField("wsfield"), wsetFU.getField());
assertEquals(2, wsetFU.size());
ValueUpdate mapUpd = wsetFU.getValueUpdate(0);
@@ -420,8 +427,8 @@ public class DocumentUpdateTestCase {
barUpdate.addFieldUpdate(barField);
fooUpdate.addAll(barUpdate);
- assertEquals(1, fooUpdate.getFieldUpdates().size());
- FieldUpdate fieldUpdate = fooUpdate.getFieldUpdate(0);
+ assertEquals(1, fooUpdate.fieldUpdates().size());
+ FieldUpdate fieldUpdate = fooUpdate.getFieldUpdate(field);
assertNotNull(fieldUpdate);
assertEquals(field, fieldUpdate.getField());
assertEquals(2, fieldUpdate.getValueUpdates().size());
@@ -435,6 +442,32 @@ public class DocumentUpdateTestCase {
}
@Test
+ public void testGetAndRemoveByName() {
+ DocumentType docType = new DocumentType("my_type");
+ Field my_int = new Field("my_int", DataType.INT);
+ Field your_int = new Field("your_int", DataType.INT);
+ docType.addField(my_int);
+ docType.addField(your_int);
+ DocumentUpdate update = new DocumentUpdate(docType, new DocumentId("doc:this:is:a:test"));
+
+ update.addFieldUpdate(FieldUpdate.createAssign(my_int, new IntegerFieldValue(2)));
+ assertNull(update.getFieldUpdate("none-existing-field"));
+ assertNull(update.removeFieldUpdate("none-existing-field"));
+ assertNull(update.getFieldUpdate("your_int"));
+ assertEquals(new IntegerFieldValue(2), update.getFieldUpdate("my_int").getValueUpdate(0).getValue());
+ assertNull(update.removeFieldUpdate("your_int"));
+ assertEquals(new IntegerFieldValue(2), update.removeFieldUpdate("my_int").getValueUpdate(0).getValue());
+ assertNull(update.getFieldUpdate("my_int"));
+
+ update.addFieldUpdate(FieldUpdate.createAssign(my_int, new IntegerFieldValue(2)));
+ assertNull(update.getFieldUpdate(your_int));
+ assertEquals(new IntegerFieldValue(2), update.getFieldUpdate(my_int).getValueUpdate(0).getValue());
+ assertNull(update.removeFieldUpdate(your_int));
+ assertEquals(new IntegerFieldValue(2), update.removeFieldUpdate(my_int).getValueUpdate(0).getValue());
+ assertNull(update.getFieldUpdate(my_int));
+ }
+
+ @Test
public void testInstantiationAndEqualsHashCode() {
DocumentType type = new DocumentType("doo");
DocumentUpdate d1 = new DocumentUpdate(type, new DocumentId("doc:this:is:a:test"));
@@ -465,6 +498,7 @@ public class DocumentUpdateTestCase {
}
@Test
+ @SuppressWarnings("deprecation")
public void testFieldUpdatesInDocUp() {
DocumentType t1 = new DocumentType("doo");
Field f1 = new Field("field1", DataType.STRING);
@@ -493,14 +527,6 @@ public class DocumentUpdateTestCase {
assertSame(fu1, documentUpdate.getFieldUpdate(f1));
- assertSame(fu1, documentUpdate.getFieldUpdate(0));
- assertSame(fu2, documentUpdate.getFieldUpdate(1));
-
- documentUpdate.setFieldUpdate(0, fu2);
- documentUpdate.setFieldUpdate(1, fu1);
- assertEquals(2, documentUpdate.size());
- assertSame(fu1, documentUpdate.getFieldUpdate(1));
- assertSame(fu2, documentUpdate.getFieldUpdate(0));
try {
documentUpdate.setFieldUpdates(null);
@@ -515,12 +541,12 @@ public class DocumentUpdateTestCase {
documentUpdate.setFieldUpdates(fus);
assertEquals(2, documentUpdate.size());
- assertSame(fu1, documentUpdate.getFieldUpdate(0));
- assertSame(fu2, documentUpdate.getFieldUpdate(1));
+ assertSame(fu1, documentUpdate.getFieldUpdate(fu1.getField()));
+ assertSame(fu2, documentUpdate.getFieldUpdate(fu2.getField()));
- documentUpdate.removeFieldUpdate(1);
+ documentUpdate.removeFieldUpdate(fu2.getField());
assertEquals(1, documentUpdate.size());
- assertSame(fu1, documentUpdate.getFieldUpdate(0));
+ assertSame(fu1, documentUpdate.getFieldUpdate(fu1.getField()));
documentUpdate.toString();
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 1fd45cb07c4..32f63e6c0b3 100644
--- a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
+++ b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
@@ -292,8 +292,8 @@ public class JsonReaderTestCase {
+ "\"skuggsjaa\": {"
+ "\"assign\": { \"sandra\": \"person\","
+ " \"cloud\": \"another person\"}}}}");
- assertEquals(1, put.getFieldUpdates().size());
- FieldUpdate fu = put.getFieldUpdate(0);
+ assertEquals(1, put.fieldUpdates().size());
+ FieldUpdate fu = put.fieldUpdates().iterator().next();
assertEquals(1, fu.getValueUpdates().size());
ValueUpdate vu = fu.getValueUpdate(0);
assertTrue(vu instanceof AssignValueUpdate);
@@ -315,8 +315,8 @@ public class JsonReaderTestCase {
+ " \"fields\": { "
+ "\"skuggsjaa\": {"
+ "\"assign\": { }}}}");
- assertEquals(1, put.getFieldUpdates().size());
- FieldUpdate fu = put.getFieldUpdate(0);
+ assertEquals(1, put.fieldUpdates().size());
+ FieldUpdate fu = put.fieldUpdates().iterator().next();
assertEquals(1, fu.getValueUpdates().size());
ValueUpdate vu = fu.getValueUpdate(0);
assertTrue(vu instanceof AssignValueUpdate);
diff --git a/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java b/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java
index ea954f0da40..dcdea0975ad 100644
--- a/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java
+++ b/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java
@@ -46,8 +46,8 @@ public class UriParserTestCase {
DocumentUpdate upd = nextUpdate(it);
assertNotNull(upd);
- assertEquals(1, upd.getFieldUpdates().size());
- FieldUpdate fieldUpd = upd.getFieldUpdate(0);
+ assertEquals(1, upd.fieldUpdates().size());
+ FieldUpdate fieldUpd = upd.fieldUpdates().iterator().next();
assertNotNull(fieldUpd);
assertEquals(docType.getField("my_arr"), fieldUpd.getField());
assertEquals(1, fieldUpd.getValueUpdates().size());
diff --git a/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java b/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java
index 4c64f7c35cb..1aad59f4c56 100755
--- a/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java
+++ b/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java
@@ -5,6 +5,7 @@ import com.yahoo.document.*;
import com.yahoo.document.datatypes.*;
import com.yahoo.document.fieldpathupdate.AddFieldPathUpdate;
import com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate;
+import com.yahoo.document.fieldpathupdate.FieldPathUpdate;
import com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate;
import com.yahoo.document.serialization.DeserializationException;
import com.yahoo.document.update.AddValueUpdate;
@@ -16,6 +17,7 @@ import org.junit.Before;
import org.junit.Test;
import java.io.ByteArrayInputStream;
+import java.util.Iterator;
import java.util.List;
import static org.junit.Assert.*;
@@ -687,103 +689,105 @@ public class VespaXMLReaderTestCase {
DocumentUpdate docUpdate = op.getDocumentUpdate();
- assertEquals(20, docUpdate.getFieldPathUpdates().size());
+ assertEquals(20, docUpdate.fieldPathUpdates().size());
+ Iterator<FieldPathUpdate> updates = docUpdate.fieldPathUpdates().iterator();
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(0);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("url", ass.getOriginalFieldPath());
assertEquals(new StringFieldValue("assignUrl"), ass.getNewValue());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(1);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("title", ass.getOriginalFieldPath());
assertEquals(new StringFieldValue("assignTitle"), ass.getNewValue());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(2);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("last_downloaded", ass.getOriginalFieldPath());
assertEquals("1", ass.getExpression());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(3);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("value_long", ass.getOriginalFieldPath());
assertEquals("2", ass.getExpression());
}
+ updates.next(); // Skip number 5
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(5);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("stringarr", ass.getOriginalFieldPath());
assertEquals("[assignString1, assignString2]", ass.getNewValue().toString());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(6);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("intarr", ass.getOriginalFieldPath());
assertEquals("[3, 4]", ass.getNewValue().toString());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(7);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("longarr", ass.getOriginalFieldPath());
assertEquals("[5, 6]", ass.getNewValue().toString());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(8);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("bytearr", ass.getOriginalFieldPath());
assertEquals("[7, 8]", ass.getNewValue().toString());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(9);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("floatarr", ass.getOriginalFieldPath());
assertEquals("[9.0, 10.0]", ass.getNewValue().toString());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(10);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("weightedsetint", ass.getOriginalFieldPath());
WeightedSet set = (WeightedSet)ass.getNewValue();
assertEquals(Integer.valueOf(11), set.get(new IntegerFieldValue(11)));
assertEquals(Integer.valueOf(12), set.get(new IntegerFieldValue(12)));
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(11);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("weightedsetstring", ass.getOriginalFieldPath());
WeightedSet set = (WeightedSet)ass.getNewValue();
assertEquals(Integer.valueOf(13), set.get(new StringFieldValue("assign13")));
assertEquals(Integer.valueOf(14), set.get(new StringFieldValue("assign14")));
}
{
- AddFieldPathUpdate ass = (AddFieldPathUpdate)docUpdate.getFieldPathUpdates().get(12);
+ AddFieldPathUpdate ass = (AddFieldPathUpdate)updates.next();
assertEquals("stringarr", ass.getOriginalFieldPath());
assertEquals("[addString1, addString2]", ass.getNewValues().toString());
}
{
- AddFieldPathUpdate ass = (AddFieldPathUpdate)docUpdate.getFieldPathUpdates().get(13);
+ AddFieldPathUpdate ass = (AddFieldPathUpdate)updates.next();
assertEquals("longarr", ass.getOriginalFieldPath());
assertEquals("[5]", ass.getNewValues().toString());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(14);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("weightedsetint{13}", ass.getOriginalFieldPath());
assertEquals("13", ass.getExpression());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(15);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("weightedsetint{14}", ass.getOriginalFieldPath());
assertEquals("14", ass.getExpression());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(16);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("weightedsetstring{add13}", ass.getOriginalFieldPath());
assertEquals("1", ass.getExpression());
}
{
- AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(17);
+ AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next();
assertEquals("weightedsetstring{assign13}", ass.getOriginalFieldPath());
assertEquals("130", ass.getExpression());
}
{
- RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)docUpdate.getFieldPathUpdates().get(18);
+ RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)updates.next();
assertEquals("weightedsetstring{assign14}", ass.getOriginalFieldPath());
}
{
- RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)docUpdate.getFieldPathUpdates().get(19);
+ RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)updates.next();
assertEquals("bytearr", ass.getOriginalFieldPath());
}
Document doc = new Document(manager.getDocumentType("news"), new DocumentId("doc:test:test:test"));
diff --git a/document/src/tests/data/serializeupdatejava.dat b/document/src/tests/data/serializeupdatejava.dat
index e2a98d42fb1..20c56228bde 100644
--- a/document/src/tests/data/serializeupdatejava.dat
+++ b/document/src/tests/data/serializeupdatejava.dat
Binary files differ
diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/SimpleAdapterFactory.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/SimpleAdapterFactory.java
index 43ccd6d48a8..35bb70c2a88 100644
--- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/SimpleAdapterFactory.java
+++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/SimpleAdapterFactory.java
@@ -61,7 +61,7 @@ public class SimpleAdapterFactory implements AdapterFactory {
throw new IllegalArgumentException("Exception during handling of update '" + fieldUpd + "' to field '" + fieldUpd.getFieldPath() + "'", e);
}
}
- for (FieldUpdate fieldUpd : upd.getFieldUpdates()) {
+ for (FieldUpdate fieldUpd : upd.fieldUpdates()) {
Field field = fieldUpd.getField();
for (ValueUpdate valueUpd : fieldUpd.getValueUpdates()) {
try {
diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentToPathUpdateTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentToPathUpdateTestCase.java
index 459f3ce827c..3c5eb9ea1c5 100644
--- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentToPathUpdateTestCase.java
+++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentToPathUpdateTestCase.java
@@ -29,8 +29,8 @@ public class DocumentToPathUpdateTestCase {
DocumentUpdate docUpd = new FieldPathUpdateAdapter(new SimpleDocumentAdapter(null, doc), upd).getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldPathUpdates().size());
- assertNotNull(upd = docUpd.getFieldPathUpdates().get(0));
+ assertEquals(1, docUpd.fieldPathUpdates().size());
+ assertNotNull(upd = docUpd.fieldPathUpdates().iterator().next());
assertTrue(upd instanceof AssignFieldPathUpdate);
assertEquals("my_int", upd.getOriginalFieldPath());
@@ -49,8 +49,8 @@ public class DocumentToPathUpdateTestCase {
DocumentUpdate docUpd = new FieldPathUpdateAdapter(new SimpleDocumentAdapter(null, doc), upd).getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldPathUpdates().size());
- assertNotNull(upd = docUpd.getFieldPathUpdates().get(0));
+ assertEquals(1, docUpd.fieldPathUpdates().size());
+ assertNotNull(upd = docUpd.fieldPathUpdates().iterator().next());
assertTrue(upd instanceof AssignFieldPathUpdate);
assertEquals("my_str", upd.getOriginalFieldPath());
@@ -77,8 +77,8 @@ public class DocumentToPathUpdateTestCase {
DocumentUpdate docUpd = new FieldPathUpdateAdapter(new SimpleDocumentAdapter(null, doc), upd).getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldPathUpdates().size());
- assertNotNull(upd = docUpd.getFieldPathUpdates().get(0));
+ assertEquals(1, docUpd.fieldPathUpdates().size());
+ assertNotNull(upd = docUpd.fieldPathUpdates().iterator().next());
assertTrue(upd instanceof AssignFieldPathUpdate);
assertEquals("a", upd.getOriginalFieldPath());
@@ -103,8 +103,8 @@ public class DocumentToPathUpdateTestCase {
DocumentUpdate docUpd = new FieldPathUpdateAdapter(new SimpleDocumentAdapter(null, doc), upd).getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldPathUpdates().size());
- assertNotNull(upd = docUpd.getFieldPathUpdates().get(0));
+ assertEquals(1, docUpd.fieldPathUpdates().size());
+ assertNotNull(upd = docUpd.fieldPathUpdates().iterator().next());
assertTrue(upd instanceof AssignFieldPathUpdate);
assertEquals("a.b", upd.getOriginalFieldPath());
diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentToValueUpdateTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentToValueUpdateTestCase.java
index de090163b7b..83947b5f64d 100644
--- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentToValueUpdateTestCase.java
+++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentToValueUpdateTestCase.java
@@ -40,8 +40,8 @@ public class DocumentToValueUpdateTestCase {
UpdateAdapter adapter = FieldUpdateAdapter.fromPartialUpdate(new SimpleDocumentAdapter(null, doc), valueUpd);
DocumentUpdate docUpd = adapter.getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldUpdates().size());
- assertEquals("my_int", docUpd.getFieldUpdate(0).getField().getName());
+ assertEquals(1, docUpd.fieldUpdates().size());
+ assertEquals("my_int", docUpd.fieldUpdates().iterator().next().getField().getName());
}
@Test
@@ -56,9 +56,9 @@ public class DocumentToValueUpdateTestCase {
UpdateAdapter adapter = FieldUpdateAdapter.fromPartialUpdate(new SimpleDocumentAdapter(null, doc), valueUpd);
DocumentUpdate docUpd = adapter.getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldUpdates().size());
+ assertEquals(1, docUpd.fieldUpdates().size());
- FieldUpdate fieldUpd = docUpd.getFieldUpdate(0);
+ FieldUpdate fieldUpd = docUpd.fieldUpdates().iterator().next();
assertNotNull(fieldUpd);
assertEquals(docType.getField("my_int"), fieldUpd.getField());
@@ -80,9 +80,9 @@ public class DocumentToValueUpdateTestCase {
UpdateAdapter adapter = FieldUpdateAdapter.fromPartialUpdate(new SimpleDocumentAdapter(null, doc), valueUpd);
DocumentUpdate docUpd = adapter.getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldUpdates().size());
+ assertEquals(1, docUpd.fieldUpdates().size());
- FieldUpdate fieldUpd = docUpd.getFieldUpdate(0);
+ FieldUpdate fieldUpd = docUpd.fieldUpdates().iterator().next();
assertNotNull(fieldUpd);
assertEquals(docType.getField("my_int"), fieldUpd.getField());
@@ -103,9 +103,9 @@ public class DocumentToValueUpdateTestCase {
UpdateAdapter adapter = FieldUpdateAdapter.fromPartialUpdate(new SimpleDocumentAdapter(null, doc), valueUpd);
DocumentUpdate docUpd = adapter.getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldUpdates().size());
+ assertEquals(1, docUpd.fieldUpdates().size());
- FieldUpdate fieldUpd = docUpd.getFieldUpdate(0);
+ FieldUpdate fieldUpd = docUpd.fieldUpdates().iterator().next();
assertNotNull(fieldUpd);
assertEquals(docType.getField("my_str"), fieldUpd.getField());
@@ -136,9 +136,9 @@ public class DocumentToValueUpdateTestCase {
UpdateAdapter adapter = FieldUpdateAdapter.fromPartialUpdate(new SimpleDocumentAdapter(null, doc), valueUpd);
DocumentUpdate docUpd = adapter.getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldUpdates().size());
+ assertEquals(1, docUpd.fieldUpdates().size());
- FieldUpdate fieldUpd = docUpd.getFieldUpdate(0);
+ FieldUpdate fieldUpd = docUpd.fieldUpdates().iterator().next();
assertNotNull(fieldUpd);
assertEquals(docType.getField("a"), fieldUpd.getField());
@@ -166,9 +166,9 @@ public class DocumentToValueUpdateTestCase {
UpdateAdapter adapter = FieldUpdateAdapter.fromPartialUpdate(new SimpleDocumentAdapter(null, doc), valueUpd);
DocumentUpdate docUpd = adapter.getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldUpdates().size());
+ assertEquals(1, docUpd.fieldUpdates().size());
- FieldUpdate fieldUpd = docUpd.getFieldUpdate(0);
+ FieldUpdate fieldUpd = docUpd.fieldUpdates().iterator().next();
assertNotNull(fieldUpd);
assertEquals(docType.getField("my_arr"), fieldUpd.getField());
@@ -196,9 +196,9 @@ public class DocumentToValueUpdateTestCase {
UpdateAdapter adapter = FieldUpdateAdapter.fromPartialUpdate(new SimpleDocumentAdapter(null, doc), valueUpd);
DocumentUpdate docUpd = adapter.getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldUpdates().size());
+ assertEquals(1, docUpd.fieldUpdates().size());
- FieldUpdate fieldUpd = docUpd.getFieldUpdate(0);
+ FieldUpdate fieldUpd = docUpd.fieldUpdates().iterator().next();
assertNotNull(fieldUpd);
assertEquals(docType.getField("my_arr"), fieldUpd.getField());
@@ -231,9 +231,9 @@ public class DocumentToValueUpdateTestCase {
UpdateAdapter adapter = FieldUpdateAdapter.fromPartialUpdate(new SimpleDocumentAdapter(null, doc), valueUpd);
DocumentUpdate docUpd = adapter.getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldUpdates().size());
+ assertEquals(1, docUpd.fieldUpdates().size());
- FieldUpdate fieldUpd = docUpd.getFieldUpdate(0);
+ FieldUpdate fieldUpd = docUpd.fieldUpdates().iterator().next();
assertNotNull(fieldUpd);
assertEquals(docType.getField("a"), fieldUpd.getField());
@@ -261,9 +261,9 @@ public class DocumentToValueUpdateTestCase {
UpdateAdapter adapter = FieldUpdateAdapter.fromPartialUpdate(new SimpleDocumentAdapter(null, doc), valueUpd);
DocumentUpdate docUpd = adapter.getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldUpdates().size());
+ assertEquals(1, docUpd.fieldUpdates().size());
- FieldUpdate fieldUpd = docUpd.getFieldUpdate(0);
+ FieldUpdate fieldUpd = docUpd.fieldUpdates().iterator().next();
assertNotNull(fieldUpd);
assertEquals(docType.getField("my_wset"), fieldUpd.getField());
@@ -294,9 +294,9 @@ public class DocumentToValueUpdateTestCase {
UpdateAdapter adapter = FieldUpdateAdapter.fromPartialUpdate(new SimpleDocumentAdapter(null, doc), valueUpd);
DocumentUpdate docUpd = adapter.getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldUpdates().size());
+ assertEquals(1, docUpd.fieldUpdates().size());
- FieldUpdate fieldUpd = docUpd.getFieldUpdate(0);
+ FieldUpdate fieldUpd = docUpd.fieldUpdates().iterator().next();
assertNotNull(fieldUpd);
assertEquals(docType.getField("my_wset"), fieldUpd.getField());
@@ -326,9 +326,9 @@ public class DocumentToValueUpdateTestCase {
UpdateAdapter adapter = FieldUpdateAdapter.fromPartialUpdate(new SimpleDocumentAdapter(null, doc), valueUpd);
DocumentUpdate docUpd = adapter.getOutput();
assertNotNull(docUpd);
- assertEquals(1, docUpd.getFieldUpdates().size());
+ assertEquals(1, docUpd.fieldUpdates().size());
- FieldUpdate fieldUpd = docUpd.getFieldUpdate(0);
+ FieldUpdate fieldUpd = docUpd.fieldUpdates().iterator().next();
assertNotNull(fieldUpd);
assertEquals(docType.getField("my_wset"), fieldUpd.getField());
diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentUpdateTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentUpdateTestCase.java
index bdb8dbedf78..dc8ffcd8d10 100644
--- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentUpdateTestCase.java
+++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentUpdateTestCase.java
@@ -32,10 +32,10 @@ public class DocumentUpdateTestCase {
docUpdate = Expression.execute(Expression.fromString("input my_str | for_each { to_pos } | index my_pos"), docUpdate);
assertNotNull(docUpdate);
- assertEquals(0, docUpdate.getFieldPathUpdates().size());
- assertEquals(1, docUpdate.getFieldUpdates().size());
+ assertEquals(0, docUpdate.fieldPathUpdates().size());
+ assertEquals(1, docUpdate.fieldUpdates().size());
- FieldUpdate fieldUpd = docUpdate.getFieldUpdate(0);
+ FieldUpdate fieldUpd = docUpdate.fieldUpdates().iterator().next();
assertNotNull(fieldUpd);
assertEquals(docType.getField("my_pos"), fieldUpd.getField());
assertEquals(1, fieldUpd.getValueUpdates().size());
diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GuardTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GuardTestCase.java
index 033034fed1f..63a2cc66a97 100644
--- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GuardTestCase.java
+++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/GuardTestCase.java
@@ -72,10 +72,10 @@ public class GuardTestCase {
docUpdate.addFieldUpdate(FieldUpdate.createAssign(docType.getField("my_str"), new StringFieldValue("69")));
assertNotNull(docUpdate = Expression.execute(Expression.fromString("guard { input my_str | to_int | attribute my_lng }"), docUpdate));
- assertEquals(0, docUpdate.getFieldPathUpdates().size());
- assertEquals(1, docUpdate.getFieldUpdates().size());
+ assertEquals(0, docUpdate.fieldPathUpdates().size());
+ assertEquals(1, docUpdate.fieldUpdates().size());
- FieldUpdate fieldUpd = docUpdate.getFieldUpdate(0);
+ FieldUpdate fieldUpd = docUpdate.fieldUpdates().iterator().next();
assertNotNull(fieldUpd);
assertEquals(docType.getField("my_lng"), fieldUpd.getField());
assertEquals(1, fieldUpd.getValueUpdates().size());
diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java
index 5f44b06ab77..ff968b941a2 100644
--- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java
+++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java
@@ -38,7 +38,7 @@ public class MockedOperationHandler implements OperationHandler {
@Override
public void update(RestUri restUri, VespaXMLFeedReader.Operation data, Optional<String> route) throws RestApiException {
log.append("UPDATE: " + data.getDocumentUpdate().getId());
- log.append(data.getDocumentUpdate().getFieldUpdates().toString());
+ log.append(data.getDocumentUpdate().fieldUpdates().toString());
if (data.getDocumentUpdate().getCreateIfNonExistent()) {
log.append("[CREATE IF NON EXISTENT IS TRUE]");
}