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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations