use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class HasMemberJPQLGeneratorTest method testHasMemberBookAwards.
@Test
void testHasMemberBookAwards() throws Exception {
HasMemberJPQLGenerator generator = new HasMemberJPQLGenerator(dictionary);
FilterExpression expression = dialect.parseFilterExpression("awards=hasmember='Foo'", ClassType.of(Book.class), true);
String actual = generator.generate((FilterPredicate) expression, aliasGenerator);
actual = actual.replaceFirst(":\\w+", ":XXX");
String expected = ":XXX MEMBER OF example_Book.awards";
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class HasMemberJPQLGeneratorTest method testHasMemberAuthorBookChapterTitle.
@Test
void testHasMemberAuthorBookChapterTitle() throws Exception {
HasMemberJPQLGenerator generator = new HasMemberJPQLGenerator(dictionary);
FilterExpression expression = dialect.parseFilterExpression("books.chapters.title=hasmember='A title'", ClassType.of(Author.class), true);
String actual = generator.generate((FilterPredicate) expression, aliasGenerator);
actual = actual.replaceFirst(":\\w+", ":XXX");
String expected = "EXISTS (SELECT 1 FROM example.Author _INNER_example_Author LEFT JOIN _INNER_example_Author.books _INNER_example_Author_books " + "LEFT JOIN _INNER_example_Author_books.chapters _INNER_example_Author_books_chapters WHERE _INNER_example_Author.id = example_Author.id AND _INNER_example_Author_books_chapters.title = :XXX)";
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class HasMemberJPQLGeneratorTest method testHasNoMemberBookAwards.
@Test
void testHasNoMemberBookAwards() throws Exception {
HasMemberJPQLGenerator generator = new HasMemberJPQLGenerator(dictionary, true);
FilterExpression expression = dialect.parseFilterExpression("awards=hasnomember='Foo'", ClassType.of(Book.class), true);
String actual = generator.generate((FilterPredicate) expression, aliasGenerator);
actual = actual.replaceFirst(":\\w+", ":XXX");
String expected = ":XXX NOT MEMBER OF example_Book.awards";
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class RootCollectionPageTotalsQueryBuilder method build.
/**
* Constructs a query that returns the count of a root collection.
*
* Constructs a query like:
*
* SELECT COUNT(DISTINCT Author)
* FROM Author AS Author
*
* @return the constructed query
*/
@Override
public Query build() {
Type<?> entityClass = entityProjection.getType();
String entityName = entityClass.getCanonicalName();
String entityAlias = getTypeAlias(entityClass);
Collection<FilterPredicate> predicates;
String filterClause;
String joinClause;
FilterExpression filterExpression = entityProjection.getFilterExpression();
if (filterExpression != null) {
PredicateExtractionVisitor extractor = new PredicateExtractionVisitor();
predicates = filterExpression.accept(extractor);
// Build the WHERE clause
filterClause = WHERE + new FilterTranslator(dictionary).apply(filterExpression, USE_ALIAS);
// Build the JOIN clause
joinClause = getJoinClauseFromFilters(filterExpression, true);
} else {
predicates = new HashSet<>();
filterClause = "";
joinClause = "";
}
Query query = session.createQuery("SELECT COUNT(DISTINCT " + entityAlias + ") " + FROM + entityName + AS + entityAlias + SPACE + joinClause + SPACE + filterClause);
supplyFilterQueryParameters(query, predicates);
return query;
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class DataStoreLoadTest method testTabCharacter.
@Test
public void testTabCharacter() throws Exception {
DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
// Case sensitive query against case insensitive index must lowercase
FilterExpression filter = filterParser.parseFilterExpression("name=ini='*est\tTa*'", ClassType.of(Item.class), false);
Iterable<Object> loaded = testTransaction.loadObjects(EntityProjection.builder().type(Item.class).filterExpression(filter).build(), mockScope);
assertListContains(loaded, Lists.newArrayList(7L));
verify(wrappedTransaction, never()).loadObjects(any(), any());
}
Aggregations