Search in sources :

Example 16 with Array

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");
}
Also used : Array(com.yahoo.document.datatypes.Array) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) WeightedSet(com.yahoo.document.datatypes.WeightedSet)

Example 17 with Array

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");
}
Also used : Array(com.yahoo.document.datatypes.Array) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) WeightedSet(com.yahoo.document.datatypes.WeightedSet)

Example 18 with Array

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;
}
Also used : Array(com.yahoo.document.datatypes.Array) DocumentOperation(com.yahoo.document.DocumentOperation) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document) SplitterDocumentProcessor.doProcessOuterDocument(com.yahoo.docproc.util.SplitterDocumentProcessor.doProcessOuterDocument)

Example 19 with Array

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));
}
Also used : Array(com.yahoo.document.datatypes.Array) ByteArrayInputStream(java.io.ByteArrayInputStream) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) Document(com.yahoo.document.Document) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader) Test(org.junit.Test)

Example 20 with Array

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));
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Document(com.yahoo.document.Document) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader) Array(com.yahoo.document.datatypes.Array) ByteArrayInputStream(java.io.ByteArrayInputStream) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) Test(org.junit.Test)

Aggregations

Array (com.yahoo.document.datatypes.Array)34 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)27 FieldValue (com.yahoo.document.datatypes.FieldValue)20 Test (org.junit.Test)17 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)16 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)9 Struct (com.yahoo.document.datatypes.Struct)9 WeightedSet (com.yahoo.document.datatypes.WeightedSet)9 Document (com.yahoo.document.Document)8 DocumentPut (com.yahoo.document.DocumentPut)7 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)7 StructDataType (com.yahoo.document.StructDataType)6 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)6 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)6 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)6 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)5 DocumentType (com.yahoo.document.DocumentType)4 Field (com.yahoo.document.Field)4 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)4 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)4