Search in sources :

Example 6 with LongFieldValue

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

the class Base64EncodeExpression method doExecute.

@Override
protected void doExecute(ExecutionContext ctx) {
    long input = ((LongFieldValue) ctx.getValue()).getLong();
    byte[] output = new byte[8];
    for (int i = 0; i < output.length; ++i) {
        output[i] = (byte) (input & 0xffL);
        input >>>= 8;
    }
    String encoded = new Base64(0).encodeToString(output);
    ctx.setValue(new StringFieldValue(encoded));
}
Also used : Base64(org.apache.commons.codec.binary.Base64) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue)

Example 7 with LongFieldValue

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

the class Base64DecodeExpression method doExecute.

@Override
protected void doExecute(ExecutionContext ctx) {
    String input = String.valueOf(ctx.getValue());
    if (input.isEmpty()) {
        ctx.setValue(new LongFieldValue(Long.MIN_VALUE));
        return;
    }
    if (input.length() > 12) {
        throw new NumberFormatException("Base64 value '" + input + "' is out of range.");
    }
    byte[] decoded = Base64.decodeBase64(input);
    if (decoded == null || decoded.length == 0) {
        throw new NumberFormatException("Illegal base64 value '" + input + "'.");
    }
    long output = 0;
    for (int i = decoded.length; --i >= 0; ) {
        output = (output << 8) + (((int) decoded[i]) & 0xff);
    }
    ctx.setValue(new LongFieldValue(output));
}
Also used : LongFieldValue(com.yahoo.document.datatypes.LongFieldValue)

Example 8 with LongFieldValue

use of com.yahoo.document.datatypes.LongFieldValue 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")));
}
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) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) WeightedSet(com.yahoo.document.datatypes.WeightedSet) Test(org.junit.Test)

Example 9 with LongFieldValue

use of com.yahoo.document.datatypes.LongFieldValue 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);
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) Test(org.junit.Test)

Example 10 with LongFieldValue

use of com.yahoo.document.datatypes.LongFieldValue 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();
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) Raw(com.yahoo.document.datatypes.Raw) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) Array(com.yahoo.document.datatypes.Array) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FileOutputStream(java.io.FileOutputStream) WeightedSet(com.yahoo.document.datatypes.WeightedSet) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) 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