Search in sources :

Example 51 with DataType

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);
}
Also used : Array(com.yahoo.document.datatypes.Array) Utf8Array(com.yahoo.text.Utf8Array) DataType(com.yahoo.document.DataType) CollectionDataType(com.yahoo.document.CollectionDataType) MapDataType(com.yahoo.document.MapDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) ArrayDataType(com.yahoo.document.ArrayDataType) StructDataType(com.yahoo.document.StructDataType) CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) ReferenceFieldValue(com.yahoo.document.datatypes.ReferenceFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue)

Example 52 with DataType

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));
    }
}
Also used : Base64(org.apache.commons.codec.binary.Base64) PositionDataType(com.yahoo.document.PositionDataType) DataType(com.yahoo.document.DataType) MapDataType(com.yahoo.document.MapDataType)

Example 53 with DataType

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")));
}
Also used : DataType(com.yahoo.document.DataType) Test(org.junit.Test)

Example 54 with DataType

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));
}
Also used : DataType(com.yahoo.document.DataType) Test(org.junit.Test)

Example 55 with DataType

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());
}
Also used : Field(com.yahoo.document.Field) StructuredDataType(com.yahoo.document.StructuredDataType) DataType(com.yahoo.document.DataType) StructuredDataType(com.yahoo.document.StructuredDataType)

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