use of com.apple.foundationdb.record.query.QueryToKeyMatcher.Match in project fdb-record-layer by FoundationDB.
the class QueryToKeyMatcherTest method testOneOfThem.
@Test
public void testOneOfThem() {
QueryToKeyMatcher matcher = new QueryToKeyMatcher(queryField("a").oneOfThem().equalsValue(7));
Match match = matcher.matchesSatisfyingQuery(keyField("a", FanType.FanOut));
assertEquals(MatchType.EQUALITY, match.getType());
assertEquals(Key.Evaluated.scalar(7), match.getEquality());
matcher = new QueryToKeyMatcher(queryField("p").matches(queryField("a").oneOfThem().equalsValue(7)));
match = matcher.matchesSatisfyingQuery(keyField("p").nest(keyField("a", FanType.FanOut)));
assertEquals(MatchType.EQUALITY, match.getType());
assertEquals(Key.Evaluated.scalar(7), match.getEquality());
matcher = new QueryToKeyMatcher(queryField("g").matches(queryField("p").oneOfThem().matches(queryField("a").equalsValue(7))));
match = matcher.matchesSatisfyingQuery(keyField("g").nest(keyField("p", FanType.FanOut).nest(keyField("a"))));
assertEquals(MatchType.EQUALITY, match.getType());
assertEquals(Key.Evaluated.scalar(7), match.getEquality());
matcher = new QueryToKeyMatcher(Query.and(queryField("a").equalsValue(10), queryField("g").matches(queryField("p").oneOfThem().matches(queryField("a").equalsValue(7)))));
match = matcher.matchesSatisfyingQuery(concat(keyField("a"), keyField("g").nest(keyField("p", FanType.FanOut).nest(keyField("a"))), keyField("b")));
assertEquals(MatchType.EQUALITY, match.getType());
assertEquals(Key.Evaluated.concatenate(10, 7), match.getEquality());
assertNoMatch(queryField("a").oneOfThem().matches(queryField("ax").greaterThan(8)), keyField("a", FanType.FanOut));
assertNoMatch(queryField("p").matches(queryField("a").oneOfThem().matches(queryField("ax").greaterThan(8))), keyField("p").nest(keyField("a", FanType.FanOut)));
}
use of com.apple.foundationdb.record.query.QueryToKeyMatcher.Match in project fdb-record-layer by FoundationDB.
the class QueryToKeyMatcherTest method testSingleNestedFieldEquality.
@Test
public void testSingleNestedFieldEquality() {
final QueryToKeyMatcher matcher = new QueryToKeyMatcher(queryField("a").matches(queryField("ax").equalsValue(10)));
Match match = matcher.matchesSatisfyingQuery(keyField("a").nest("ax"));
assertEquals(MatchType.EQUALITY, match.getType());
assertEquals(Key.Evaluated.scalar(10), match.getEquality());
match = matcher.matchesSatisfyingQuery(concat(keyField("a").nest("ax"), keyField("b")));
assertEquals(MatchType.EQUALITY, match.getType());
assertEquals(Key.Evaluated.scalar(10), match.getEquality());
match = matcher.matchesCoveringKey(concat(keyField("a").nest(keyField("ax")), keyField("b")));
assertEquals(MatchType.NO_MATCH, match.getType());
match = matcher.matchesSatisfyingQuery(keyField("a").nest(concat(keyField("ax"), keyField("b"))));
assertEquals(MatchType.EQUALITY, match.getType());
assertEquals(Key.Evaluated.scalar(10), match.getEquality());
match = matcher.matchesCoveringKey(keyField("a").nest(concat(keyField("ax"), keyField("b"))));
assertEquals(MatchType.NO_MATCH, match.getType());
final Match match2 = matcher.matchesSatisfyingQuery(keyField("a"));
assertNoMatch(match2);
assertNoMatch(matcher.matchesSatisfyingQuery(keyField("a", FanType.FanOut)));
assertNoMatch(matcher.matchesSatisfyingQuery(keyField("a", FanType.Concatenate)));
assertNoMatch(matcher.matchesSatisfyingQuery(keyField("a", FanType.FanOut).nest("ax")));
assertNoMatch(matcher.matchesSatisfyingQuery(keyField("a").nest("ax", FanType.FanOut)));
assertNoMatch(matcher.matchesSatisfyingQuery(keyField("a").nest("ax", FanType.Concatenate)));
assertNoMatch(matcher.matchesSatisfyingQuery(keyField("b").nest("ax")));
assertNoMatch(matcher.matchesSatisfyingQuery(keyField("a").nest("bx")));
assertNoMatch(matcher.matchesSatisfyingQuery(concat(keyField("b").nest("ax"), keyField("a").nest("ax"))));
assertNoMatch(matcher.matchesSatisfyingQuery(keyField("a").nest(concat(keyField("bx"), keyField("ax")))));
}
use of com.apple.foundationdb.record.query.QueryToKeyMatcher.Match in project fdb-record-layer by FoundationDB.
the class QueryToKeyMatcherTest method testMatchKeyWithValue.
@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());
}
use of com.apple.foundationdb.record.query.QueryToKeyMatcher.Match in project fdb-record-layer by FoundationDB.
the class QueryToKeyMatcherTest method testMatchWithValueExpression.
@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());
}
use of com.apple.foundationdb.record.query.QueryToKeyMatcher.Match in project fdb-record-layer by FoundationDB.
the class QueryToKeyMatcherTest method testMatchWithFunctionExpression.
@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());
}
Aggregations