Search in sources :

Example 66 with FieldValue

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

the class UriParserTestCase method requireThatUriFieldsCanBeParsed.

@Test
public void requireThatUriFieldsCanBeParsed() throws Exception {
    DocumentTypeManager mgr = new DocumentTypeManager();
    DocumentType docType = new DocumentType("my_doc");
    docType.addField("my_uri", DataType.URI);
    docType.addField("my_arr", DataType.getArray(DataType.URI));
    mgr.registerDocumentType(docType);
    VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test_uri.xml", mgr);
    Iterator<VespaXMLFeedReader.Operation> it = parser.readAll().iterator();
    Document doc = nextDocument(it);
    assertNotNull(doc);
    assertEquals(new StringFieldValue("scheme://host"), doc.getFieldValue("my_uri"));
    assertNull(doc.getFieldValue("my_arr"));
    assertNotNull(doc = nextDocument(it));
    assertNull(doc.getFieldValue("my_uri"));
    FieldValue val = doc.getFieldValue("my_arr");
    assertNotNull(val);
    assertTrue(val instanceof Array);
    Array arr = (Array) val;
    assertEquals(1, arr.size());
    assertEquals(new StringFieldValue("scheme://host"), arr.get(0));
    DocumentUpdate upd = nextUpdate(it);
    assertNotNull(upd);
    assertEquals(1, upd.getFieldUpdates().size());
    FieldUpdate fieldUpd = upd.getFieldUpdate(0);
    assertNotNull(fieldUpd);
    assertEquals(docType.getField("my_arr"), fieldUpd.getField());
    assertEquals(1, fieldUpd.getValueUpdates().size());
    ValueUpdate valueUpd = fieldUpd.getValueUpdate(0);
    assertNotNull(valueUpd);
    assertTrue(valueUpd instanceof AddValueUpdate);
    assertEquals(new StringFieldValue("scheme://host"), valueUpd.getValue());
    assertFalse(it.hasNext());
}
Also used : Array(com.yahoo.document.datatypes.Array) AddValueUpdate(com.yahoo.document.update.AddValueUpdate) ValueUpdate(com.yahoo.document.update.ValueUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) AddValueUpdate(com.yahoo.document.update.AddValueUpdate) FieldUpdate(com.yahoo.document.update.FieldUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) Test(org.junit.Test)

Example 67 with FieldValue

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

the class CatExpression method doExecute.

@Override
protected void doExecute(ExecutionContext ctx) {
    FieldValue input = ctx.getValue();
    DataType inputType = input != null ? input.getDataType() : null;
    VerificationContext ver = new VerificationContext(ctx);
    List<FieldValue> values = new LinkedList<>();
    List<DataType> types = new LinkedList<>();
    for (Expression exp : this) {
        FieldValue val = ctx.setValue(input).execute(exp).getValue();
        values.add(val);
        DataType type;
        if (val != null) {
            type = val.getDataType();
        } else {
            type = ver.setValue(inputType).execute(this).getValue();
        }
        types.add(type);
    }
    DataType type = resolveOutputType(types);
    ctx.setValue(type == DataType.STRING ? asString(values) : asCollection(type, values));
}
Also used : CollectionDataType(com.yahoo.document.CollectionDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue)

Example 68 with FieldValue

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

the class ForEachExpression method doExecute.

@Override
protected void doExecute(final ExecutionContext ctx) {
    FieldValue input = ctx.getValue();
    if (input instanceof Array || input instanceof WeightedSet) {
        FieldValue next = new MyConverter(ctx, exp).convert(input);
        if (next == null) {
            VerificationContext vctx = new VerificationContext(ctx);
            vctx.setValue(input.getDataType()).execute(this);
            next = vctx.getValue().createFieldValue();
        }
        ctx.setValue(next);
    } else if (input instanceof Struct) {
        ctx.setValue(new MyConverter(ctx, exp).convert(input));
    } else {
        throw new IllegalArgumentException("Expected Array, Struct or WeightedSet input, got " + input.getDataType().getName() + ".");
    }
}
Also used : Array(com.yahoo.document.datatypes.Array) FieldValue(com.yahoo.document.datatypes.FieldValue) WeightedSet(com.yahoo.document.datatypes.WeightedSet) Struct(com.yahoo.document.datatypes.Struct)

Example 69 with FieldValue

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

the class SetValueTestCase method requireThatHashCodeAndEqualsAreImplemented.

@Test
public void requireThatHashCodeAndEqualsAreImplemented() {
    FieldValue foo = new StringFieldValue("foo");
    Expression exp = new SetValueExpression(foo);
    assertFalse(exp.equals(new Object()));
    assertFalse(exp.equals(new SetValueExpression(new StringFieldValue("bar"))));
    assertEquals(exp, new SetValueExpression(foo));
    assertEquals(exp.hashCode(), new SetValueExpression(foo).hashCode());
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) Test(org.junit.Test)

Example 70 with FieldValue

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

the class SetValueTestCase method requireThatAccessorsWork.

@Test
public void requireThatAccessorsWork() {
    FieldValue foo = new StringFieldValue("foo");
    SetValueExpression exp = new SetValueExpression(foo);
    assertSame(foo, exp.getValue());
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) Test(org.junit.Test)

Aggregations

FieldValue (com.yahoo.document.datatypes.FieldValue)106 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)69 Test (org.junit.Test)52 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)45 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)30 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)26 Array (com.yahoo.document.datatypes.Array)20 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)20 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)18 StructuredFieldValue (com.yahoo.document.datatypes.StructuredFieldValue)14 Struct (com.yahoo.document.datatypes.Struct)13 DataType (com.yahoo.document.DataType)12 Document (com.yahoo.document.Document)12 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)12 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)12 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)11 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)11 ByteArrayInputStream (java.io.ByteArrayInputStream)11 InputStream (java.io.InputStream)11 DocumentPut (com.yahoo.document.DocumentPut)10