Search in sources :

Example 11 with StructDataType

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

the class DocumentGenTest method testLocalApp.

@Test
public void testLocalApp() throws MojoFailureException {
    DocumentGenMojo mojo = new DocumentGenMojo();
    mojo.execute(new File("etc/localapp/"), new File("target/generated-test-sources/vespa-documentgen-plugin/"), "com.yahoo.vespa.document");
    Map<String, Search> searches = mojo.getSearches();
    assertEquals(searches.get("video").getDocument("video").getField("weight").getDataType(), DataType.FLOAT);
    assertTrue(searches.get("book").getDocument("book").getField("mystruct").getDataType() instanceof StructDataType);
    assertTrue(searches.get("book").getDocument("book").getField("mywsfloat").getDataType() instanceof WeightedSetDataType);
    assertTrue(((WeightedSetDataType) (searches.get("book").getDocument("book").getField("mywsfloat").getDataType())).getNestedType() == DataType.FLOAT);
}
Also used : StructDataType(com.yahoo.document.StructDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) Search(com.yahoo.searchdefinition.Search) File(java.io.File) Test(org.junit.Test)

Example 12 with StructDataType

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

the class FieldValueConverterTestCase method requireThatStructElementsAreConverted.

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

Example 13 with StructDataType

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

the class FieldValueConverterTestCase method requireThatStructArrayElementsAreConverted.

@Test
public void requireThatStructArrayElementsAreConverted() {
    StructDataType type = new StructDataType("foo");
    type.addField(new Field("bar", DataType.STRING));
    type.addField(new Field("baz", DataType.STRING));
    Array<Struct> before = new Array<>(DataType.getArray(type));
    Struct elem = type.createFieldValue();
    elem.setFieldValue("bar", new StringFieldValue("6"));
    elem.setFieldValue("baz", new StringFieldValue("9"));
    before.add(elem);
    elem = type.createFieldValue();
    elem.setFieldValue("bar", new StringFieldValue("9"));
    elem.setFieldValue("baz", new StringFieldValue("6"));
    before.add(elem);
    FieldValue after = new StringMarker().convert(before);
    assertTrue(after instanceof Array);
    FieldValue val = ((Array) after).getFieldValue(0);
    assertTrue(val instanceof Struct);
    assertEquals(new StringFieldValue("6'"), ((Struct) val).getFieldValue("bar"));
    assertEquals(new StringFieldValue("9'"), ((Struct) val).getFieldValue("baz"));
    val = ((Array) after).getFieldValue(1);
    assertTrue(val instanceof Struct);
    assertEquals(new StringFieldValue("9'"), ((Struct) val).getFieldValue("bar"));
    assertEquals(new StringFieldValue("6'"), ((Struct) val).getFieldValue("baz"));
}
Also used : Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType) Test(org.junit.Test)

Example 14 with StructDataType

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

the class VespaXmlUpdateReaderTestCase method requireThatStructFieldDeserializeExceptionIncludesFieldName.

@Test
public void requireThatStructFieldDeserializeExceptionIncludesFieldName() throws Exception {
    StructDataType structType = new StructDataType("my_struct");
    structType.addField(new Field("my_byte", DataType.BYTE));
    Field field = new Field("my_field", structType);
    assertThrows(field, "<assign field='my_field'><my_byte>-129</my_byte></assign>", "Field 'my_byte': Invalid byte \"-129\". (at line 1, column 89)");
    assertThrows(field, "<assign fieldpath='my_field'><my_byte>-129</my_byte></assign>", "Field 'my_byte': Invalid byte \"-129\". (at line 1, column 93)");
    assertThrows(field, "<add field='my_field'><my_byte>-129</my_byte></add>", "Field 'my_byte': Invalid byte \"-129\". (at line 1, column 86)");
    assertThrows(field, "<add fieldpath='my_field'><my_byte>-129</my_byte></add>", "Field 'my_byte': Invalid byte \"-129\". (at line 1, column 90)");
    assertThrows(field, "<remove field='my_field'><my_byte>-129</my_byte></remove>", "Field 'my_byte': Invalid byte \"-129\". (at line 1, column 89)");
}
Also used : Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType) Test(org.junit.Test)

Example 15 with StructDataType

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

the class MapTestCase method testAdvancedMap.

public void testAdvancedMap() {
    MapDataType stringMapType1 = new MapDataType(DataType.STRING, DataType.STRING);
    MapDataType stringMapType2 = new MapDataType(DataType.STRING, DataType.STRING);
    MapFieldValue sm1 = stringMapType1.createFieldValue();
    MapFieldValue sm2 = stringMapType2.createFieldValue();
    StringFieldValue e = new StringFieldValue("e");
    StringFieldValue g = new StringFieldValue("g");
    sm1.put(new StringFieldValue("a"), new StringFieldValue("b"));
    sm1.put(new StringFieldValue("c"), new StringFieldValue("d"));
    sm2.put(e, new StringFieldValue("f"));
    sm2.put(g, new StringFieldValue("h"));
    StructDataType structType = new StructDataType("teststr");
    structType.addField(new Field("int", DataType.INT));
    structType.addField(new Field("flt", DataType.FLOAT));
    Struct s = structType.createFieldValue();
    s.setFieldValue("int", 99);
    s.setFieldValue("flt", -89.345);
    ArrayDataType twoDimArray = DataType.getArray(DataType.getArray(DataType.FLOAT));
    Array tda = twoDimArray.createFieldValue();
    MapDataType floatToTwoDimArray = new MapDataType(DataType.FLOAT, twoDimArray);
    MapDataType stringToStruct = new MapDataType(DataType.STRING, structType);
    MapDataType stringMapToStringMap = new MapDataType(stringMapType1, stringMapType2);
    MapFieldValue f2tda = floatToTwoDimArray.createFieldValue();
    f2tda.put(new FloatFieldValue(3.4f), tda);
    MapFieldValue s2sct = stringToStruct.createFieldValue();
    s2sct.put(new StringFieldValue("s1"), s);
    MapFieldValue sm2sm = stringMapToStringMap.createFieldValue();
    sm2sm.put(sm1, sm2);
    assertEquals(f2tda.get(new FloatFieldValue(3.4f)), tda);
    assertEquals(new IntegerFieldValue(99), ((Struct) (s2sct.get(new StringFieldValue("s1")))).getFieldValue("int"));
    assertEquals(new StringFieldValue("f"), ((MapFieldValue) (sm2sm.get(sm1))).get(e));
    assertEquals(new StringFieldValue("h"), ((MapFieldValue) (sm2sm.get(sm1))).get(g));
    // Look up using different map w same contents
    // TODO it works even if sm1_2 is empty, something with class id?
    MapFieldValue sm1_2 = stringMapType1.createFieldValue();
    sm1_2.put(new StringFieldValue("a"), new StringFieldValue("b"));
    sm1_2.put(new StringFieldValue("c"), new StringFieldValue("d"));
    assertEquals(new StringFieldValue("f"), ((MapFieldValue) (sm2sm.get(sm1_2))).get(e));
    assertEquals(new StringFieldValue("h"), ((MapFieldValue) (sm2sm.get(sm1_2))).get(g));
}
Also used : Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType) MapDataType(com.yahoo.document.MapDataType) ArrayDataType(com.yahoo.document.ArrayDataType)

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