Search in sources :

Example 6 with Field

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

the class SDDocumentType method createSDDocumentType.

private static SDDocumentType createSDDocumentType(StructDataType structType) {
    SDDocumentType docType = new SDDocumentType(structType.getName());
    for (Field field : structType.getFields()) {
        docType.addField(new SDField(docType, field.getName(), field.getDataType()));
    }
    docType.setStruct(structType);
    return docType;
}
Also used : Field(com.yahoo.document.Field)

Example 7 with Field

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

the class SDDocumentType method getField.

/**
 * Override getField, as it may need to ask inherited types that isn't registered in document type.
 * @param name Name of field to get.
 * @return The field found.
 */
public Field getField(String name) {
    if (name.contains(".")) {
        String superFieldName = name.substring(0, name.indexOf("."));
        String subFieldName = name.substring(name.indexOf(".") + 1);
        Field f = docType.getField(superFieldName);
        if (f != null) {
            if (f instanceof SDField) {
                SDField superField = (SDField) f;
                return superField.getStructField(subFieldName);
            } else {
                throw new IllegalArgumentException("Field " + f.getName() + " is not SDField");
            }
        }
    }
    Field f = docType.getField(name);
    if (f == null) {
        for (SDDocumentType parent : inheritedTypes.values()) {
            f = parent.getField(name);
            if (f != null)
                return f;
        }
    }
    return f;
}
Also used : Field(com.yahoo.document.Field)

Example 8 with Field

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

the class TypedTransformProvider method requiresTransform.

@Override
protected final boolean requiresTransform(Expression exp) {
    if (exp instanceof OutputExpression) {
        String fieldName = ((OutputExpression) exp).getFieldName();
        if (exp instanceof AttributeExpression) {
            Attribute attribute = search.getAttribute(fieldName);
            if (attribute == null)
                throw new IllegalArgumentException("Attribute '" + fieldName + "' not found.");
            fieldType = attribute.getDataType();
        } else if (exp instanceof IndexExpression) {
            Field field = search.getConcreteField(fieldName);
            if (field == null)
                throw new IllegalArgumentException("Index field '" + fieldName + "' not found.");
            fieldType = field.getDataType();
        } else if (exp instanceof SummaryExpression) {
            Field field = search.getSummaryField(fieldName);
            if (field == null)
                throw new IllegalArgumentException("Summary field '" + fieldName + "' not found.");
            fieldType = field.getDataType();
        } else {
            throw new UnsupportedOperationException();
        }
    }
    return requiresTransform(exp, fieldType);
}
Also used : Field(com.yahoo.document.Field) Attribute(com.yahoo.searchdefinition.document.Attribute)

Example 9 with Field

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

the class AddExtraFieldsToDocument method addSummaryField.

private void addSummaryField(Search search, SDDocumentType document, SummaryField field, boolean validate) {
    Field docField = document.getField(field.getName());
    if (docField == null) {
        ImmutableSDField existingField = search.getField(field.getName());
        if (existingField == null) {
            SDField newField = new SDField(document, field.getName(), field.getDataType(), field.isHeader(), true);
            newField.setIsExtraField(true);
            document.addField(newField);
        } else if (!existingField.isImportedField()) {
            document.addField(existingField.asField());
        }
    } else if (!docField.getDataType().equals(field.getDataType())) {
        if (validate)
            throw newProcessException(search, field, "Summary field has conflicting type.");
    }
}
Also used : SummaryField(com.yahoo.vespa.documentmodel.SummaryField) SDField(com.yahoo.searchdefinition.document.SDField) Field(com.yahoo.document.Field) ImmutableSDField(com.yahoo.searchdefinition.document.ImmutableSDField) SDField(com.yahoo.searchdefinition.document.SDField) ImmutableSDField(com.yahoo.searchdefinition.document.ImmutableSDField) ImmutableSDField(com.yahoo.searchdefinition.document.ImmutableSDField)

Example 10 with Field

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

the class IndexSchemaTestCase method requireThatArrayOfStructIsFlattened.

@Test
public void requireThatArrayOfStructIsFlattened() {
    StructDataType type = new StructDataType("my_struct");
    type.addField(new Field("my_byte", DataType.BYTE));
    type.addField(new Field("my_double", DataType.DOUBLE));
    type.addField(new Field("my_float", DataType.FLOAT));
    type.addField(new Field("my_int", DataType.INT));
    type.addField(new Field("my_long", DataType.LONG));
    type.addField(new Field("my_raw", DataType.RAW));
    type.addField(new Field("my_string", DataType.STRING));
    type.addField(new Field("my_uri", DataType.URI));
    assertFlat(new Field("foo", DataType.getArray(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)

Aggregations

Field (com.yahoo.document.Field)115 Test (org.junit.Test)50 StructDataType (com.yahoo.document.StructDataType)46 DocumentType (com.yahoo.document.DocumentType)24 DataType (com.yahoo.document.DataType)17 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)14 ReferenceDataType (com.yahoo.document.ReferenceDataType)13 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)13 ArrayDataType (com.yahoo.document.ArrayDataType)12 MapDataType (com.yahoo.document.MapDataType)12 TensorDataType (com.yahoo.document.TensorDataType)11 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)11 SDField (com.yahoo.searchdefinition.document.SDField)10 PositionDataType (com.yahoo.document.PositionDataType)9 FieldValue (com.yahoo.document.datatypes.FieldValue)9 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)9 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)8 Struct (com.yahoo.document.datatypes.Struct)7 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)6 Document (com.yahoo.document.Document)5