use of com.yahoo.document.datatypes.DoubleFieldValue in project vespa by vespa-engine.
the class ToDoubleTestCase method requireThatValueIsConverted.
@Test
public void requireThatValueIsConverted() {
ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
ctx.setValue(new StringFieldValue("6.9")).execute(new ToDoubleExpression());
FieldValue val = ctx.getValue();
assertTrue(val instanceof DoubleFieldValue);
assertEquals(6.9, ((DoubleFieldValue) val).getDouble(), 1e-6);
}
use of com.yahoo.document.datatypes.DoubleFieldValue in project vespa by vespa-engine.
the class DocumentTestCase method testCppDocSplit.
@Test
public void testCppDocSplit() throws IOException {
docMan = setUpCppDocType();
byte[] headerData = readFile("src/test/document/serializecppsplit_header.dat");
byte[] bodyData = readFile("src/test/document/serializecppsplit_body.dat");
DocumentDeserializer header = DocumentDeserializerFactory.create42(docMan, GrowableByteBuffer.wrap(headerData), GrowableByteBuffer.wrap(bodyData));
Document doc = new Document(header);
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((byte) -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());
WeightedSet wset = (WeightedSet) doc.getFieldValue("wsfield");
assertEquals(new Integer(50), wset.get(new StringFieldValue("Weighted 0")));
assertEquals(new Integer(199), wset.get(new StringFieldValue("Weighted 1")));
}
use of com.yahoo.document.datatypes.DoubleFieldValue in project vespa by vespa-engine.
the class DocumentTestCase method testTypeChecking.
@Test
public void testTypeChecking() {
DocumentType type = new DocumentType("test");
type.addField(new Field("double", DataType.DOUBLE));
type.addField(new Field("float", DataType.FLOAT));
type.addField(new Field("int", DataType.INT));
type.addField(new Field("long", DataType.LONG));
type.addField(new Field("string", DataType.STRING));
Document doc = new Document(type, "doc:scheme:");
FieldValue stringVal = new StringFieldValue("69");
FieldValue doubleVal = new DoubleFieldValue(6.9);
FieldValue floatVal = new FloatFieldValue(6.9f);
FieldValue intVal = new IntegerFieldValue(69);
FieldValue longVal = new LongFieldValue(69L);
doc.setFieldValue("string", stringVal);
doc.setFieldValue("string", doubleVal);
doc.setFieldValue("string", floatVal);
doc.setFieldValue("string", intVal);
doc.setFieldValue("string", longVal);
doc.setFieldValue("double", stringVal);
doc.setFieldValue("double", doubleVal);
doc.setFieldValue("double", floatVal);
doc.setFieldValue("double", intVal);
doc.setFieldValue("double", longVal);
doc.setFieldValue("float", stringVal);
doc.setFieldValue("float", doubleVal);
doc.setFieldValue("float", floatVal);
doc.setFieldValue("float", intVal);
doc.setFieldValue("float", longVal);
doc.setFieldValue("int", stringVal);
doc.setFieldValue("int", doubleVal);
doc.setFieldValue("int", floatVal);
doc.setFieldValue("int", intVal);
doc.setFieldValue("int", longVal);
doc.setFieldValue("long", stringVal);
doc.setFieldValue("long", doubleVal);
doc.setFieldValue("long", floatVal);
doc.setFieldValue("long", intVal);
doc.setFieldValue("long", longVal);
}
use of com.yahoo.document.datatypes.DoubleFieldValue in project vespa by vespa-engine.
the class DocumentTestCase method testGenerateSerializedFile.
@Test
public void testGenerateSerializedFile() throws IOException {
docMan = setUpCppDocType();
Document doc = new Document(docMan.getDocumentType("serializetest"), new DocumentId("doc:serializetest:http://test.doc.id/"));
Document docindoc = new Document(docMan.getDocumentType("docindoc"), new DocumentId("doc:serializetest:http://doc.in.doc/"));
docindoc.setFieldValue("stringindocfield", "Elvis is dead");
doc.setFieldValue("docfield", docindoc);
Array<FloatFieldValue> l = new Array<>(doc.getField("arrayoffloatfield").getDataType());
l.add(new FloatFieldValue((float) 1.0));
l.add(new FloatFieldValue((float) 2.0));
doc.setFieldValue("arrayoffloatfield", l);
WeightedSet<StringFieldValue> wset = new WeightedSet<>(doc.getDataType().getField("wsfield").getDataType());
wset.put(new StringFieldValue("Weighted 0"), 50);
wset.put(new StringFieldValue("Weighted 1"), 199);
doc.setFieldValue("wsfield", wset);
MapFieldValue<StringFieldValue, StringFieldValue> map = new MapFieldValue<>((MapDataType) doc.getDataType().getField("mapfield").getDataType());
map.put(new StringFieldValue("foo1"), new StringFieldValue("bar1"));
map.put(new StringFieldValue("foo2"), new StringFieldValue("bar2"));
doc.setFieldValue("mapfield", map);
doc.setFieldValue("bytefield", new ByteFieldValue((byte) 254));
doc.setFieldValue("rawfield", new Raw(ByteBuffer.wrap("RAW DATA".getBytes())));
doc.setFieldValue("intfield", new IntegerFieldValue(5));
doc.setFieldValue("floatfield", new FloatFieldValue(-9.23f));
doc.setFieldValue("stringfield", new StringFieldValue("This is a string."));
doc.setFieldValue("longfield", new LongFieldValue(398420092938472983L));
doc.setFieldValue("doublefield", new DoubleFieldValue(98374532.398820d));
doc.setFieldValue("urifield", new StringFieldValue("http://this.is.a.test/"));
int size = doc.getSerializedSize();
GrowableByteBuffer buf = new GrowableByteBuffer(size, 2.0f);
doc.serialize(buf);
assertEquals(size, buf.position());
buf.position(0);
FileOutputStream fos = new FileOutputStream("src/tests/data/serializejava.dat");
fos.write(buf.array(), 0, size);
fos.close();
CompressionConfig noncomp = new CompressionConfig();
CompressionConfig lz4comp = new CompressionConfig(CompressionType.LZ4);
doc.getDataType().getHeaderType().setCompressionConfig(lz4comp);
doc.getDataType().getBodyType().setCompressionConfig(lz4comp);
buf = new GrowableByteBuffer(size, 2.0f);
doc.serialize(buf);
doc.getDataType().getHeaderType().setCompressionConfig(noncomp);
doc.getDataType().getBodyType().setCompressionConfig(noncomp);
fos = new FileOutputStream("src/tests/data/serializejava-compressed.dat");
fos.write(buf.array(), 0, buf.position());
fos.close();
}
use of com.yahoo.document.datatypes.DoubleFieldValue in project vespa by vespa-engine.
the class DocumentCalculatorTestCase method testFieldDivideByZero.
public void testFieldDivideByZero() throws Exception {
try {
DocumentCalculator calculator = new DocumentCalculator("(testdoc.byteattr + testdoc.intattr) / testdoc.doubleattr");
doc.setFieldValue("doubleattr", new DoubleFieldValue(0.0));
calculator.evaluate(doc, new HashMap<String, Object>());
assertTrue(false);
} catch (IllegalArgumentException e) {
// ok
}
}
Aggregations