Search in sources :

Example 71 with FieldValue

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

the class SplitTestCase method requireThatEmptyInputProducesEmptyArray.

@Test
public void requireThatEmptyInputProducesEmptyArray() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue(""));
    new SplitExpression(";").execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val.getDataType().equals(DataType.getArray(DataType.STRING)));
    assertTrue(val instanceof Array);
    assertEquals(0, ((Array) val).size());
}
Also used : Array(com.yahoo.document.datatypes.Array) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) Test(org.junit.Test)

Example 72 with FieldValue

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

the class SubstringTestCase method requireThatStringIsSliced.

@Test
public void requireThatStringIsSliced() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("666999"));
    new SubstringExpression(2, 4).execute(ctx);
    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) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) Test(org.junit.Test)

Example 73 with FieldValue

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

the class ExecutionContextTestCase method requireThatVariablesCanBeSet.

@Test
public void requireThatVariablesCanBeSet() {
    ExecutionContext ctx = new ExecutionContext();
    FieldValue val = new StringFieldValue("foo");
    ctx.setVariable("foo", val);
    assertSame(val, ctx.getVariable("foo"));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) Test(org.junit.Test)

Example 74 with FieldValue

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

use of com.yahoo.document.datatypes.FieldValue 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)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