use of com.yahoo.document.DataType in project vespa by vespa-engine.
the class VespaDocumentDeserializer42 method read.
public void read(AddFieldPathUpdate update) {
DataType dt = update.getFieldPath().getResultingDataType();
FieldValue fv = dt.createFieldValue();
dt.createFieldValue();
fv.deserialize(this);
if (!(fv instanceof Array)) {
throw new DeserializationException("Add only applicable to array types");
}
update.setNewValues((Array) fv);
}
use of com.yahoo.document.DataType in project vespa by vespa-engine.
the class VespaXMLFieldReader method assignPositionFieldFromStringIfNonEmpty.
private void assignPositionFieldFromStringIfNonEmpty(Struct value, String elementText, boolean base64) {
String str = base64 ? Utf8.toString(new Base64().decode(elementText)) : elementText;
str = str.trim();
if (str.isEmpty()) {
return;
}
DataType valueType = value.getDataType();
if (valueType.equals(PositionDataType.INSTANCE)) {
value.assign(PositionDataType.fromString(str));
}
}
use of com.yahoo.document.DataType in project vespa by vespa-engine.
the class CatTestCase method requireThatWsetsCanBeNull.
@Test
public void requireThatWsetsCanBeNull() {
DataType type = DataType.getWeightedSet(DataType.STRING);
WeightedSet<StringFieldValue> wset = new WeightedSet<>(type);
wset.put(new StringFieldValue("6"), 9);
FieldValue val = evaluate(type, null, type, wset);
assertEquals(type, val.getDataType());
assertEquals(1, ((WeightedSet) val).size());
assertEquals(Integer.valueOf(9), ((WeightedSet) val).get(new StringFieldValue("6")));
val = evaluate(type, wset, type, null);
assertEquals(type, val.getDataType());
assertEquals(1, ((WeightedSet) val).size());
assertEquals(Integer.valueOf(9), ((WeightedSet) val).get(new StringFieldValue("6")));
}
use of com.yahoo.document.DataType in project vespa by vespa-engine.
the class CatTestCase method requireThatArraysCanBeNull.
@Test
public void requireThatArraysCanBeNull() {
DataType type = DataType.getArray(DataType.STRING);
Array<StringFieldValue> arr = new Array<>(type);
arr.add(new StringFieldValue("9"));
FieldValue val = evaluate(type, null, type, arr);
assertEquals(type, val.getDataType());
assertEquals(1, ((Array) val).size());
assertEquals(new StringFieldValue("9"), ((Array) val).get(0));
val = evaluate(type, arr, type, null);
assertEquals(type, val.getDataType());
assertEquals(1, ((Array) val).size());
assertEquals(new StringFieldValue("9"), ((Array) val).get(0));
}
use of com.yahoo.document.DataType in project vespa by vespa-engine.
the class GetFieldExpression method doVerify.
@Override
protected void doVerify(VerificationContext context) {
DataType input = context.getValue();
if (!(input instanceof StructuredDataType)) {
throw new VerificationException(this, "Expected structured input, got " + input.getName() + ".");
}
Field field = ((StructuredDataType) input).getField(fieldName);
if (field == null) {
throw new VerificationException(this, "Field '" + fieldName + "' not found.");
}
context.setValue(field.getDataType());
}
Aggregations