Search in sources :

Example 21 with FieldValue

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

the class OutputAssert method assertExecute.

public static void assertExecute(OutputExpression exp) {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter(new Field(exp.getFieldName(), DataType.STRING)));
    ctx.setValue(new StringFieldValue("69"));
    ctx.execute(exp);
    FieldValue out = ctx.getInputValue(exp.getFieldName());
    assertTrue(out instanceof StringFieldValue);
    assertEquals("69", ((StringFieldValue) out).getString());
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 22 with FieldValue

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

the class SetVarTestCase method requireThatSymbolIsWritten.

@Test
public void requireThatSymbolIsWritten() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new IntegerFieldValue(69));
    new SetVarExpression("out").execute(ctx);
    FieldValue val = ctx.getVariable("out");
    assertTrue(val instanceof IntegerFieldValue);
    assertEquals(69, ((IntegerFieldValue) val).getInteger());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 23 with FieldValue

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

the class ToStringTestCase method requireThatValueIsConverted.

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

Example 24 with FieldValue

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

the class StatementTestCase method requireThatStatementIsExecuted.

@Test
public void requireThatStatementIsExecuted() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    StatementExpression statement = newStatement(new SetValueExpression(new IntegerFieldValue(69)));
    newStatement(statement).execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof IntegerFieldValue);
    assertEquals(69, ((IntegerFieldValue) val).getInteger());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 25 with FieldValue

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

the class DocumentFieldTemplate method hit.

@Override
public void hit(Context context, Writer writer) throws IOException {
    DocumentHit hit = (DocumentHit) context.get("hit");
    Document doc = hit.getDocument();
    // Assume field existence has been checked before we ever get here.
    // Also assume that relevant encoding/content type is set
    // appropriately according to the request and the field's content
    // type, as this is immutable in the template set.
    FieldValue value = doc.getFieldValue(field);
    if (field.getDataType() == DataType.RAW) {
        ByteWriter bw = (ByteWriter) writer;
        bw.append(((Raw) value).getByteBuffer().array());
    } else {
        writer.write(XML.xmlEscape(value.toString(), false));
    }
}
Also used : ByteWriter(com.yahoo.io.ByteWriter) Raw(com.yahoo.document.datatypes.Raw) FieldValue(com.yahoo.document.datatypes.FieldValue) Document(com.yahoo.document.Document)

Aggregations

FieldValue (com.yahoo.document.datatypes.FieldValue)106 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)69 Test (org.junit.Test)52 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)45 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)30 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)26 Array (com.yahoo.document.datatypes.Array)20 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)20 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)18 StructuredFieldValue (com.yahoo.document.datatypes.StructuredFieldValue)14 Struct (com.yahoo.document.datatypes.Struct)13 DataType (com.yahoo.document.DataType)12 Document (com.yahoo.document.Document)12 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)12 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)12 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)11 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)11 ByteArrayInputStream (java.io.ByteArrayInputStream)11 InputStream (java.io.InputStream)11 DocumentPut (com.yahoo.document.DocumentPut)10