Search in sources :

Example 6 with IntegerFieldValue

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

the class DocumentUpdateTestCase method requireThatArrayOfStructElementAddIsProcessedCorrectly.

@Test
public void requireThatArrayOfStructElementAddIsProcessedCorrectly() throws ParseException {
    DocumentType docType = new DocumentType("my_input");
    docType.addField(new Field("my_str", DataType.getArray(DataType.STRING)));
    docType.addField(new Field("my_pos", DataType.getArray(PositionDataType.INSTANCE)));
    DocumentUpdate docUpdate = new DocumentUpdate(docType, "doc:scheme:");
    docUpdate.addFieldUpdate(FieldUpdate.createAdd(docType.getField("my_str"), new StringFieldValue("6;9")));
    docUpdate = Expression.execute(Expression.fromString("input my_str | for_each { to_pos } | index my_pos"), docUpdate);
    assertNotNull(docUpdate);
    assertEquals(0, docUpdate.getFieldPathUpdates().size());
    assertEquals(1, docUpdate.getFieldUpdates().size());
    FieldUpdate fieldUpd = docUpdate.getFieldUpdate(0);
    assertNotNull(fieldUpd);
    assertEquals(docType.getField("my_pos"), fieldUpd.getField());
    assertEquals(1, fieldUpd.getValueUpdates().size());
    ValueUpdate valueUpd = fieldUpd.getValueUpdate(0);
    assertNotNull(valueUpd);
    assertTrue(valueUpd instanceof AddValueUpdate);
    Object val = valueUpd.getValue();
    assertNotNull(val);
    assertTrue(val instanceof Struct);
    Struct pos = (Struct) val;
    assertEquals(PositionDataType.INSTANCE, pos.getDataType());
    assertEquals(new IntegerFieldValue(6), PositionDataType.getXValue(pos));
    assertEquals(new IntegerFieldValue(9), PositionDataType.getYValue(pos));
}
Also used : 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) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Example 7 with IntegerFieldValue

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

the class ExpressionVisitorTestCase method requireThatAllExpressionsAreVisited.

@SuppressWarnings("unchecked")
@Test
public void requireThatAllExpressionsAreVisited() {
    assertCount(3, new ArithmeticExpression(new InputExpression("foo"), ArithmeticExpression.Operator.ADD, new InputExpression("bar")));
    assertCount(1, new AttributeExpression("foo"));
    assertCount(1, new Base64DecodeExpression());
    assertCount(1, new Base64EncodeExpression());
    assertCount(3, new CatExpression(new InputExpression("foo"), new IndexExpression("bar")));
    assertCount(1, new ClearStateExpression());
    assertCount(1, new EchoExpression());
    assertCount(2, new ForEachExpression(new IndexExpression("foo")));
    assertCount(1, new GetFieldExpression("foo"));
    assertCount(1, new GetVarExpression("foo"));
    assertCount(2, new GuardExpression(new IndexExpression("foo")));
    assertCount(1, new HexDecodeExpression());
    assertCount(1, new HexEncodeExpression());
    assertCount(1, new HostNameExpression());
    assertCount(5, new IfThenExpression(new InputExpression("foo"), IfThenExpression.Comparator.EQ, new InputExpression("bar"), new IndexExpression("baz"), new IndexExpression("cox")));
    assertCount(1, new IndexExpression("foo"));
    assertCount(1, new InputExpression("foo"));
    assertCount(1, new JoinExpression("foo"));
    assertCount(1, new LowerCaseExpression());
    assertCount(1, new NormalizeExpression(new SimpleLinguistics()));
    assertCount(1, new NowExpression());
    assertCount(1, new OptimizePredicateExpression());
    assertCount(2, new ParenthesisExpression(new InputExpression("foo")));
    assertCount(1, new RandomExpression(69));
    assertCount(3, new ScriptExpression(new StatementExpression(new InputExpression("foo"))));
    assertCount(3, new SelectInputExpression(new Pair<String, Expression>("foo", new IndexExpression("bar")), new Pair<String, Expression>("bar", new IndexExpression("foo"))));
    assertCount(1, new SetLanguageExpression());
    assertCount(1, new SetValueExpression(new IntegerFieldValue(69)));
    assertCount(1, new SetVarExpression("foo"));
    assertCount(1, new SplitExpression("foo"));
    assertCount(2, new StatementExpression(new InputExpression("foo")));
    assertCount(1, new SummaryExpression("foo"));
    assertCount(1, new SubstringExpression(6, 9));
    assertCount(3, new SwitchExpression(Collections.singletonMap("foo", (Expression) new IndexExpression("bar")), new InputExpression("baz")));
    assertCount(1, new ThisExpression());
    assertCount(1, new ToArrayExpression());
    assertCount(1, new ToByteExpression());
    assertCount(1, new ToDoubleExpression());
    assertCount(1, new ToFloatExpression());
    assertCount(1, new ToIntegerExpression());
    assertCount(1, new TokenizeExpression(new SimpleLinguistics(), new AnnotatorConfig()));
    assertCount(1, new ToLongExpression());
    assertCount(1, new ToPositionExpression());
    assertCount(1, new ToStringExpression());
    assertCount(1, new ToWsetExpression(false, false));
    assertCount(1, new TrimExpression());
    assertCount(1, 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 8 with IntegerFieldValue

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

the class MathResolverTestCase method evaluate.

private static int evaluate(Expression exp) {
    FieldValue val = new ExecutionContext(new SimpleTestAdapter()).execute(exp).getValue();
    assertTrue(val instanceof IntegerFieldValue);
    return ((IntegerFieldValue) val).getInteger();
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue)

Example 9 with IntegerFieldValue

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

the class OptimizePredicateTestCase method requireThatOptimizerIsCalledWithCloneOfInput.

@Test
public void requireThatOptimizerIsCalledWithCloneOfInput() {
    final Predicate predicateA = Mockito.mock(Predicate.class);
    final Predicate predicateB = Mockito.mock(Predicate.class);
    final PredicateFieldValue input = new PredicateFieldValue(predicateA);
    ExecutionContext ctx = new ExecutionContext().setValue(input).setVariable("arity", new IntegerFieldValue(10));
    FieldValue output = new OptimizePredicateExpression((predicate, options) -> {
        assertNotSame(predicateA, predicate);
        return predicateB;
    }).execute(ctx);
    assertNotSame(output, input);
    assertTrue(output instanceof PredicateFieldValue);
    assertSame(predicateB, ((PredicateFieldValue) output).getPredicate());
}
Also used : Mockito(org.mockito.Mockito) ExpressionAssert.assertVerifyCtx(com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyCtx) Test(org.junit.Test) DataType(com.yahoo.document.DataType) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) ExpressionAssert.assertVerifyCtxThrows(com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyCtxThrows) FieldValue(com.yahoo.document.datatypes.FieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) Assert(org.junit.Assert) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) ExpressionAssert.assertVerifyThrows(com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyThrows) Predicate(com.yahoo.document.predicate.Predicate) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 10 with IntegerFieldValue

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

the class RandomTestCase method requireThatRandomValueIsSet.

@Test
public void requireThatRandomValueIsSet() {
    for (int i = 0; i < 666; ++i) {
        ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
        new RandomExpression(69).execute(ctx);
        FieldValue val = ctx.getValue();
        assertTrue(val instanceof IntegerFieldValue);
        assertTrue(((IntegerFieldValue) val).getInteger() < 69);
    }
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) 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)

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