Search in sources :

Example 6 with StructDataType

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

the class IndexSchemaTestCase method requireThatStructWithArrayOfArrayFieldIsFlattened.

@Test
public void requireThatStructWithArrayOfArrayFieldIsFlattened() {
    StructDataType type = new StructDataType("my_struct");
    type.addField(new Field("my_byte", DataType.getArray(DataType.getArray(DataType.BYTE))));
    type.addField(new Field("my_double", DataType.getArray(DataType.getArray(DataType.DOUBLE))));
    type.addField(new Field("my_float", DataType.getArray(DataType.getArray(DataType.FLOAT))));
    type.addField(new Field("my_int", DataType.getArray(DataType.getArray(DataType.INT))));
    type.addField(new Field("my_long", DataType.getArray(DataType.getArray(DataType.LONG))));
    type.addField(new Field("my_raw", DataType.getArray(DataType.getArray(DataType.RAW))));
    type.addField(new Field("my_string", DataType.getArray(DataType.getArray(DataType.STRING))));
    type.addField(new Field("my_uri", DataType.getArray(DataType.getArray(DataType.URI))));
    assertFlat(new Field("foo", type), new Field("foo.my_byte", DataType.getArray(DataType.getArray(DataType.BYTE))), new Field("foo.my_double", DataType.getArray(DataType.getArray(DataType.DOUBLE))), new Field("foo.my_float", DataType.getArray(DataType.getArray(DataType.FLOAT))), new Field("foo.my_int", DataType.getArray(DataType.getArray(DataType.INT))), new Field("foo.my_long", DataType.getArray(DataType.getArray(DataType.LONG))), new Field("foo.my_raw", DataType.getArray(DataType.getArray(DataType.RAW))), new Field("foo.my_string", DataType.getArray(DataType.getArray(DataType.STRING))), new Field("foo.my_uri", DataType.getArray(DataType.getArray(DataType.URI))));
}
Also used : Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType) Test(org.junit.Test)

Example 7 with StructDataType

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

the class DocumentTypeChangeValidatorTest method createDocumentTypeWithReferenceField.

private static NewDocumentType createDocumentTypeWithReferenceField(String nameReferencedDocumentType) {
    StructDataType headerfields = new StructDataType("headerfields");
    headerfields.addField(new Field("ref", new ReferenceDataType(new DocumentType(nameReferencedDocumentType), 0)));
    return new NewDocumentType(new NewDocumentType.Name("mydoc"), headerfields, new StructDataType("bodyfields"), new FieldSets(), Collections.emptySet());
}
Also used : Field(com.yahoo.document.Field) FieldSets(com.yahoo.searchdefinition.FieldSets) ReferenceDataType(com.yahoo.document.ReferenceDataType) StructDataType(com.yahoo.document.StructDataType) DocumentType(com.yahoo.document.DocumentType) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) NewDocumentType(com.yahoo.documentmodel.NewDocumentType)

Example 8 with StructDataType

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

the class ForEachTestCase method requireThatStructFieldCompatibilityIsVerified.

@Test
public void requireThatStructFieldCompatibilityIsVerified() {
    StructDataType type = new StructDataType("my_struct");
    type.addField(new Field("foo", DataType.INT));
    assertVerify(type, new ForEachExpression(new SimpleExpression()), type);
    assertVerifyThrows(type, new ForEachExpression(SimpleExpression.newConversion(DataType.STRING, DataType.INT)), "Expected string input, got int.");
    assertVerifyThrows(type, new ForEachExpression(SimpleExpression.newConversion(DataType.INT, DataType.STRING)), "Expected int output, got string.");
}
Also used : Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType) Test(org.junit.Test)

Example 9 with StructDataType

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

the class SchemaMappingAndAccessesTest method getDoc.

private Document getDoc() {
    DocumentType type = new DocumentType("album");
    AnnotationType personType = new AnnotationType("person");
    Annotation person = new Annotation(personType);
    type.addField("title", DataType.STRING);
    type.addField("artist", DataType.STRING);
    type.addField("guitarist", DataType.STRING);
    type.addField("year", DataType.INT);
    type.addField("labels", DataType.getArray(DataType.STRING));
    Document doc = new Document(type, new DocumentId("doc:map:test:1"));
    doc.setFieldValue("title", new StringFieldValue("Black Rock"));
    StringFieldValue joe = new StringFieldValue("Joe Bonamassa");
    joe.setSpanTree(new SpanTree("mytree").annotate(person));
    doc.setFieldValue("artist", joe);
    doc.setFieldValue("year", new IntegerFieldValue(2010));
    Array<StringFieldValue> labels = new Array<>(type.getField("labels").getDataType());
    labels.add(new StringFieldValue("audun"));
    labels.add(new StringFieldValue("tylden"));
    doc.setFieldValue("labels", labels);
    StructDataType personStructType = new StructDataType("artist");
    personStructType.addField(new com.yahoo.document.Field("firstname", DataType.STRING));
    personStructType.addField(new com.yahoo.document.Field("lastname", DataType.STRING));
    type.addField("listeners", DataType.getArray(personStructType));
    Array<Struct> listeners = new Array<>(type.getField("listeners").getDataType());
    Struct listenerOne = new Struct(personStructType);
    listenerOne.setFieldValue("firstname", new StringFieldValue("per"));
    listenerOne.setFieldValue("lastname", new StringFieldValue("olsen"));
    Struct listenerTwo = new Struct(personStructType);
    listenerTwo.setFieldValue("firstname", new StringFieldValue("anders"));
    listenerTwo.setFieldValue("lastname", new StringFieldValue("and"));
    listeners.add(listenerOne);
    listeners.add(listenerTwo);
    doc.setFieldValue("listeners", listeners);
    return doc;
}
Also used : DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Document(com.yahoo.document.Document) AnnotationType(com.yahoo.document.annotation.AnnotationType) Annotation(com.yahoo.document.annotation.Annotation) Struct(com.yahoo.document.datatypes.Struct) Array(com.yahoo.document.datatypes.Array) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StructDataType(com.yahoo.document.StructDataType) SpanTree(com.yahoo.document.annotation.SpanTree)

Example 10 with StructDataType

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

the class SchemaMappingAndAccessesTest method testMappedDocStruct.

public void testMappedDocStruct() {
    StructDataType materialsStructType = new StructDataType("materialstype");
    materialsStructType.addField(new com.yahoo.document.Field("ceiling", DataType.STRING));
    materialsStructType.addField(new com.yahoo.document.Field("walls", DataType.STRING));
    DocumentType docType = new DocumentType("album");
    docType.addField("title", DataType.STRING);
    docType.addField("artist", DataType.STRING);
    StructDataType storeStructType = new StructDataType("storetype");
    storeStructType.addField(new com.yahoo.document.Field("name", DataType.STRING));
    storeStructType.addField(new com.yahoo.document.Field("city", DataType.STRING));
    storeStructType.addField(new com.yahoo.document.Field("materials", materialsStructType));
    docType.addField("store", storeStructType);
    Document doc = new Document(docType, new DocumentId("doc:map:test:1"));
    doc.setFieldValue("title", new StringFieldValue("Black Rock"));
    doc.setFieldValue("artist", new StringFieldValue("Joe Bonamassa"));
    Struct material = new Struct(materialsStructType);
    material.setFieldValue("ceiling", new StringFieldValue("wood"));
    material.setFieldValue("walls", new StringFieldValue("brick"));
    Struct store = new Struct(storeStructType);
    store.setFieldValue("name", new StringFieldValue("Platekompaniet"));
    store.setFieldValue("city", new StringFieldValue("Trondheim"));
    store.setFieldValue(storeStructType.getField("materials"), material);
    doc.setFieldValue(docType.getField("store"), store);
    Map<String, String> fieldMap = new HashMap<>();
    fieldMap.put("t", "title");
    fieldMap.put("c", "store.city");
    fieldMap.put("w", "store.materials.walls");
    ProxyDocument mapped = new ProxyDocument(new TestDocumentProcessor1(), doc, fieldMap);
    assertEquals(new StringFieldValue("Trondheim"), mapped.getFieldValue("c"));
    assertEquals(new StringFieldValue("Black Rock"), mapped.getFieldValue("t"));
    assertEquals(new StringFieldValue("brick"), mapped.getFieldValue("w"));
    assertEquals(new StringFieldValue("brick"), material.getFieldValue("walls"));
    mapped.setFieldValue("c", new StringFieldValue("Steinkjer"));
    mapped.setFieldValue("w", new StringFieldValue("plaster"));
    assertEquals(new StringFieldValue("plaster"), mapped.getFieldValue("w"));
    assertEquals(new StringFieldValue("plaster"), material.getFieldValue("walls"));
    assertEquals(new StringFieldValue("Steinkjer"), store.getFieldValue("city"));
    assertEquals(new StringFieldValue("Steinkjer"), mapped.getFieldValue("c"));
    assertEquals(new StringFieldValue("Steinkjer"), mapped.getFieldValue("c"));
    mapped.setFieldValue("c", new StringFieldValue("Levanger"));
    assertEquals(new StringFieldValue("Levanger"), store.getFieldValue("city"));
    assertEquals(new StringFieldValue("Levanger"), mapped.getFieldValue("c"));
    mapped.setFieldValue("c", mapped.getFieldValue("c") + "Kommune");
    assertEquals(new StringFieldValue("LevangerKommune"), mapped.getFieldValue("c"));
// mapped.set(mapped.getField("c"), mapped.get("c")+"Styre");
// assertEquals(new StringFieldValue("LevangerKommuneStyre"), mapped.getFieldValue("c"));
}
Also used : HashMap(java.util.HashMap) TestDocumentProcessor1(com.yahoo.docproc.DocumentProcessingAbstractTestCase.TestDocumentProcessor1) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Struct(com.yahoo.document.datatypes.Struct) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StructDataType(com.yahoo.document.StructDataType)

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