use of com.yahoo.document.datatypes.Array in project vespa by vespa-engine.
the class VespaXMLUpdateReader method readRemove.
FieldUpdate readRemove(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.createRemoveAll(f, l);
} else if (value instanceof WeightedSet) {
return FieldUpdate.createRemoveAll(f, ((WeightedSet) value));
} else {
throw newDeserializeException("Remove operation only applicable to multivalue lists");
}
}
}
throw newDeserializeException("Remove update without field attribute");
}
use of com.yahoo.document.datatypes.Array 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.Array in project vespa by vespa-engine.
the class JoinerDocumentProcessor method process.
@Override
public Progress process(Processing processing) {
if (!doProcessOuterDocument(processing.getVariable(contextFieldName), documentTypeName)) {
return Progress.DONE;
}
DocumentPut outerDoc = (DocumentPut) processing.getVariable(contextFieldName);
@SuppressWarnings("unchecked") Array<Document> innerDocuments = (Array<Document>) outerDoc.getDocument().getFieldValue(arrayFieldName);
if (innerDocuments == null) {
@SuppressWarnings("unchecked") Array<Document> empty = (Array<Document>) outerDoc.getDocument().getDataType().getField(arrayFieldName).getDataType().createFieldValue();
innerDocuments = empty;
}
for (DocumentOperation op : processing.getDocumentOperations()) {
if (op instanceof DocumentPut) {
innerDocuments.add(((DocumentPut) op).getDocument());
} else {
log.log(LogLevel.DEBUG, "Skipping: " + op);
}
}
processing.getDocumentOperations().clear();
processing.getDocumentOperations().add(outerDoc);
processing.removeVariable(contextFieldName);
return Progress.DONE;
}
use of com.yahoo.document.datatypes.Array in project vespa by vespa-engine.
the class JsonReaderTestCase method testArray.
@Test
public final void testArray() throws IOException {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testarray::whee\"," + " \"fields\": { \"actualarray\": [" + " \"nalle\"," + " \"tralle\"]}}"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentParseInfo parseInfo = r.parseDocument().get();
DocumentType docType = r.readDocumentType(parseInfo.documentId);
DocumentPut put = new DocumentPut(new Document(docType, parseInfo.documentId));
new VespaJsonDocumentReader().readPut(parseInfo.fieldsBuffer, put);
Document doc = put.getDocument();
FieldValue f = doc.getFieldValue(doc.getField("actualarray"));
assertSame(Array.class, f.getClass());
Array<?> a = (Array<?>) f;
assertEquals(2, a.size());
assertEquals(new StringFieldValue("nalle"), a.get(0));
assertEquals(new StringFieldValue("tralle"), a.get(1));
}
use of com.yahoo.document.datatypes.Array in project vespa by vespa-engine.
the class JsonReaderTestCase method testOldMapStringToArrayOfInt.
@Test
public final void testOldMapStringToArrayOfInt() throws IOException {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testMapStringToArrayOfInt::whee\"," + " \"fields\": { \"actualMapStringToArrayOfInt\": [" + "{ \"key\": \"bamse\", \"value\": [1, 2, 3] }" + "]}}"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentParseInfo parseInfo = r.parseDocument().get();
DocumentType docType = r.readDocumentType(parseInfo.documentId);
DocumentPut put = new DocumentPut(new Document(docType, parseInfo.documentId));
new VespaJsonDocumentReader().readPut(parseInfo.fieldsBuffer, put);
Document doc = put.getDocument();
FieldValue f = doc.getFieldValue("actualMapStringToArrayOfInt");
assertSame(MapFieldValue.class, f.getClass());
MapFieldValue<?, ?> m = (MapFieldValue<?, ?>) f;
Array<?> a = (Array<?>) m.get(new StringFieldValue("bamse"));
assertEquals(3, a.size());
assertEquals(new IntegerFieldValue(1), a.get(0));
assertEquals(new IntegerFieldValue(2), a.get(1));
assertEquals(new IntegerFieldValue(3), a.get(2));
}
Aggregations