Search in sources :

Example 16 with LongFieldValue

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

the class GuardTestCase method requireThatInputFieldsAreIncludedByDocument.

@Test
public void requireThatInputFieldsAreIncludedByDocument() throws ParseException {
    DocumentType docType = new DocumentType("my_input");
    docType.addField(new Field("my_lng", DataType.LONG));
    docType.addField(new Field("my_str", DataType.STRING));
    Document doc = new Document(docType, "doc:scheme:");
    doc.setFieldValue("my_str", new StringFieldValue("69"));
    assertNotNull(doc = Expression.execute(Expression.fromString("guard { input my_str | to_int | attribute my_lng }"), doc));
    assertEquals(new LongFieldValue(69), doc.getFieldValue("my_lng"));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) Test(org.junit.Test)

Example 17 with LongFieldValue

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

the class ToLongTestCase method requireThatValueIsConverted.

@Test
public void requireThatValueIsConverted() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("69")).execute(new ToLongExpression());
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof LongFieldValue);
    assertEquals(69L, ((LongFieldValue) val).getLong());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) Test(org.junit.Test)

Example 18 with LongFieldValue

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

the class DocumentTestCase method testCppDocSplitNoBody.

@Test
public void testCppDocSplitNoBody() throws IOException {
    docMan = setUpCppDocType();
    byte[] headerData = readFile("src/test/document/serializecppsplit_header.dat");
    DocumentDeserializer header = DocumentDeserializerFactory.create42(docMan, GrowableByteBuffer.wrap(headerData));
    Document doc = new Document(header);
    assertEquals("doc:serializetest:http://test.doc.id/", doc.getId().toString());
    assertEquals(new FloatFieldValue((float) -9.23), doc.getFieldValue("floatfield"));
    assertEquals(new StringFieldValue("This is a string."), doc.getFieldValue("stringfield"));
    assertEquals(new LongFieldValue(398420092938472983L), doc.getFieldValue("longfield"));
    assertEquals(new StringFieldValue("http://this.is.a.test/"), doc.getFieldValue("urifield"));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) Test(org.junit.Test)

Example 19 with LongFieldValue

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

the class DocumentTestCase method validateCppDocNotMap.

@SuppressWarnings("unchecked")
public void validateCppDocNotMap(Document doc) throws IOException {
    // in practice to validate v6 serialization
    assertEquals("doc:serializetest:http://test.doc.id/", doc.getId().toString());
    assertEquals(new IntegerFieldValue(5), doc.getFieldValue("intfield"));
    assertEquals(new FloatFieldValue((float) -9.23), doc.getFieldValue("floatfield"));
    assertEquals(new StringFieldValue("This is a string."), doc.getFieldValue("stringfield"));
    assertEquals(new LongFieldValue(398420092938472983L), doc.getFieldValue("longfield"));
    assertEquals(new DoubleFieldValue(98374532.398820d), doc.getFieldValue("doublefield"));
    assertEquals(new StringFieldValue("http://this.is.a.test/"), doc.getFieldValue("urifield"));
    // NOTE: The value really is unsigned 254, which becomes signed -2:
    assertEquals(new ByteFieldValue(-2), doc.getFieldValue("bytefield"));
    ByteBuffer raw = ByteBuffer.wrap("RAW DATA".getBytes());
    assertEquals(new Raw(raw), doc.getFieldValue("rawfield"));
    Document docindoc = (Document) doc.getFieldValue("docfield");
    assertEquals(docMan.getDocumentType("docindoc"), docindoc.getDataType());
    assertEquals(new DocumentId("doc:docindoc:http://embedded"), docindoc.getId());
    Array<FloatFieldValue> array = (Array<FloatFieldValue>) doc.getFieldValue("arrayoffloatfield");
    assertEquals(new FloatFieldValue(1.0f), array.get(0));
    assertEquals(new FloatFieldValue(2.0f), array.get(1));
    WeightedSet<StringFieldValue> wset = (WeightedSet<StringFieldValue>) doc.getFieldValue("wsfield");
    assertEquals(new Integer(50), wset.get(new StringFieldValue("Weighted 0")));
    assertEquals(new Integer(199), wset.get(new StringFieldValue("Weighted 1")));
}
Also used : DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Raw(com.yahoo.document.datatypes.Raw) ByteBuffer(java.nio.ByteBuffer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) Array(com.yahoo.document.datatypes.Array) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) WeightedSet(com.yahoo.document.datatypes.WeightedSet)

Example 20 with LongFieldValue

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

the class ArithmeticTestCase method requireThatResultIsCalculated.

@Test
public void requireThatResultIsCalculated() {
    for (int i = 0; i < 50; ++i) {
        LongFieldValue lhs = new LongFieldValue(i);
        LongFieldValue rhs = new LongFieldValue(100 - i);
        assertResult(lhs, Operator.ADD, rhs, new LongFieldValue(lhs.getLong() + rhs.getLong()));
        assertResult(lhs, Operator.SUB, rhs, new LongFieldValue(lhs.getLong() - rhs.getLong()));
        assertResult(lhs, Operator.DIV, rhs, new LongFieldValue(lhs.getLong() / rhs.getLong()));
        assertResult(lhs, Operator.MOD, rhs, new LongFieldValue(lhs.getLong() % rhs.getLong()));
        assertResult(lhs, Operator.MUL, rhs, new LongFieldValue(lhs.getLong() * rhs.getLong()));
    }
}
Also used : LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) Test(org.junit.Test)

Aggregations

LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)25 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)17 Test (org.junit.Test)17 FieldValue (com.yahoo.document.datatypes.FieldValue)9 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)8 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)7 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)6 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)6 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)6 Raw (com.yahoo.document.datatypes.Raw)4 WeightedSet (com.yahoo.document.datatypes.WeightedSet)4 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)4 Array (com.yahoo.document.datatypes.Array)3 ByteBuffer (java.nio.ByteBuffer)3 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)2 PredicateFieldValue (com.yahoo.document.datatypes.PredicateFieldValue)2 FileOutputStream (java.io.FileOutputStream)2 DataType (com.yahoo.document.DataType)1 AbstractTypesTest (com.yahoo.document.annotation.AbstractTypesTest)1 Struct (com.yahoo.document.datatypes.Struct)1