Search in sources :

Example 26 with Predicate

use of com.yahoo.document.predicate.Predicate 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 27 with Predicate

use of com.yahoo.document.predicate.Predicate in project vespa by vespa-engine.

the class AndOrSimplifierTest method assertSimplified.

private static void assertSimplified(Predicate expected, Predicate input) {
    AndOrSimplifier simplifier = new AndOrSimplifier();
    Predicate actual = simplifier.process(input, new PredicateOptions(10));
    assertEquals(expected, actual);
}
Also used : Predicate(com.yahoo.document.predicate.Predicate)

Example 28 with Predicate

use of com.yahoo.document.predicate.Predicate in project vespa by vespa-engine.

the class ComplexNodeTransformerTest method requireThatExistingPartitionsAreCleared.

@Test
public void requireThatExistingPartitionsAreCleared() {
    testConvert("foo in [10..19]", "foo in [10..19 (foo=10-19)]");
    Predicate p = Predicate.fromString("foo in [10..19]");
    ((FeatureRange) p).addPartition(new RangePartition("foo", 10000L, 20000L, false));
    ComplexNodeTransformer tranformer = new ComplexNodeTransformer();
    Predicate converted = tranformer.process(p, new PredicateOptions(10, lowerBound, upperBound));
    assertEquals("foo in [10..19 (foo=10-19)]", converted.toString());
}
Also used : RangePartition(com.yahoo.document.predicate.RangePartition) FeatureRange(com.yahoo.document.predicate.FeatureRange) Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 29 with Predicate

use of com.yahoo.document.predicate.Predicate in project vespa by vespa-engine.

the class OrSimplifierTest method require_that_or_with_feature_sets_of_different_keys_is_simplified.

@Test
public void require_that_or_with_feature_sets_of_different_keys_is_simplified() {
    Predicate p = or(feature("key1").inSet("value1", "value3"), feature("key1").inSet("value2"), feature("key2").inSet("value1"), feature("key2").inSet("value2", "value3"));
    Predicate expected = or(feature("key1").inSet("value1", "value2", "value3"), feature("key2").inSet("value1", "value2", "value3"));
    assertConvertedPredicateEquals(expected, p);
}
Also used : Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 30 with Predicate

use of com.yahoo.document.predicate.Predicate in project vespa by vespa-engine.

the class OrSimplifierTest method require_that_or_below_not_is_converted.

@Test
public void require_that_or_below_not_is_converted() {
    Predicate p = not(or(feature("key1").inSet("value1"), feature("key1").inSet("value2")));
    Predicate expected = not(feature("key1").inSet("value1", "value2"));
    assertConvertedPredicateEquals(expected, p);
}
Also used : Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Aggregations

Predicate (com.yahoo.document.predicate.Predicate)45 Test (org.junit.Test)33 Conjunction (com.yahoo.document.predicate.Conjunction)7 Disjunction (com.yahoo.document.predicate.Disjunction)6 Negation (com.yahoo.document.predicate.Negation)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 FeatureConjunction (com.yahoo.document.predicate.FeatureConjunction)3 FeatureRange (com.yahoo.document.predicate.FeatureRange)3 FeatureSet (com.yahoo.document.predicate.FeatureSet)3 IndexableFeatureConjunction (com.yahoo.search.predicate.index.conjunction.IndexableFeatureConjunction)3 Map (java.util.Map)3 DataType (com.yahoo.document.DataType)2 FieldValue (com.yahoo.document.datatypes.FieldValue)2 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)2 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)2 PredicateFieldValue (com.yahoo.document.datatypes.PredicateFieldValue)2 RangePartition (com.yahoo.document.predicate.RangePartition)2 ExpressionAssert.assertVerifyCtx (com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyCtx)2 ExpressionAssert.assertVerifyCtxThrows (com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerifyCtxThrows)2