use of org.infinispan.objectfilter.Matcher in project infinispan by infinispan.
the class AbstractMatcherTest method testProjectionOnRepeatedAttribute.
@Test
public void testProjectionOnRepeatedAttribute() throws Exception {
String queryString = "select p.address.postCode, p.phoneNumbers.number from org.infinispan.objectfilter.test.model.Person p where p.name = 'John'";
Matcher matcher = createMatcher();
Object person = createPerson1();
List<Object[]> result = new ArrayList<>();
FilterSubscription filterSubscription = matcher.registerFilter(queryString, (userContext, eventType, instance, projection, sortProjection) -> result.add(projection));
assertNotNull(filterSubscription.getProjection());
assertEquals(2, filterSubscription.getProjection().length);
assertEquals("address.postCode", filterSubscription.getProjection()[0]);
assertEquals("phoneNumbers.number", filterSubscription.getProjection()[1]);
matcher.match(null, null, person);
matcher.unregisterFilter(filterSubscription);
assertEquals(1, result.size());
assertEquals(2, result.get(0).length);
assertEquals("SW12345", result.get(0)[0]);
// todo [anistor] it is unclear what whe should expect here...
// expect the first phone number
assertEquals("0040888888", result.get(0)[1]);
}
use of org.infinispan.objectfilter.Matcher in project infinispan by infinispan.
the class AbstractMatcherTest method testTautologyAndProjections.
/**
* Test that projections are properly computed even if the query is a tautology so no predicates will ever be
* computed.
*/
@Test
public void testTautologyAndProjections() throws Exception {
String queryString = "select name from org.infinispan.objectfilter.test.model.Person where age < 30 or age >= 30";
Matcher matcher = createMatcher();
Object person = createPerson1();
List<Object[]> result = new ArrayList<>();
FilterSubscription filterSubscription = matcher.registerFilter(queryString, (userContext, eventType, instance, projection, sortProjection) -> result.add(projection));
assertNotNull(filterSubscription.getProjection());
assertEquals(1, filterSubscription.getProjection().length);
assertEquals("name", filterSubscription.getProjection()[0]);
matcher.match(null, null, person);
matcher.unregisterFilter(filterSubscription);
assertEquals(1, result.size());
assertEquals(1, result.get(0).length);
assertEquals("John", result.get(0)[0]);
}
use of org.infinispan.objectfilter.Matcher in project infinispan by infinispan.
the class AbstractMatcherTest method testObjectFilterWithDSLSamePredicate2.
@Test
public void testObjectFilterWithDSLSamePredicate2() throws Exception {
Matcher matcher = createMatcher();
Object person = createPerson1();
QueryFactory qf = createQueryFactory();
// use the same "like 'Jo%'" predicate (in positive and negative form) on the same attribute to demonstrate they do not interfere (see ISPN-4654)
Query<Person> q = qf.from(Person.class).having("name").like("Jo%").and(qf.not().having("name").like("Jo%").or().having("id").lt(1000)).build();
ObjectFilter objectFilter = matcher.getObjectFilter(q);
ObjectFilter.FilterResult result = objectFilter.filter(person);
assertNotNull(result);
assertSame(person, result.getInstance());
}
use of org.infinispan.objectfilter.Matcher in project infinispan by infinispan.
the class RowMatcherTest method match.
private boolean match(Query<?> query, Object obj) {
Matcher matcher = createMatcher();
int[] matchCount = { 0 };
matcher.registerFilter(query, (userContext, eventType, instance, projection, sortProjection) -> matchCount[0]++);
matcher.match(null, null, obj);
return matchCount[0] == 1;
}
use of org.infinispan.objectfilter.Matcher in project infinispan by infinispan.
the class RowMatcherTest method testDuplicateProjections.
@Test
public void testDuplicateProjections() {
String queryString = "select p.name, p.name, p.age from Row p where p.name = 'John'";
Matcher matcher = createMatcher();
Object person = createPerson1();
List<Object[]> result = new ArrayList<>();
FilterSubscription filterSubscription = matcher.registerFilter(queryString, (userContext, eventType, instance, projection, sortProjection) -> result.add(projection));
assertNotNull(filterSubscription.getProjection());
assertEquals(3, filterSubscription.getProjection().length);
assertEquals("name", filterSubscription.getProjection()[0]);
assertEquals("name", filterSubscription.getProjection()[1]);
assertEquals("age", filterSubscription.getProjection()[2]);
matcher.match(null, null, person);
matcher.unregisterFilter(filterSubscription);
assertEquals(1, result.size());
assertEquals(3, result.get(0).length);
assertEquals("John", result.get(0)[0]);
assertEquals("John", result.get(0)[1]);
assertEquals(40, result.get(0)[2]);
}
Aggregations