Search in sources :

Example 61 with IntegerFieldValue

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

the class SimpleDocumentTestCase method requireThatAccessorsWorks.

@Test
public void requireThatAccessorsWorks() {
    DocumentType type = new DocumentType("test");
    type.addField("int", DataType.INT);
    Document doc = new Document(type, "doc:scheme:");
    SimpleDocument simple = new SimpleDocument(doc);
    assertNull(simple.get("int"));
    assertNull(doc.getFieldValue("int"));
    simple.set("int", 69);
    assertEquals(69, simple.get("int"));
    assertEquals(new IntegerFieldValue(69), doc.getFieldValue("int"));
    simple.remove("int");
    assertNull(simple.get("int"));
    assertNull(doc.getFieldValue("int"));
}
Also used : IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 62 with IntegerFieldValue

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

the class AnnotationTestCase method testApi.

/**
 * A test case taken from real use to verify the API ease of use
 */
@Test
public void testApi() {
    // Prepare
    AnnotationType type1 = new AnnotationType("type1", DataType.STRING);
    AnnotationType type2 = new AnnotationType("type2", DataType.INT);
    StringFieldValue output = new StringFieldValue("foo bar");
    SpanTree tree;
    // no shortcuts
    {
        SpanList root = new SpanList();
        tree = new SpanTree("SpanTree1", root);
        SpanNode node = new Span(0, 3);
        tree.annotate(node, new Annotation(type1, new StringFieldValue("text")));
        tree.annotate(node, new Annotation(type2, new IntegerFieldValue(1)));
        root.add(node);
        output.setSpanTree(tree);
    }
    // short
    {
        SpanList root = new SpanList();
        output.setSpanTree(new SpanTree("SpanTree2", root));
        SpanNode node = root.add(new Span(0, 3));
        node.annotate(type1, "text").annotate(type2, 1);
    }
    // shorter
    {
        SpanList root = output.setSpanTree(new SpanTree("SpanTree3")).spanList();
        root.span(0, 3).annotate(type1, "text").annotate(type2, 1);
    }
    // shortest
    {
        output.setSpanTree(new SpanTree("SpanTree4")).spanList().span(0, 3).annotate(type1, "text").annotate(type2, 1);
    }
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 63 with IntegerFieldValue

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

the class ExpressionConverterTestCase method requireThatAllExpressionTypesCanBeTraversed.

@SuppressWarnings("unchecked")
@Test
public void requireThatAllExpressionTypesCanBeTraversed() {
    assertConvertable(new ArithmeticExpression(new InputExpression("foo"), ArithmeticExpression.Operator.ADD, new InputExpression("bar")));
    assertConvertable(new AttributeExpression("foo"));
    assertConvertable(new Base64DecodeExpression());
    assertConvertable(new Base64EncodeExpression());
    assertConvertable(new CatExpression(new InputExpression("foo"), new IndexExpression("bar")));
    assertConvertable(new ClearStateExpression());
    assertConvertable(new EchoExpression());
    assertConvertable(new ForEachExpression(new IndexExpression("foo")));
    assertConvertable(new GetFieldExpression("foo"));
    assertConvertable(new GetVarExpression("foo"));
    assertConvertable(new GuardExpression(new IndexExpression("foo")));
    assertConvertable(new HexDecodeExpression());
    assertConvertable(new HexEncodeExpression());
    assertConvertable(new HostNameExpression());
    assertConvertable(new IfThenExpression(new InputExpression("foo"), IfThenExpression.Comparator.EQ, new InputExpression("bar"), new IndexExpression("baz"), new IndexExpression("cox")));
    assertConvertable(new IndexExpression("foo"));
    assertConvertable(new InputExpression("foo"));
    assertConvertable(new JoinExpression("foo"));
    assertConvertable(new LowerCaseExpression());
    assertConvertable(new NormalizeExpression(new SimpleLinguistics()));
    assertConvertable(new NowExpression());
    assertConvertable(new OptimizePredicateExpression());
    assertConvertable(new ParenthesisExpression(new InputExpression("foo")));
    assertConvertable(new RandomExpression(69));
    assertConvertable(new ScriptExpression(new StatementExpression(new InputExpression("foo"))));
    assertConvertable(new SelectInputExpression(new Pair<String, Expression>("foo", new IndexExpression("bar")), new Pair<String, Expression>("bar", new IndexExpression("foo"))));
    assertConvertable(new SetLanguageExpression());
    assertConvertable(new SetValueExpression(new IntegerFieldValue(69)));
    assertConvertable(new SetVarExpression("foo"));
    assertConvertable(new SplitExpression("foo"));
    assertConvertable(new StatementExpression(new InputExpression("foo")));
    assertConvertable(new SubstringExpression(6, 9));
    assertConvertable(new SummaryExpression("foo"));
    assertConvertable(new SwitchExpression(Collections.singletonMap("foo", (Expression) new IndexExpression("bar")), new InputExpression("baz")));
    assertConvertable(new ThisExpression());
    assertConvertable(new ToArrayExpression());
    assertConvertable(new ToByteExpression());
    assertConvertable(new ToDoubleExpression());
    assertConvertable(new ToFloatExpression());
    assertConvertable(new ToIntegerExpression());
    assertConvertable(new TokenizeExpression(new SimpleLinguistics(), new AnnotatorConfig()));
    assertConvertable(new ToLongExpression());
    assertConvertable(new ToPositionExpression());
    assertConvertable(new ToStringExpression());
    assertConvertable(new ToWsetExpression(false, false));
    assertConvertable(new TrimExpression());
    assertConvertable(new ZCurveExpression());
}
Also used : SummaryExpression(com.yahoo.vespa.indexinglanguage.expressions.SummaryExpression) SwitchExpression(com.yahoo.vespa.indexinglanguage.expressions.SwitchExpression) AnnotatorConfig(com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig) StatementExpression(com.yahoo.vespa.indexinglanguage.expressions.StatementExpression) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) OptimizePredicateExpression(com.yahoo.vespa.indexinglanguage.expressions.OptimizePredicateExpression) SplitExpression(com.yahoo.vespa.indexinglanguage.expressions.SplitExpression) ToPositionExpression(com.yahoo.vespa.indexinglanguage.expressions.ToPositionExpression) ThisExpression(com.yahoo.vespa.indexinglanguage.expressions.ThisExpression) ToByteExpression(com.yahoo.vespa.indexinglanguage.expressions.ToByteExpression) TokenizeExpression(com.yahoo.vespa.indexinglanguage.expressions.TokenizeExpression) IfThenExpression(com.yahoo.vespa.indexinglanguage.expressions.IfThenExpression) ToStringExpression(com.yahoo.vespa.indexinglanguage.expressions.ToStringExpression) SubstringExpression(com.yahoo.vespa.indexinglanguage.expressions.SubstringExpression) EchoExpression(com.yahoo.vespa.indexinglanguage.expressions.EchoExpression) SetVarExpression(com.yahoo.vespa.indexinglanguage.expressions.SetVarExpression) HexDecodeExpression(com.yahoo.vespa.indexinglanguage.expressions.HexDecodeExpression) SelectInputExpression(com.yahoo.vespa.indexinglanguage.expressions.SelectInputExpression) InputExpression(com.yahoo.vespa.indexinglanguage.expressions.InputExpression) AttributeExpression(com.yahoo.vespa.indexinglanguage.expressions.AttributeExpression) ScriptExpression(com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression) SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) ToArrayExpression(com.yahoo.vespa.indexinglanguage.expressions.ToArrayExpression) SetLanguageExpression(com.yahoo.vespa.indexinglanguage.expressions.SetLanguageExpression) LowerCaseExpression(com.yahoo.vespa.indexinglanguage.expressions.LowerCaseExpression) ToIntegerExpression(com.yahoo.vespa.indexinglanguage.expressions.ToIntegerExpression) ForEachExpression(com.yahoo.vespa.indexinglanguage.expressions.ForEachExpression) SelectInputExpression(com.yahoo.vespa.indexinglanguage.expressions.SelectInputExpression) ToWsetExpression(com.yahoo.vespa.indexinglanguage.expressions.ToWsetExpression) Base64DecodeExpression(com.yahoo.vespa.indexinglanguage.expressions.Base64DecodeExpression) IndexExpression(com.yahoo.vespa.indexinglanguage.expressions.IndexExpression) GetFieldExpression(com.yahoo.vespa.indexinglanguage.expressions.GetFieldExpression) RandomExpression(com.yahoo.vespa.indexinglanguage.expressions.RandomExpression) TrimExpression(com.yahoo.vespa.indexinglanguage.expressions.TrimExpression) JoinExpression(com.yahoo.vespa.indexinglanguage.expressions.JoinExpression) HexEncodeExpression(com.yahoo.vespa.indexinglanguage.expressions.HexEncodeExpression) Pair(com.yahoo.collections.Pair) SetValueExpression(com.yahoo.vespa.indexinglanguage.expressions.SetValueExpression) NowExpression(com.yahoo.vespa.indexinglanguage.expressions.NowExpression) ToDoubleExpression(com.yahoo.vespa.indexinglanguage.expressions.ToDoubleExpression) ToLongExpression(com.yahoo.vespa.indexinglanguage.expressions.ToLongExpression) ToFloatExpression(com.yahoo.vespa.indexinglanguage.expressions.ToFloatExpression) Base64EncodeExpression(com.yahoo.vespa.indexinglanguage.expressions.Base64EncodeExpression) CatExpression(com.yahoo.vespa.indexinglanguage.expressions.CatExpression) GuardExpression(com.yahoo.vespa.indexinglanguage.expressions.GuardExpression) ParenthesisExpression(com.yahoo.vespa.indexinglanguage.expressions.ParenthesisExpression) NormalizeExpression(com.yahoo.vespa.indexinglanguage.expressions.NormalizeExpression) ArithmeticExpression(com.yahoo.vespa.indexinglanguage.expressions.ArithmeticExpression) HostNameExpression(com.yahoo.vespa.indexinglanguage.expressions.HostNameExpression) GetVarExpression(com.yahoo.vespa.indexinglanguage.expressions.GetVarExpression) ClearStateExpression(com.yahoo.vespa.indexinglanguage.expressions.ClearStateExpression) ZCurveExpression(com.yahoo.vespa.indexinglanguage.expressions.ZCurveExpression) Test(org.junit.Test)

Example 64 with IntegerFieldValue

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

the class GetVarTestCase method requireThatGetVarCanBeUsedToImplementSum.

@Test
public void requireThatGetVarCanBeUsedToImplementSum() throws ParseException {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setOutputValue(null, "in", new StringFieldValue("0;1;2;3;4;5;6;7;8;9"));
    ScriptExpression.fromString("{ 0 | set_var tmp; " + "  input in | split ';' | for_each { to_int + get_var tmp | set_var tmp };" + "  get_var tmp | attribute out; }").execute(ctx);
    FieldValue val = ctx.getInputValue("out");
    assertTrue(val instanceof IntegerFieldValue);
    assertEquals(45, ((IntegerFieldValue) val).getInteger());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 65 with IntegerFieldValue

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

the class SimpleAdapterFactoryTestCase method requireThatFieldUpdateCanHaveManyPartialUpdatesForOneField.

@Test
public void requireThatFieldUpdateCanHaveManyPartialUpdatesForOneField() {
    DocumentType docType = new DocumentType("my_type");
    DocumentUpdate docUpdate = new DocumentUpdate(docType, "doc:foo:1");
    Field field = new Field("my_int", DataType.INT);
    docType.addField(field);
    FieldUpdate fieldUpdate = FieldUpdate.create(field);
    fieldUpdate.addValueUpdate(ValueUpdate.createIncrement(1));
    fieldUpdate.addValueUpdate(ValueUpdate.createIncrement(2));
    fieldUpdate.addValueUpdate(ValueUpdate.createIncrement(4));
    docUpdate.addFieldUpdate(fieldUpdate);
    SimpleAdapterFactory factory = new SimpleAdapterFactory();
    List<UpdateAdapter> adapters = factory.newUpdateAdapterList(docUpdate);
    assertEquals(4, adapters.size());
    UpdateAdapter adapter = adapters.get(0);
    assertNotNull(adapter);
    assertEquals(new IntegerFieldValue(1), adapter.getInputValue("my_int"));
    assertNotNull(adapter = adapters.get(1));
    assertEquals(new IntegerFieldValue(2), adapter.getInputValue("my_int"));
    assertNotNull(adapter = adapters.get(2));
    assertEquals(new IntegerFieldValue(4), adapter.getInputValue("my_int"));
    assertNotNull(adapter = adapters.get(3));
    // always add an adapter for complete updates
    assertNull(adapter.getInputValue("my_int"));
}
Also used : Field(com.yahoo.document.Field) DocumentUpdate(com.yahoo.document.DocumentUpdate) FieldUpdate(com.yahoo.document.update.FieldUpdate) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Aggregations

IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)69 Test (org.junit.Test)56 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)39 FieldValue (com.yahoo.document.datatypes.FieldValue)23 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)14 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)13 Array (com.yahoo.document.datatypes.Array)12 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)10 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)10 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)10 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)10 Struct (com.yahoo.document.datatypes.Struct)10 Field (com.yahoo.document.Field)8 DocumentType (com.yahoo.document.DocumentType)7 WeightedSet (com.yahoo.document.datatypes.WeightedSet)7 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)7 Document (com.yahoo.document.Document)5 DocumentUpdate (com.yahoo.document.DocumentUpdate)5 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)4 PredicateFieldValue (com.yahoo.document.datatypes.PredicateFieldValue)4