Search in sources :

Example 16 with FieldValue

use of com.yahoo.document.datatypes.FieldValue 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);
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) Test(org.junit.Test)

Example 17 with FieldValue

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

the class ToIntegerTestCase method requireThatValueIsConverted.

@Test
public void requireThatValueIsConverted() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("69")).execute(new ToIntegerExpression());
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof IntegerFieldValue);
    assertEquals(69, ((IntegerFieldValue) val).getInteger());
}
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 18 with FieldValue

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

the class ToWsetTestCase method assertConvert.

private static void assertConvert(boolean createIfNonExistent, boolean removeIfZero) {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("69")).execute(new ToWsetExpression(createIfNonExistent, removeIfZero));
    FieldValue val = ctx.getValue();
    assertEquals(WeightedSet.class, val.getClass());
    WeightedSet wset = (WeightedSet) val;
    WeightedSetDataType type = wset.getDataType();
    assertEquals(DataType.STRING, type.getNestedType());
    assertEquals(createIfNonExistent, type.createIfNonExistent());
    assertEquals(removeIfZero, type.removeIfZero());
    assertEquals(1, wset.size());
    assertEquals(Integer.valueOf(1), wset.get(new StringFieldValue("69")));
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) WeightedSet(com.yahoo.document.datatypes.WeightedSet)

Example 19 with FieldValue

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

the class TrimTestCase method requireThatStringIsTrimmed.

@Test
public void requireThatStringIsTrimmed() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("  69  ")).execute(new TrimExpression());
    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 20 with FieldValue

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

the class NowTestCase method requireThatCurrentTimeIsSet.

@Test
public void requireThatCurrentTimeIsSet() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    new NowExpression(new MyTimer()).execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof LongFieldValue);
    assertEquals(69L, ((LongFieldValue) val).getLong());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) 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