QueryToKeyMatcher { @Nonnull @Deprecated public Match matches(@Nonnull KeyExpression expression) { return matchesSatisfyingQuery(expression); } QueryToKeyMatcher(@Nonnull QueryComponent rootQuery); @Nonnull Match matchesCoveringKey(@Nonnull KeyExpression expression); @Nonnull Match matchesCoveringKey(@Nonnull KeyExpression expression, @Nullable FilterSatisfiedMask filterMask); @Nonnull Match matchesSatisfyingQuery(@Nonnull KeyExpression expression); @Nonnull Match matchesSatisfyingQuery(@Nonnull KeyExpression expression, @Nullable FilterSatisfiedMask filterMask); @Nonnull @Deprecated Match matches(@Nonnull KeyExpression expression);  }
@Test public void testQueryAndPatterns() { assertEquality(MatchType.NO_MATCH, queryField("p").matches( Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2))), keyField("p").nest(concatenateFields("a", "c", "b"))); assertEquality(MatchType.NO_MATCH, queryField("p").matches( Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2))), keyField("p").nest(keyField("a"), keyField("q").nest(keyField("c"), keyField("d")), keyField("b"))); assertEquality(MatchType.EQUALITY, queryField("p").matches( Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2))), keyField("p").nest(keyField("a"), keyField("b"), keyField("q").nest(keyField("c"), keyField("d")))); assertEqualityCoveringKey(MatchType.NO_MATCH, queryField("p").matches( Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2))), keyField("p").nest(keyField("a"), keyField("b"), keyField("q").nest(keyField("c"), keyField("d")))); assertEquality(MatchType.EQUALITY, queryField("p").matches( Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2), queryField("c").equalsValue(3))), keyField("p").nest(concatenateFields("c", "b", "a", "extra"))); assertEqualityCoveringKey(MatchType.NO_MATCH, queryField("p").matches( Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2), queryField("c").equalsValue(3))), keyField("p").nest(concatenateFields("c", "b", "a", "extra"))); assertEqualityCoveringKey(MatchType.EQUALITY, queryField("p").matches( Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2), queryField("c").equalsValue(3))), keyField("p").nest(concatenateFields("c", "b"))); assertEquality(MatchType.INEQUALITY, Query.and( queryField("a").lessThanOrEquals(1), queryField("b").equalsValue(2), queryField("c").equalsValue(3)), concatenateFields("c", "b", "a")); assertEquality(MatchType.NO_MATCH, Query.and( queryField("a").lessThanOrEquals(1), queryField("b").equalsValue(2)), concatenateFields("a", "b", "c", "d")); assertEquality(MatchType.NO_MATCH, Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2), queryField("c").equalsValue(3), queryField("DoesNotExist").lessThan(4)), concatenateFields("c", "b", "a")); assertEqualityCoveringKey(MatchType.EQUALITY, Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2), queryField("c").equalsValue(3), queryField("DoesNotExist").lessThan(4)), concatenateFields("c", "b", "a")); assertEquality(MatchType.EQUALITY, Query.and( queryField("a").isNull(), queryField("b").equalsValue(2)), concatenateFields("a", "b")); assertEquality(MatchType.EQUALITY, Query.and( queryField("p").matches(queryField("c").equalsValue(1)), queryField("b").equalsValue(2)), concat( keyField("p").nest(keyField("c")), keyField("b"))); assertEqualityCoveringKey(MatchType.EQUALITY, Query.and( queryField("p").matches(queryField("c").equalsValue(1)), queryField("b").equalsValue(2), queryField("a").equalsValue(1)), concat( keyField("p").nest(keyField("c")), keyField("b"))); assertEquality(MatchType.NO_MATCH, Query.and( queryField("p").matches(queryField("d").equalsValue(1)), queryField("b").equalsValue(2)), concat( keyField("p").nest(keyField("c")), keyField("b"))); assertEquality(MatchType.NO_MATCH, Query.and( queryField("q").matches(queryField("c").equalsValue(1)), queryField("b").equalsValue(2)), concat( keyField("p").nest(keyField("c")), keyField("b"))); assertEquality(MatchType.INEQUALITY, Query.and( queryField("p").matches(queryField("c").equalsValue(1)), queryField("b").lessThanOrEquals(2)), concat( keyField("p").nest(keyField("c")), keyField("b"))); assertEquality(MatchType.NO_MATCH, Query.and( queryField("p").matches(queryField("c").lessThanOrEquals(1)), queryField("b").equalsValue(2)), concat( keyField("p").nest(keyField("c")), keyField("b"))); assertEquality(MatchType.EQUALITY, Query.and( queryField("p").matches(queryField("c1").equalsValue(1)), queryField("p").matches(queryField("c2").equalsValue(2))), concat( keyField("p").nest(keyField("c1")), keyField("p").nest(keyField("c2")))); assertEquality(MatchType.NO_MATCH, Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2) ), keyField("a")); assertEqualityCoveringKey(MatchType.EQUALITY, Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2) ), keyField("a")); assertEquality(MatchType.NO_MATCH, Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2) ), keyField("b")); assertEqualityCoveringKey(MatchType.EQUALITY, Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2) ), keyField("b")); assertEquality(MatchType.EQUALITY, Query.and( queryField("a").equalsValue(1), new RecordTypeKeyComparison("ErsatzRecordType") ), concat(recordType(), keyField("a"))); assertEquality(MatchType.NO_MATCH, Query.and( queryField("a").equalsValue(1), new RecordTypeKeyComparison("ErsatzRecordType") ), recordType()); assertEqualityCoveringKey(MatchType.EQUALITY, Query.and( queryField("a").equalsValue(1), new RecordTypeKeyComparison("ErsatzRecordType") ), recordType()); }
@Test public void testNestedAnd() { assertEquality(MatchType.NO_MATCH, Query.and( queryField("p").matches(Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2) )), queryField("c").equalsValue(3) ), keyField("p").nest(concatenateFields("a", "b"))); assertEqualityCoveringKey(MatchType.EQUALITY, Query.and( queryField("p").matches(Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2) )), queryField("c").equalsValue(3) ), keyField("p").nest(concatenateFields("a", "b"))); assertEqualityCoveringKey(MatchType.INEQUALITY, Query.and( queryField("p").matches(Query.and( queryField("a").equalsValue(1), queryField("b").greaterThan(2) )), queryField("c").equalsValue(3) ), keyField("p").nest(concatenateFields("a", "b"))); assertEquality(MatchType.EQUALITY, Query.and( queryField("p").matches(Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2) )), queryField("c").equalsValue(3) ), concat(keyField("p").nest(concatenateFields("a", "b")), keyField("c"))); assertEquality(MatchType.EQUALITY, Query.and( queryField("p").matches(Query.and( queryField("a").equalsValue(1), queryField("b").equalsValue(2) )), queryField("c").equalsValue(3) ), concat(keyField("c"), keyField("p").nest(concatenateFields("a", "b")), keyField("c"))); assertEquality(MatchType.NO_MATCH, Query.and( queryField("p").matches(Query.and( queryField("a").equalsValue(1), queryField("b").matches(Query.and( queryField("c").equalsValue(2), queryField("d").equalsValue(3) )) )), queryField("e").equalsValue(4) ), concat(keyField("e"), keyField("p").nest("a"))); assertEqualityCoveringKey(MatchType.EQUALITY, Query.and( queryField("p").matches(Query.and( queryField("a").equalsValue(1), queryField("b").matches(Query.and( queryField("c").equalsValue(2), queryField("d").equalsValue(3) )) )), queryField("e").equalsValue(4) ), concat(keyField("e"), keyField("p").nest("a"))); assertEquality(MatchType.EQUALITY, Query.and( queryField("p").matches(Query.and( queryField("a").equalsValue(1), queryField("b").matches(Query.and( queryField("c").equalsValue(2), queryField("d").equalsValue(3) )) )), queryField("e").equalsValue(4) ), concat(keyField("e"), keyField("p").nest(concat(keyField("b").nest(concatenateFields("c", "d")), keyField("a"))))); assertEquality(MatchType.INEQUALITY, Query.and( queryField("p").matches(Query.and( queryField("a").lessThan(1), queryField("b").matches(Query.and( queryField("c").equalsValue(2), queryField("d").equalsValue(3) )) )), queryField("e").equalsValue(4) ), concat(keyField("e"), keyField("p").nest(concat(keyField("b").nest(concatenateFields("c", "d")), keyField("a"))))); assertEqualityCoveringKey(MatchType.EQUALITY, Query.and( queryField("p").matches(Query.and( queryField("a").equalsValue(1), queryField("b").matches(Query.and( queryField("c").equalsValue(2), queryField("d").equalsValue(3) )) )), queryField("e").equalsValue(4) ), concat(keyField("e"), keyField("p").nest(concat(keyField("b").nest(concatenateFields("c", "d")), keyField("a"))))); }
@Test public void testTemporarilyNoMatch() { assertNoMatch(Query.and(queryField("a").equalsValue(3), queryField("b").isEmpty()), concatenateFields("a", "b")); assertNoMatch( Query.and( queryField("a").lessThan(3), queryField("a").greaterThan(0) ), concatenateFields("a", "b")); assertNoMatch(Query.not(queryField("a").equalsValue(3)), keyField("a")); assertNoMatch(Query.or(queryField("a").equalsValue(3), queryField("b").equalsValue(4)), concatenateFields("a", "b")); assertNoMatch(Query.rank("a").equalsValue(5), keyField("a")); assertNoMatch( queryField("p").matches(Query.or(queryField("a").equalsValue(3), queryField("b").equalsValue(4))), keyField("p").nest(concatenateFields("a", "b"))); assertNoMatch( queryField("p").matches(Query.rank("a").equalsValue(5)), keyField("p").nest(keyField("a"))); assertNoMatch( queryField("p").matches(Query.not(queryField("a").equalsValue(3))), keyField("p").nest(keyField("a"))); assertNoMatch( queryField("p").matches(Query.and(queryField("a").greaterThan(3), Query.or(queryField("b").lessThan(4), queryField("b").greaterThan(5)))), keyField("p").nest(concatenateFields("a", "b"))); assertNoMatch( queryField("p").matches(Query.and( queryField("c1").equalsValue(1), queryField("c2").equalsValue(2))), concat( keyField("p").nest(keyField("c1")), keyField("p").nest(keyField("c2")))); assertNoMatch( Query.and( queryField("p").matches(queryField("c1").equalsValue(1)), queryField("p").matches(queryField("c2").equalsValue(2))), keyField("p").nest(concatenateFields("c1", "c2"))); }