Search in sources :

Example 41 with Predicate

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

the class PredicateTreeAnnotatorTest method require_that_ands_below_ors_get_different_intervals.

@Test
public void require_that_ands_below_ors_get_different_intervals() {
    Predicate p = or(and(feature("key1").inSet("value1"), feature("key1").inSet("value1"), feature("key1").inSet("value1")), and(feature("key2").inSet("value2"), feature("key2").inSet("value2"), feature("key2").inSet("value2")));
    PredicateTreeAnnotations r = PredicateTreeAnnotator.createPredicateTreeAnnotations(p);
    assertEquals(1, r.minFeature);
    assertEquals(6, r.intervalEnd);
    assertEquals(2, r.intervalMap.size());
    assertIntervalContains(r, "key1=value1", 0x00010001, 0x00020002, 0x00030006);
    assertIntervalContains(r, "key2=value2", 0x00010004, 0x00050005, 0x00060006);
}
Also used : Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 42 with Predicate

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

the class PredicateTreeAnnotatorTest method require_that_hashed_ranges_get_correct_intervals.

@Test
public void require_that_hashed_ranges_get_correct_intervals() {
    Predicate p = and(range("key", partition("key=10-19"), partition("key=20-29"), edgePartition("key=0", 5, 10, 20), edgePartition("key=30", 0, 0, 3)), range("foo", partition("foo=10-19"), partition("foo=20-29"), edgePartition("foo=0", 5, 40, 60), edgePartition("foo=30", 0, 0, 3)));
    PredicateTreeAnnotations r = PredicateTreeAnnotator.createPredicateTreeAnnotations(p);
    assertEquals(2, r.minFeature);
    assertEquals(2, r.intervalEnd);
    assertEquals(4, r.intervalMap.size());
    assertEquals(4, r.boundsMap.size());
    assertIntervalContains(r, "key=10-19", 0x00010001);
    assertIntervalContains(r, "key=20-29", 0x00010001);
    // [10..20]
    assertBoundsContains(r, "key=0", bound(0x00010001, 0x000a0015));
    // [..3]
    assertBoundsContains(r, "key=30", bound(0x00010001, 0x40000004));
    assertIntervalContains(r, "foo=10-19", 0x00020002);
    assertIntervalContains(r, "foo=20-29", 0x00020002);
    // [40..60]
    assertBoundsContains(r, "foo=0", bound(0x00020002, 0x0028003d));
    // [..3]
    assertBoundsContains(r, "foo=30", bound(0x00020002, 0x40000004));
}
Also used : Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 43 with Predicate

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

the class PredicateTreeAnnotatorTest method require_that_or_intervals_are_the_same.

@Test
public void require_that_or_intervals_are_the_same() {
    Predicate p = or(feature("key1").inSet("value1"), feature("key2").inSet("value2"));
    PredicateTreeAnnotations r = PredicateTreeAnnotator.createPredicateTreeAnnotations(p);
    assertEquals(1, r.minFeature);
    assertEquals(2, r.intervalEnd);
    assertEquals(2, r.intervalMap.size());
    assertIntervalContains(r, "key1=value1", 0x00010002);
    assertIntervalContains(r, "key2=value2", 0x00010002);
}
Also used : Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 44 with Predicate

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

the class PredicateTreeAnnotatorTest method require_that_extreme_ranges_works.

@Test
public void require_that_extreme_ranges_works() {
    Predicate p = and(range("max range", partition("max range=9223372036854775806-9223372036854775807")), range("max edge", edgePartition("max edge=9223372036854775807", 0, 0, 1)), range("min range", partition("min range=-9223372036854775807-9223372036854775806")), range("min edge", edgePartition("min edge=-9223372036854775808", 0, 0, 1)));
    PredicateTreeAnnotations r = PredicateTreeAnnotator.createPredicateTreeAnnotations(p);
    assertEquals(4, r.minFeature);
    assertEquals(4, r.intervalEnd);
    assertEquals(2, r.intervalMap.size());
    assertEquals(2, r.boundsMap.size());
    assertIntervalContains(r, "max range=9223372036854775806-9223372036854775807", 0x00010001);
    assertBoundsContains(r, "max edge=9223372036854775807", bound(0x00020002, 0x40000002));
    assertIntervalContains(r, "min range=-9223372036854775807-9223372036854775806", 0x00030003);
    assertBoundsContains(r, "min edge=-9223372036854775808", bound(0x00040004, 0x40000002));
}
Also used : Predicate(com.yahoo.document.predicate.Predicate) Test(org.junit.Test)

Example 45 with Predicate

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

the class BooleanSimplifier method simplifySubTree.

public Predicate simplifySubTree(Predicate predicate) {
    if (predicate == null) {
        return null;
    }
    if (predicate instanceof Conjunction) {
        List<Predicate> in = ((PredicateOperator) predicate).getOperands();
        List<Predicate> out = new ArrayList<>(in.size());
        for (Predicate operand : in) {
            operand = simplifySubTree(operand);
            if (isFalse(operand)) {
                return new BooleanPredicate(false);
            } else if (!isTrue(operand)) {
                out.add(operand);
            }
        }
        if (out.size() == 1) {
            return out.get(0);
        } else if (out.size() == 0) {
            return new BooleanPredicate(true);
        }
        ((Conjunction) predicate).setOperands(out);
    } else if (predicate instanceof Disjunction) {
        List<Predicate> in = ((PredicateOperator) predicate).getOperands();
        List<Predicate> out = new ArrayList<>(in.size());
        for (Predicate operand : in) {
            operand = simplifySubTree(operand);
            if (isTrue(operand)) {
                return new BooleanPredicate(true);
            } else if (!isFalse(operand)) {
                out.add(operand);
            }
        }
        if (out.size() == 1) {
            return out.get(0);
        } else if (out.size() == 0) {
            return new BooleanPredicate(false);
        }
        ((Disjunction) predicate).setOperands(out);
    } else if (predicate instanceof Negation) {
        Predicate operand = ((Negation) predicate).getOperand();
        operand = simplifySubTree(operand);
        if (isTrue(operand)) {
            return new BooleanPredicate(false);
        } else if (isFalse(operand)) {
            return new BooleanPredicate(true);
        }
        ((Negation) predicate).setOperand(operand);
    }
    return predicate;
}
Also used : Disjunction(com.yahoo.document.predicate.Disjunction) Negation(com.yahoo.document.predicate.Negation) Conjunction(com.yahoo.document.predicate.Conjunction) ArrayList(java.util.ArrayList) PredicateOperator(com.yahoo.document.predicate.PredicateOperator) List(java.util.List) ArrayList(java.util.ArrayList) BooleanPredicate(com.yahoo.document.predicate.BooleanPredicate) BooleanPredicate(com.yahoo.document.predicate.BooleanPredicate) Predicate(com.yahoo.document.predicate.Predicate)

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