Search in sources :

Example 46 with IntegerFieldValue

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

the class OptimizePredicateTestCase method requireThatPredicateOptionsAreSet.

@Test
public void requireThatPredicateOptionsAreSet() {
    final Predicate predicate = Mockito.mock(Predicate.class);
    final PredicateFieldValue input = new PredicateFieldValue(predicate);
    ExecutionContext ctx = new ExecutionContext().setValue(input).setVariable("arity", new IntegerFieldValue(10));
    new OptimizePredicateExpression((predicate1, options) -> {
        assertEquals(10, options.getArity());
        assertEquals(0x8000000000000000L, options.getLowerBound());
        assertEquals(0x7fffffffffffffffL, options.getUpperBound());
        return predicate1;
    }).execute(ctx);
    ctx.setVariable("upper_bound", new LongFieldValue(1000));
    ctx.setVariable("lower_bound", new LongFieldValue(0));
    new OptimizePredicateExpression((value, options) -> {
        assertEquals(10, options.getArity());
        assertEquals(0, options.getLowerBound());
        assertEquals(1000, options.getUpperBound());
        return value;
    }).execute(ctx);
}
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) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 47 with IntegerFieldValue

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

the class ScriptTestCase method requireThatVariablesReplaceOthersOutsideScript.

@Test
public void requireThatVariablesReplaceOthersOutsideScript() {
    SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out", DataType.INT));
    newStatement(new SetValueExpression(new IntegerFieldValue(6)), new SetVarExpression("tmp"), newScript(newStatement(new SetValueExpression(new IntegerFieldValue(9)), new SetVarExpression("tmp"))), new GetVarExpression("tmp"), new AttributeExpression("out")).execute(adapter);
    assertEquals(new IntegerFieldValue(9), adapter.getInputValue("out"));
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 48 with IntegerFieldValue

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

the class ScriptTestCase method requireThatVariablesAreAvailableInScript.

@Test
public void requireThatVariablesAreAvailableInScript() {
    SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out", DataType.INT));
    newScript(newStatement(new SetValueExpression(new IntegerFieldValue(69)), new SetVarExpression("tmp")), newStatement(new GetVarExpression("tmp"), new AttributeExpression("out"))).execute(adapter);
    assertEquals(new IntegerFieldValue(69), adapter.getInputValue("out"));
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 49 with IntegerFieldValue

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

the class ScriptTestCase method requireThatScriptEvaluatesToInputValue.

@Test
public void requireThatScriptEvaluatesToInputValue() {
    SimpleTestAdapter adapter = new SimpleTestAdapter(new Field("out", DataType.INT));
    newStatement(new SetValueExpression(new IntegerFieldValue(6)), newScript(newStatement(new SetValueExpression(new IntegerFieldValue(9)))), new AttributeExpression("out")).execute(adapter);
    assertEquals(new IntegerFieldValue(6), adapter.getInputValue("out"));
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 50 with IntegerFieldValue

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

the class SwitchTestCase method requireThatIllegalArgumentThrows.

@Test
public void requireThatIllegalArgumentThrows() {
    try {
        new SwitchExpression(Collections.<String, Expression>emptyMap()).execute(new IntegerFieldValue(69));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("Expected string input, got int.", e.getMessage());
    }
}
Also used : 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