Search in sources :

Example 41 with StructDataType

use of com.yahoo.document.StructDataType 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 42 with StructDataType

use of com.yahoo.document.StructDataType 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 43 with StructDataType

use of com.yahoo.document.StructDataType 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 44 with StructDataType

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

the class FieldValueConverterTestCase method requireThatStructElementsCanBeRemoved.

@Test
public void requireThatStructElementsCanBeRemoved() {
    StructDataType type = new StructDataType("foo");
    type.addField(new Field("bar", DataType.STRING));
    type.addField(new Field("baz", DataType.STRING));
    Struct before = type.createFieldValue();
    StringFieldValue barVal = new StringFieldValue("6");
    StringFieldValue bazVal = new StringFieldValue("9");
    before.setFieldValue("bar", barVal);
    before.setFieldValue("baz", bazVal);
    FieldValue after = new SearchReplace(barVal, null).convert(before);
    assertTrue(after instanceof Struct);
    assertNull(((Struct) after).getFieldValue("bar"));
    assertEquals(bazVal, ((Struct) after).getFieldValue("baz"));
    after = new SearchReplace(bazVal, null).convert(before);
    assertTrue(after instanceof Struct);
    assertEquals(barVal, ((Struct) after).getFieldValue("bar"));
    assertNull(((Struct) after).getFieldValue("baz"));
}
Also used : Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType) Test(org.junit.Test)

Aggregations

StructDataType (com.yahoo.document.StructDataType)44 Field (com.yahoo.document.Field)37 Test (org.junit.Test)27 Struct (com.yahoo.document.datatypes.Struct)9 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)8 DocumentType (com.yahoo.document.DocumentType)6 Array (com.yahoo.document.datatypes.Array)5 FieldValue (com.yahoo.document.datatypes.FieldValue)5 MapDataType (com.yahoo.document.MapDataType)4 NewDocumentType (com.yahoo.documentmodel.NewDocumentType)4 DataType (com.yahoo.document.DataType)3 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)3 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)3 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)3 ArrayList (java.util.ArrayList)3 ArrayDataType (com.yahoo.document.ArrayDataType)2 CollectionDataType (com.yahoo.document.CollectionDataType)2 Document (com.yahoo.document.Document)2 DocumentId (com.yahoo.document.DocumentId)2 ReferenceDataType (com.yahoo.document.ReferenceDataType)2