Search in sources :

Example 1 with SimpleDocumentAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleDocumentAdapter in project vespa by vespa-engine.

the class GetFieldTestCase method requireThatStructFieldsCanBeRead.

@Test
public void requireThatStructFieldsCanBeRead() {
    DataType barType = DataType.STRING;
    FieldValue bar = barType.createFieldValue("bar");
    StructDataType fooType = new StructDataType("my_struct");
    fooType.addField(new Field("bar", barType));
    Struct foo = new Struct(fooType);
    foo.setFieldValue("bar", bar);
    DocumentType docType = new DocumentType("my_doc");
    docType.addField("foo", fooType);
    Document doc = new Document(docType, "doc:scheme:");
    doc.setFieldValue("foo", foo);
    ExecutionContext ctx = new ExecutionContext(new SimpleDocumentAdapter(doc));
    assertEquals(bar, new StatementExpression(new InputExpression("foo"), new GetFieldExpression("bar")).execute(ctx));
}
Also used : SimpleDocumentAdapter(com.yahoo.vespa.indexinglanguage.SimpleDocumentAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Example 2 with SimpleDocumentAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleDocumentAdapter in project vespa by vespa-engine.

the class InputTestCase method requireThatStructFieldsCanBeRead.

@Test
public void requireThatStructFieldsCanBeRead() {
    DataType barType = DataType.STRING;
    FieldValue bar = barType.createFieldValue("bar");
    StructDataType fooType = new StructDataType("my_struct");
    fooType.addField(new Field("bar", barType));
    Struct foo = new Struct(fooType);
    foo.setFieldValue("bar", bar);
    DocumentType docType = new DocumentType("my_doc");
    docType.addField("foo", fooType);
    Document doc = new Document(docType, "doc:scheme:");
    doc.setFieldValue("foo", foo);
    ExecutionContext ctx = new ExecutionContext(new SimpleDocumentAdapter(doc));
    assertEquals(foo, new InputExpression("foo").execute(ctx));
    assertEquals(bar, new InputExpression("foo.bar").execute(ctx));
}
Also used : SimpleDocumentAdapter(com.yahoo.vespa.indexinglanguage.SimpleDocumentAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Aggregations

FieldValue (com.yahoo.document.datatypes.FieldValue)2 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)2 Struct (com.yahoo.document.datatypes.Struct)2 SimpleDocumentAdapter (com.yahoo.vespa.indexinglanguage.SimpleDocumentAdapter)2 Test (org.junit.Test)2