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);
}
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));
}
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);
}
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));
}
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;
}
Aggregations