Search in sources :

Example 56 with SimpleTestAdapter

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

the class ForEachTestCase method requireThatStructContentCanBeConverted.

@Test
public void requireThatStructContentCanBeConverted() {
    StructDataType type = new StructDataType("my_type");
    type.addField(new Field("my_str", DataType.STRING));
    Struct struct = new Struct(type);
    struct.setFieldValue("my_str", new StringFieldValue("  foo  "));
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(struct);
    new ForEachExpression(new TrimExpression()).execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof Struct);
    assertEquals(type, val.getDataType());
    assertEquals(new StringFieldValue("foo"), ((Struct) val).getFieldValue("my_str"));
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StructDataType(com.yahoo.document.StructDataType) Test(org.junit.Test)

Example 57 with SimpleTestAdapter

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

the class ForEachTestCase method requireThatIncompatibleStructFieldsFailToValidate.

@Test
public void requireThatIncompatibleStructFieldsFailToValidate() {
    StructDataType type = new StructDataType("my_type");
    type.addField(new Field("my_int", DataType.INT));
    VerificationContext ctx = new VerificationContext(new SimpleTestAdapter());
    ctx.setValue(type);
    try {
        new ForEachExpression(new ToArrayExpression()).verify(ctx);
        fail();
    } catch (VerificationException e) {
        assertEquals("Expected int output, got Array<int>.", e.getMessage());
    }
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StructDataType(com.yahoo.document.StructDataType) Test(org.junit.Test)

Example 58 with SimpleTestAdapter

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

the class ForEachTestCase method requireThatIncompatibleStructFieldsFailToExecute.

@Test
public void requireThatIncompatibleStructFieldsFailToExecute() {
    StructDataType type = new StructDataType("my_type");
    type.addField(new Field("my_int", DataType.INT));
    Struct struct = new Struct(type);
    struct.setFieldValue("my_int", new IntegerFieldValue(69));
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(struct);
    try {
        new ForEachExpression(new ToArrayExpression()).execute(ctx);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("Class class com.yahoo.document.datatypes.Array not applicable to an class " + "com.yahoo.document.datatypes.IntegerFieldValue instance.", e.getMessage());
    }
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StructDataType(com.yahoo.document.StructDataType) Test(org.junit.Test)

Example 59 with SimpleTestAdapter

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

the class ForEachTestCase method requireThatArrayCanBeConverted.

@Test
public void requireThatArrayCanBeConverted() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    Array<StringFieldValue> before = new Array<>(DataType.getArray(DataType.STRING));
    before.add(new StringFieldValue("6"));
    before.add(new StringFieldValue("9"));
    ctx.setValue(before);
    new ForEachExpression(new ToIntegerExpression()).execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof Array);
    Array after = (Array) val;
    assertEquals(2, after.size());
    assertEquals(new IntegerFieldValue(6), after.get(0));
    assertEquals(new IntegerFieldValue(9), after.get(1));
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) Test(org.junit.Test)

Example 60 with SimpleTestAdapter

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

the class ForEachTestCase method requireThatEmptyArrayCanBeConverted.

@Test
public void requireThatEmptyArrayCanBeConverted() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new Array<StringFieldValue>(DataType.getArray(DataType.STRING)));
    new ForEachExpression(new ToIntegerExpression()).execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof Array);
    assertEquals(DataType.INT, ((Array) val).getDataType().getNestedType());
    assertTrue(((Array) val).isEmpty());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) Test(org.junit.Test)

Aggregations

SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)67 Test (org.junit.Test)59 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)42 FieldValue (com.yahoo.document.datatypes.FieldValue)30 Field (com.yahoo.document.Field)14 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)14 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)7 Array (com.yahoo.document.datatypes.Array)4 StructDataType (com.yahoo.document.StructDataType)3 SimpleLinguistics (com.yahoo.language.simple.SimpleLinguistics)3 Pair (com.yahoo.collections.Pair)1 ArrayDataType (com.yahoo.document.ArrayDataType)1 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)1 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)1 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)1 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)1 StructuredFieldValue (com.yahoo.document.datatypes.StructuredFieldValue)1 WeightedSet (com.yahoo.document.datatypes.WeightedSet)1 AnnotatorConfig (com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1