1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.fieldpathupdate;
import com.yahoo.document.Document;
import com.yahoo.document.DocumentType;
import com.yahoo.document.datatypes.FieldPathIteratorHandler;
import com.yahoo.document.datatypes.FieldValue;
import com.yahoo.document.serialization.DocumentUpdateReader;
/**
* RemoveFieldPathUpdate is used to remove fields or portions of fields based on the field path supplied and optionally
* a where clause.
*
* If document type "testdoc" has a field "ivec" which is an array of integers, then the field path and where clause
* to remove all array elements having the value 5 is "ivec[$x]" and "testdoc.ivec[$x] == 5".
*
* If document type "testdoc" has a field "svec" which is an array of struct containing an integer field "ival" then
* "svec[$x]" and "testdoc.svec[$x].ival == 5" can be used to remove all array elements where ival is 5.
*
* @author <a href="mailto:thomasg@yahoo-inc.com">Thomas Gundersen</a>
*/
public class RemoveFieldPathUpdate extends FieldPathUpdate {
class IteratorHandler extends FieldPathIteratorHandler {
IteratorHandler() {
}
@Override
public ModificationStatus doModify(FieldValue fv) {
return ModificationStatus.REMOVED;
}
@Override
public boolean onComplex(FieldValue fv) {
return false;
}
}
IteratorHandler handler;
public RemoveFieldPathUpdate(DocumentType type, String fieldPath, String whereClause) {
super(FieldPathUpdate.Type.REMOVE, type, fieldPath, whereClause);
handler = new IteratorHandler();
}
public RemoveFieldPathUpdate(DocumentType type, String fieldPath) {
super(FieldPathUpdate.Type.REMOVE, type, fieldPath, null);
handler = new IteratorHandler();
}
public RemoveFieldPathUpdate(DocumentType type, DocumentUpdateReader reader) {
super(FieldPathUpdate.Type.REMOVE, type, reader);
reader.read(this);
handler = new IteratorHandler();
}
FieldPathIteratorHandler getIteratorHandler(Document doc) {
return handler;
}
@Override
public String toString() {
return "Remove: " + super.toString();
}
}
|