Search in sources :

Example 41 with IntegerFieldValue

use of com.yahoo.document.datatypes.IntegerFieldValue in project vespa by vespa-engine.

the class VespaXMLUpdateReader method readArithmetic.

FieldUpdate readArithmetic(DocumentUpdate update, String type, Field f, FieldUpdate fu) throws XMLStreamException {
    Double by = null;
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        if ("by".equals(reader.getAttributeName(i).toString())) {
            by = Double.parseDouble(reader.getAttributeValue(i));
        }
    }
    if (by == null) {
        throw newDeserializeException("Assignment update without \"by\" attribute");
    }
    FieldValue key = null;
    do {
        reader.next();
        if (reader.getEventType() == XMLStreamReader.START_ELEMENT) {
            if ("key".equals(reader.getName().toString())) {
                if (f.getDataType() instanceof WeightedSetDataType) {
                    DataType nestedType = ((WeightedSetDataType) f.getDataType()).getNestedType();
                    key = nestedType.createFieldValue();
                    key.deserialize(this);
                } else if (f.getDataType() instanceof MapDataType) {
                    key = ((MapDataType) f.getDataType()).getKeyType().createFieldValue();
                    key.deserialize(this);
                } else if (f.getDataType() instanceof ArrayDataType) {
                    key = new IntegerFieldValue(Integer.parseInt(reader.getElementText()));
                } else {
                    throw newDeserializeException("Key tag only applicable for weighted sets and maps");
                }
                skipToEnd("key");
            } else {
                throw newDeserializeException("\"" + reader.getName() + "\" not appropriate within " + type + " element.");
            }
        }
    } while (reader.getEventType() != XMLStreamReader.END_ELEMENT);
    if (key != null) {
        if ("increment".equals(type)) {
            fu.addValueUpdate(ValueUpdate.createIncrement(key, by));
        }
        if ("decrement".equals(type)) {
            fu.addValueUpdate(ValueUpdate.createDecrement(key, by));
        }
        if ("multiply".equals(type)) {
            fu.addValueUpdate(ValueUpdate.createMultiply(key, by));
        }
        if ("divide".equals(type)) {
            fu.addValueUpdate(ValueUpdate.createDivide(key, by));
        }
    } else {
        if ("increment".equals(type)) {
            fu.addValueUpdate(ValueUpdate.createIncrement(by));
        }
        if ("decrement".equals(type)) {
            fu.addValueUpdate(ValueUpdate.createDecrement(by));
        }
        if ("multiply".equals(type)) {
            fu.addValueUpdate(ValueUpdate.createMultiply(by));
        }
        if ("divide".equals(type)) {
            fu.addValueUpdate(ValueUpdate.createDivide(by));
        }
    }
    return fu;
}
Also used : IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue)

Example 42 with IntegerFieldValue

use of com.yahoo.document.datatypes.IntegerFieldValue in project vespa by vespa-engine.

the class GetSearcherTestCase method testQueryPassThroughAndGet.

/* Test that a query will contain both document hits and hits from a searcher
     * further down the chain, iff the searcher returns a DocumentHit.
     */
@Test
public void testQueryPassThroughAndGet() throws Exception {
    Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:1234:foo"));
    doc1.setFieldValue("name", new StringFieldValue("megacat"));
    doc1.setFieldValue("description", new StringFieldValue("supercat"));
    doc1.setFieldValue("fluffiness", new IntegerFieldValue(10000));
    GetDocumentReply[] replies = new GetDocumentReply[] { new GetDocumentReply(doc1) };
    DocumentSessionFactory factory = new DocumentSessionFactory(docType, null, false, replies);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    DocumentHit backendHit = new DocumentHit(new Document(docType, new DocumentId("userdoc:kittens:5678:bar")), 5);
    Chain<Searcher> searchChain = new Chain<>(searcher, new MockBackend(backendHit));
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?query=flarn&id=userdoc:kittens:1234:foo"));
    assertEquals(1, factory.messages.size());
    assertEquals(2, result.hits().size());
    assertNotNull(result.hits().get("userdoc:kittens:5678:bar"));
    assertNotNull(result.hits().get("userdoc:kittens:1234:foo"));
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Searcher(com.yahoo.search.Searcher) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FeedContext(com.yahoo.feedapi.FeedContext) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Test(org.junit.Test)

Example 43 with IntegerFieldValue

use of com.yahoo.document.datatypes.IntegerFieldValue in project vespa by vespa-engine.

the class AccessesAnnotationTestCase method requireThatFieldsAreRestricted.

@Test
public void requireThatFieldsAreRestricted() {
    DocumentType type = new DocumentType("album");
    type.addField("title", DataType.STRING);
    type.addField("artist", DataType.STRING);
    type.addField("year", DataType.INT);
    Document doc = new Document(type, new DocumentId("doc:map:test:1"));
    MyDocProc docProc = new MyDocProc();
    DocumentPut put = new DocumentPut(doc);
    Document proxy = new Call(docProc).configDoc(docProc, put).getDocument();
    proxy.setFieldValue("title", new StringFieldValue("foo"));
    try {
        proxy.setFieldValue("year", new IntegerFieldValue(69));
        fail("Should have failed");
    } catch (Exception e) {
        System.out.println(e.getMessage());
        assertTrue(e.getMessage().matches(".*not allowed.*"));
    }
    proxy.getFieldValue("title");
    try {
        proxy.getFieldValue("year");
        fail("Should have failed");
    } catch (Exception e) {
        System.out.println(e.getMessage());
        assertTrue(e.getMessage().matches(".*not allowed.*"));
    }
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentId(com.yahoo.document.DocumentId) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 44 with IntegerFieldValue

use of com.yahoo.document.datatypes.IntegerFieldValue 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)

Example 45 with IntegerFieldValue

use of com.yahoo.document.datatypes.IntegerFieldValue in project vespa by vespa-engine.

the class VespaDocumentSerializerTestCase method get_serialized_size_uses_latest_serializer.

@Test
public void get_serialized_size_uses_latest_serializer() {
    DocumentType docType = new DocumentType("my_type");
    docType.addField("my_str", DataType.STRING);
    docType.addField("my_int", DataType.INT);
    Document doc = new Document(docType, "doc:scheme:");
    doc.setFieldValue("my_str", new StringFieldValue("foo"));
    doc.setFieldValue("my_int", new IntegerFieldValue(69));
    GrowableByteBuffer buf = new GrowableByteBuffer();
    doc.serialize(buf);
    assertEquals(buf.position(), VespaDocumentSerializer42.getSerializedSize(doc));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document) Test(org.junit.Test)

Aggregations

IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)69 Test (org.junit.Test)56 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)39 FieldValue (com.yahoo.document.datatypes.FieldValue)23 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)14 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)13 Array (com.yahoo.document.datatypes.Array)12 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)10 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)10 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)10 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)10 Struct (com.yahoo.document.datatypes.Struct)10 Field (com.yahoo.document.Field)8 DocumentType (com.yahoo.document.DocumentType)7 WeightedSet (com.yahoo.document.datatypes.WeightedSet)7 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)7 Document (com.yahoo.document.Document)5 DocumentUpdate (com.yahoo.document.DocumentUpdate)5 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)4 PredicateFieldValue (com.yahoo.document.datatypes.PredicateFieldValue)4