Skip to content

Commit

Permalink
Respect multi-value attributes in range optimizer (#15139)
Browse files Browse the repository at this point in the history
Fixes: #15138
  • Loading branch information
taburet committed Jun 7, 2019
1 parent 6172f18 commit 0023aee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static Ranges intersect(Predicate[] predicates, int predicateIndex, Rang

if (predicate instanceof FalsePredicate) {
return Ranges.UNSATISFIABLE;
} else if (!isRangePredicate(predicate)) {
} else if (!isSupportedPredicate(predicate)) {
return ranges;
}

Expand All @@ -111,6 +111,16 @@ private static Ranges intersect(Predicate[] predicates, int predicateIndex, Rang
return ranges;
}

private static boolean isSupportedPredicate(Predicate predicate) {
if (!isRangePredicate(predicate)) {
return false;
}

RangePredicate rangePredicate = (RangePredicate) predicate;
// we are unable to reason about multi-value attributes currently
return !rangePredicate.getAttribute().contains("[any]");
}

private static Range intersect(RangePredicate predicate, Range range, Indexes indexes) {
if (range == null) {
TypeConverter converter = indexes.getConverter(predicate.getAttribute());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public void before() {
when(indexes.getConverter("age")).thenReturn(INTEGER_CONVERTER);
when(indexes.getConverter("name")).thenReturn(STRING_CONVERTER);
when(indexes.getConverter("noConverter")).thenReturn(null);
when(indexes.getConverter("collection[any]")).thenReturn(INTEGER_CONVERTER);
when(indexes.getConverter("collection[0]")).thenReturn(INTEGER_CONVERTER);

visitor = new RangeVisitor();
}
Expand All @@ -69,6 +71,8 @@ public void testUnoptimizablePredicates() {
check(same(), equal("age", 0), equal("name", "Alice"));
check(same(), equal("age", 0), equal("name", "Alice"), greaterEqual("unindexed", true));
check(same(), between("name", "Alice", "Bob"));
check(same(), equal("collection[any]", 0));
check(same(), equal("collection[any]", 0), equal("collection[any]", 1));
}

@Test
Expand All @@ -84,6 +88,7 @@ public void testUnsatisfiablePredicates() {
check(alwaysFalse(), greaterEqual("age", "10"), lessThan("age", 10.0));
check(alwaysFalse(), greaterThan("age", "10"), lessThan("age", 0));
check(alwaysFalse(), equal("name", "Alice"), equal("name", "Bob"), greaterEqual("age", "10"), equal("age", 9));
check(alwaysFalse(), equal("collection[0]", 0), equal("collection[0]", 1));
}

@Test
Expand All @@ -107,6 +112,8 @@ public void testOptimizablePredicates() {
check(and(ref(0), equal("age", 1)), new CustomPredicate(), equal("age", 1), equal("age", "1"));
check(and(ref(0), ref(1), equal("age", 1)), new CustomPredicate(), equal("unindexed", true), equal("age", 1),
equal("age", "1"));

check(equal("collection[0]", 1), equal("collection[0]", 1), equal("collection[0]", "1"));
}

@Test
Expand Down

0 comments on commit 0023aee

Please sign in to comment.