QueryToKeyMatcher { @Nonnull public Match matchesSatisfyingQuery(@Nonnull KeyExpression expression) { return matchesSatisfyingQuery(expression, null); } 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 testSingleFieldEquality() { final QueryToKeyMatcher matcher = new QueryToKeyMatcher(queryField("a").equalsValue(7)); Match match = matcher.matchesSatisfyingQuery(keyField("a")); assertEquals(MatchType.EQUALITY, match.getType()); assertEquals(Key.Evaluated.scalar(7), match.getEquality()); match = matcher.matchesSatisfyingQuery(concatenateFields("a", "b")); assertEquals(MatchType.EQUALITY, match.getType()); assertEquals(Key.Evaluated.scalar(7), match.getEquality()); assertNoMatch(matcher.matchesSatisfyingQuery(keyField("b"))); assertNoMatch(matcher.matchesSatisfyingQuery(keyField("a", FanType.FanOut))); assertNoMatch(matcher.matchesSatisfyingQuery(keyField("a", FanType.Concatenate))); assertNoMatch(matcher.matchesSatisfyingQuery(keyField("b").nest("a"))); assertNoMatch(matcher.matchesSatisfyingQuery(keyField("a").nest("b"))); assertNoMatch(matcher.matchesSatisfyingQuery(concatenateFields("b", "a"))); }
@Test public void testMatchKeyWithValue() { final QueryToKeyMatcher matcher = new QueryToKeyMatcher( Query.and( queryField("f1").equalsValue(7), queryField("f2").equalsValue(11))); Match match = matcher.matchesSatisfyingQuery(keyWithValue(concatenateFields("f1", "f2", "f3", "f4"), 2)); assertEquals(MatchType.EQUALITY, match.getType()); assertEquals(Key.Evaluated.concatenate(7, 11), match.getEquality()); }
@Test public void testMatchWithFunctionExpression() { final QueryToKeyMatcher matcher = new QueryToKeyMatcher(queryField("f1").equalsValue("hello!")); Match match = matcher.matchesSatisfyingQuery(keyWithValue(function("nada", concatenateFields("f1", "f2", "f3")), 1)); assertEquals(MatchType.NO_MATCH, match.getType()); }
@Test public void testMatchWithValueExpression() { final QueryToKeyMatcher matcher = new QueryToKeyMatcher(queryField("f1").equalsValue("hello!")); Match match = matcher.matchesSatisfyingQuery(value(4)); assertEquals(MatchType.NO_MATCH, match.getType()); }
@Test public void testMatchWithQueryableExpression() { final QueryableKeyExpression key = (QueryableKeyExpression)function("nada", concatenateFields("f1", "f2", "f3")); final QueryToKeyMatcher matcher = new QueryToKeyMatcher(Query.keyExpression(key).equalsValue("hello!")); Match match = matcher.matchesSatisfyingQuery(key); assertEquals(MatchType.EQUALITY, match.getType()); assertEquals(Key.Evaluated.scalar("hello!"), match.getEquality()); }