use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class VespaXMLUpdateReader method readAdd.
FieldUpdate readAdd(DocumentUpdate update) throws XMLStreamException {
for (int i = 0; i < reader.getAttributeCount(); i++) {
if ("field".equals(reader.getAttributeName(i).toString())) {
Field f = update.getDocumentType().getField(reader.getAttributeValue(i));
FieldValue value = f.getDataType().createFieldValue();
value.deserialize(f, this);
if (value instanceof Array) {
List<FieldValue> l = ((Array) value).getValues();
return FieldUpdate.createAddAll(f, l);
} else if (value instanceof WeightedSet) {
return FieldUpdate.createAddAll(f, ((WeightedSet) value));
} else {
throw newDeserializeException("Add operation only applicable to multivalue lists");
}
}
}
throw newDeserializeException("Add update without field attribute");
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class MapReader method fillMapFromArray.
@SuppressWarnings({ "rawtypes", "cast", "unchecked" })
public static void fillMapFromArray(TokenBuffer buffer, MapFieldValue parent) {
JsonToken token = buffer.currentToken();
int initNesting = buffer.nesting();
expectArrayStart(token);
token = buffer.next();
DataType keyType = parent.getDataType().getKeyType();
DataType valueType = parent.getDataType().getValueType();
while (buffer.nesting() >= initNesting) {
FieldValue key = null;
FieldValue value = null;
expectObjectStart(token);
token = buffer.next();
for (int i = 0; i < 2; ++i) {
if (MAP_KEY.equals(buffer.currentName())) {
key = readSingleValue(buffer, keyType);
} else if (MAP_VALUE.equals(buffer.currentName())) {
value = readSingleValue(buffer, valueType);
}
token = buffer.next();
}
Preconditions.checkState(key != null && value != null, "Missing key or value for map entry.");
parent.put(key, value);
expectObjectEnd(token);
// array end or next entry
token = buffer.next();
}
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class MapReader method fillMapFromObject.
@SuppressWarnings({ "rawtypes", "cast", "unchecked" })
public static void fillMapFromObject(TokenBuffer buffer, MapFieldValue parent) {
JsonToken token = buffer.currentToken();
int initNesting = buffer.nesting();
expectObjectStart(token);
token = buffer.next();
DataType keyType = parent.getDataType().getKeyType();
DataType valueType = parent.getDataType().getValueType();
while (buffer.nesting() >= initNesting) {
FieldValue key = readAtomic(buffer.currentName(), keyType);
FieldValue value = readSingleValue(buffer, valueType);
Preconditions.checkState(key != null && value != null, "Missing key or value for map entry.");
parent.put(key, value);
token = buffer.next();
}
expectObjectEnd(token);
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class VespaJsonDocumentReader method readAddFieldPathUpdate.
private AddFieldPathUpdate readAddFieldPathUpdate(DocumentType documentType, String fieldPath, TokenBuffer buffer) {
AddFieldPathUpdate fieldPathUpdate = new AddFieldPathUpdate(documentType, fieldPath);
FieldValue fv = SingleValueReader.readSingleValue(buffer, fieldPathUpdate.getFieldPath().getResultingDataType());
fieldPathUpdate.setNewValues((Array) fv);
return fieldPathUpdate;
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class VespaJsonDocumentReader method readAssignFieldPathUpdate.
private AssignFieldPathUpdate readAssignFieldPathUpdate(DocumentType documentType, String fieldPath, TokenBuffer buffer) {
AssignFieldPathUpdate fieldPathUpdate = new AssignFieldPathUpdate(documentType, fieldPath);
FieldValue fv = SingleValueReader.readSingleValue(buffer, fieldPathUpdate.getFieldPath().getResultingDataType());
fieldPathUpdate.setNewValue(fv);
return fieldPathUpdate;
}
Aggregations