Search in sources :

Example 16 with DataType

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

the class FieldValueConverter method convertMap.

@SuppressWarnings({ "unchecked", "rawtypes" })
private FieldValue convertMap(MapFieldValue<FieldValue, FieldValue> val) {
    Map<FieldValue, FieldValue> next = new LinkedHashMap<FieldValue, FieldValue>();
    DataType nextKeyType = null, nextValType = null;
    for (Map.Entry<FieldValue, FieldValue> entry : val.entrySet()) {
        FieldValue prevKey = entry.getKey();
        FieldValue nextKey = convert(prevKey);
        if (nextKey == null) {
            continue;
        }
        if (nextKeyType == null) {
            nextKeyType = nextKey.getDataType();
        } else if (!nextKeyType.isValueCompatible(nextKey)) {
            throw new IllegalArgumentException("Expected " + nextKeyType.getName() + ", got " + nextKey.getDataType().getName() + ".");
        }
        FieldValue prevVal = entry.getValue();
        FieldValue nextVal = convert(prevVal);
        if (nextVal == null) {
            continue;
        }
        if (nextValType == null) {
            nextValType = nextVal.getDataType();
        } else if (!nextValType.isValueCompatible(nextVal)) {
            throw new IllegalArgumentException("Expected " + nextValType.getName() + ", got " + nextVal.getDataType().getName() + ".");
        }
        next.put(nextKey, nextVal);
    }
    if (nextKeyType == null || nextValType == null) {
        return null;
    }
    MapFieldValue ret = DataType.getMap(nextKeyType, nextValType).createFieldValue();
    for (Map.Entry<FieldValue, FieldValue> entry : next.entrySet()) {
        ret.put(entry.getKey(), entry.getValue());
    }
    return ret;
}
Also used : DataType(com.yahoo.document.DataType)

Example 17 with DataType

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

the class FieldValueConverter method convertWset.

@SuppressWarnings({ "unchecked", "rawtypes" })
private FieldValue convertWset(WeightedSet val) {
    Map<FieldValue, Integer> next = new LinkedHashMap<FieldValue, Integer>();
    DataType nextType = null;
    for (Iterator<FieldValue> it = val.fieldValueIterator(); it.hasNext(); ) {
        FieldValue prevKey = it.next();
        Integer prevVal = val.get(prevKey);
        FieldValue nextKey = convert(prevKey);
        if (nextKey == null) {
            continue;
        }
        if (nextType == null) {
            nextType = nextKey.getDataType();
        } else if (!nextType.isValueCompatible(nextKey)) {
            throw new IllegalArgumentException("Expected " + nextType.getName() + ", got " + nextKey.getDataType().getName() + ".");
        }
        next.put(nextKey, prevVal);
    }
    if (nextType == null) {
        return null;
    }
    WeightedSet ret = DataType.getWeightedSet(nextType, val.getDataType().createIfNonExistent(), val.getDataType().removeIfZero()).createFieldValue();
    for (Map.Entry<FieldValue, Integer> entry : next.entrySet()) {
        ret.put(entry.getKey(), entry.getValue());
    }
    return ret;
}
Also used : DataType(com.yahoo.document.DataType)

Example 18 with DataType

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

the class JsonWriterTestCase method registerArrayDocumentType.

private void registerArrayDocumentType() {
    DocumentType x = new DocumentType("testarray");
    DataType d = new ArrayDataType(DataType.STRING);
    x.addField(new Field("actualarray", d));
    types.registerDocumentType(x);
}
Also used : Field(com.yahoo.document.Field) DocumentType(com.yahoo.document.DocumentType) DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) StructDataType(com.yahoo.document.StructDataType) MapDataType(com.yahoo.document.MapDataType) PositionDataType(com.yahoo.document.PositionDataType) TensorDataType(com.yahoo.document.TensorDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType) ArrayDataType(com.yahoo.document.ArrayDataType)

Example 19 with DataType

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

the class JsonWriterTestCase method registerMapDocumentType.

private void registerMapDocumentType() {
    DocumentType x = new DocumentType("testmap");
    DataType d = new MapDataType(DataType.STRING, DataType.STRING);
    x.addField(new Field("actualmap", d));
    types.registerDocumentType(x);
}
Also used : Field(com.yahoo.document.Field) DocumentType(com.yahoo.document.DocumentType) DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) StructDataType(com.yahoo.document.StructDataType) MapDataType(com.yahoo.document.MapDataType) PositionDataType(com.yahoo.document.PositionDataType) TensorDataType(com.yahoo.document.TensorDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType) MapDataType(com.yahoo.document.MapDataType)

Example 20 with DataType

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

the class JsonWriterTestCase method registerPredicateDocumentType.

private void registerPredicateDocumentType() {
    DocumentType x = new DocumentType("testpredicate");
    DataType d = DataType.PREDICATE;
    x.addField(new Field("actualpredicate", d));
    types.registerDocumentType(x);
}
Also used : Field(com.yahoo.document.Field) DocumentType(com.yahoo.document.DocumentType) DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) StructDataType(com.yahoo.document.StructDataType) MapDataType(com.yahoo.document.MapDataType) PositionDataType(com.yahoo.document.PositionDataType) TensorDataType(com.yahoo.document.TensorDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType)

Aggregations

DataType (com.yahoo.document.DataType)62 ArrayDataType (com.yahoo.document.ArrayDataType)20 MapDataType (com.yahoo.document.MapDataType)19 Field (com.yahoo.document.Field)17 StructDataType (com.yahoo.document.StructDataType)17 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)17 ReferenceDataType (com.yahoo.document.ReferenceDataType)13 PositionDataType (com.yahoo.document.PositionDataType)12 CollectionDataType (com.yahoo.document.CollectionDataType)11 FieldValue (com.yahoo.document.datatypes.FieldValue)11 TensorDataType (com.yahoo.document.TensorDataType)10 DocumentType (com.yahoo.document.DocumentType)9 StructuredDataType (com.yahoo.document.StructuredDataType)7 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)6 SDField (com.yahoo.searchdefinition.document.SDField)6 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)5 TemporaryStructuredDataType (com.yahoo.document.TemporaryStructuredDataType)4 AnnotationReferenceDataType (com.yahoo.document.annotation.AnnotationReferenceDataType)4 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)4 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)4