Search in sources :

Example 6 with FloatFieldValue

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

the class ToFloatTestCase method requireThatValueIsConverted.

@Test
public void requireThatValueIsConverted() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("6.9f")).execute(new ToFloatExpression());
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof FloatFieldValue);
    assertEquals(6.9f, ((FloatFieldValue) val).getFloat(), 1e-6);
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) Test(org.junit.Test)

Example 7 with FloatFieldValue

use of com.yahoo.document.datatypes.FloatFieldValue 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 8 with FloatFieldValue

use of com.yahoo.document.datatypes.FloatFieldValue 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 9 with FloatFieldValue

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

the class DocumentTestCase method testDocumentComparisonDoesNotCorruptStateBug6394548.

@Test
public void testDocumentComparisonDoesNotCorruptStateBug6394548() {
    DocumentTypeManager docMan = new DocumentTypeManager();
    DocumentType docType = new DocumentType("bug2354045");
    docType.addField(new Field("string", 2, DataType.STRING, true));
    docType.addField(new Field("int", 1, DataType.INT, true));
    docType.addField(new Field("float", 0, DataType.FLOAT, true));
    docMan.register(docType);
    Document doc1 = new Document(docType, new DocumentId("doc:a:b:bug6394548"));
    doc1.setFieldValue("string", new StringFieldValue("hello world"));
    doc1.setFieldValue("int", new IntegerFieldValue(1234));
    doc1.setFieldValue("float", new FloatFieldValue(5.5f));
    String doc1Before = doc1.toXml();
    Document doc2 = new Document(docType, new DocumentId("doc:a:b:bug6394548"));
    doc2.setFieldValue("string", new StringFieldValue("aardvark"));
    doc2.setFieldValue("int", new IntegerFieldValue(90909));
    doc2.setFieldValue("float", new FloatFieldValue(777.15f));
    String doc2Before = doc2.toXml();
    doc1.compareTo(doc2);
    String doc1After = doc1.toXml();
    String doc2After = doc2.toXml();
    assertEquals(doc1Before, doc1After);
    assertEquals(doc2Before, doc2After);
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) Test(org.junit.Test)

Example 10 with FloatFieldValue

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

the class DocumentTestCaseBase method getTestDocument.

public Document getTestDocument() {
    Document doc = new Document(docMan.getDocumentType("testdoc"), new DocumentId("doc:testdoc:http://www.ntnu.no/"));
    doc.setFieldValue(byteField.getName(), (byte) 30);
    doc.setFieldValue(byteField.getName(), (byte) 30);
    doc.setFieldValue(intField.getName(), 50);
    ByteBuffer buf = ByteBuffer.allocate(7).put("hei der".getBytes());
    buf.flip();
    doc.setFieldValue(rawField, new Raw(buf));
    doc.setFieldValue(floatField, new FloatFieldValue((float) 3.56));
    doc.setFieldValue("stringattr", "tjohei");
    assertNotNull(doc.getId());
    assertNotNull(doc.getDataType());
    return doc;
}
Also used : Raw(com.yahoo.document.datatypes.Raw) ByteBuffer(java.nio.ByteBuffer) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue)

Aggregations

FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)11 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)10 Test (org.junit.Test)7 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)6 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)6 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)5 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)5 Raw (com.yahoo.document.datatypes.Raw)5 WeightedSet (com.yahoo.document.datatypes.WeightedSet)4 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)4 ByteBuffer (java.nio.ByteBuffer)4 Array (com.yahoo.document.datatypes.Array)3 FileOutputStream (java.io.FileOutputStream)3 ArrayList (java.util.ArrayList)3 FieldValue (com.yahoo.document.datatypes.FieldValue)2 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)2 AbstractTypesTest (com.yahoo.document.annotation.AbstractTypesTest)1 Struct (com.yahoo.document.datatypes.Struct)1 DocumentSerializer (com.yahoo.document.serialization.DocumentSerializer)1 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)1