Search in sources :

Example 21 with StructDataType

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

the class DocumentModelBuilder method resolveTemporariesRecurse.

@SuppressWarnings("deprecation")
private static DataType resolveTemporariesRecurse(DataType type, DataTypeCollection repo, Collection<NewDocumentType> docs) {
    if (type instanceof TemporaryStructuredDataType) {
        NewDocumentType docType = getDocumentType(docs, type.getId());
        if (docType != null) {
            type = docType;
            return type;
        }
        DataType real = repo.getDataType(type.getId());
        if (real == null) {
            throw new NullPointerException("Can not find type '" + type.toString() + "', impossible.");
        }
        type = real;
    } else if (type instanceof StructDataType) {
        StructDataType dt = (StructDataType) type;
        for (com.yahoo.document.Field field : dt.getFields()) {
            if (field.getDataType() != type) {
                // XXX deprecated:
                field.setDataType(resolveTemporariesRecurse(field.getDataType(), repo, docs));
            }
        }
    } else if (type instanceof MapDataType) {
        MapDataType t = (MapDataType) type;
        t.setKeyType(resolveTemporariesRecurse(t.getKeyType(), repo, docs));
        t.setValueType(resolveTemporariesRecurse(t.getValueType(), repo, docs));
    } else if (type instanceof CollectionDataType) {
        CollectionDataType t = (CollectionDataType) type;
        t.setNestedType(resolveTemporariesRecurse(t.getNestedType(), repo, docs));
    } else if (type instanceof ReferenceDataType) {
        ReferenceDataType t = (ReferenceDataType) type;
        if (t.getTargetType() instanceof TemporaryStructuredDataType) {
            DataType targetType = resolveTemporariesRecurse(t.getTargetType(), repo, docs);
            t.setTargetType((StructuredDataType) targetType);
        }
    }
    return type;
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) SearchField(com.yahoo.vespa.documentmodel.SearchField) Field(com.yahoo.document.Field) TemporaryStructuredDataType(com.yahoo.document.TemporaryStructuredDataType) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType) StructDataType(com.yahoo.document.StructDataType) CollectionDataType(com.yahoo.document.CollectionDataType) StructuredDataType(com.yahoo.document.StructuredDataType) TemporaryStructuredDataType(com.yahoo.document.TemporaryStructuredDataType) DataType(com.yahoo.document.DataType) StructDataType(com.yahoo.document.StructDataType) CollectionDataType(com.yahoo.document.CollectionDataType) MapDataType(com.yahoo.document.MapDataType) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) MapDataType(com.yahoo.document.MapDataType)

Example 22 with StructDataType

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

the class DocumentModelBuilder method extractNestedTypes.

private static void extractNestedTypes(NewDocumentType dt, DataType type) {
    if (type instanceof StructDataType) {
        StructDataType tmp = (StructDataType) type;
        extractDataTypesFromFields(dt, tmp.getFieldsThisTypeOnly());
    } else if (type instanceof DocumentType) {
        throw new IllegalArgumentException("Can not handle nested document definitions. In document type '" + dt.getName().toString() + "', we can not define document type '" + type.toString());
    } else if (type instanceof CollectionDataType) {
        CollectionDataType tmp = (CollectionDataType) type;
        extractNestedTypes(dt, tmp.getNestedType());
        addType(dt, tmp.getNestedType());
    } else if (type instanceof MapDataType) {
        MapDataType tmp = (MapDataType) type;
        extractNestedTypes(dt, tmp.getKeyType());
        extractNestedTypes(dt, tmp.getValueType());
        addType(dt, tmp.getKeyType());
        addType(dt, tmp.getValueType());
    } else if (type instanceof TemporaryAnnotationReferenceDataType) {
        throw new IllegalArgumentException(type.toString());
    }
}
Also used : StructDataType(com.yahoo.document.StructDataType) CollectionDataType(com.yahoo.document.CollectionDataType) DocumentType(com.yahoo.document.DocumentType) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) VespaDocumentType(com.yahoo.documentmodel.VespaDocumentType) MapDataType(com.yahoo.document.MapDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType)

Example 23 with StructDataType

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

the class IndexSchemaTestCase method requireThatStructWithArrayFieldIsFlattened.

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

Example 24 with StructDataType

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

the class DocumentGenTest method testComplex.

@Test
public void testComplex() throws MojoFailureException {
    DocumentGenMojo mojo = new DocumentGenMojo();
    mojo.execute(new File("etc/complex/"), 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 25 with StructDataType

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

the class JsonRendererTestCase method testFieldValueInHit.

@Test
public final void testFieldValueInHit() throws IOException, InterruptedException, ExecutionException, JSONException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"fields\": {\n" + "                    \"fromDocumentApi\":{\"integerField\":123, \"stringField\":\"abc\"}" + "                },\n" + "                \"id\": \"fieldValueTest\",\n" + "                \"relevance\": 1.0\n" + "            }\n" + "        ],\n" + "        \"fields\": {\n" + "            \"totalCount\": 1\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}\n";
    Result r = newEmptyResult();
    Hit h = new Hit("fieldValueTest");
    StructDataType structType = new StructDataType("jsonRenderer");
    structType.addField(new Field("stringField", DataType.STRING));
    structType.addField(new Field("integerField", DataType.INT));
    Struct struct = structType.createFieldValue();
    struct.setFieldValue("stringField", "abc");
    struct.setFieldValue("integerField", 123);
    h.setField("fromDocumentApi", struct);
    r.hits().add(h);
    r.setTotalHitCount(1L);
    String summary = render(r);
    assertEqualJson(expected, summary);
}
Also used : Field(com.yahoo.document.Field) FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) StructDataType(com.yahoo.document.StructDataType) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result) Struct(com.yahoo.document.datatypes.Struct) 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