Search in sources :

Example 66 with FilterExpression

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);
}
Also used : Book(example.Book) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 67 with FilterExpression

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);
}
Also used : Author(example.Author) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 68 with FilterExpression

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);
}
Also used : Book(example.Book) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 69 with FilterExpression

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;
}
Also used : Query(com.yahoo.elide.datastores.jpql.porting.Query) PredicateExtractionVisitor(com.yahoo.elide.core.filter.expression.PredicateExtractionVisitor) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) FilterTranslator(com.yahoo.elide.datastores.jpql.filter.FilterTranslator)

Example 70 with FilterExpression

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());
}
Also used : Item(com.yahoo.elide.datastores.search.models.Item) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Aggregations

FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)214 Test (org.junit.jupiter.api.Test)161 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)91 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)72 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)49 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)46 Path (com.yahoo.elide.core.Path)44 Query (com.yahoo.elide.datastores.aggregation.query.Query)42 Argument (com.yahoo.elide.core.request.Argument)39 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)39 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)34 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)34 HashMap (java.util.HashMap)29 Book (example.Book)28 NotFilterExpression (com.yahoo.elide.core.filter.expression.NotFilterExpression)24 EntityProjection (com.yahoo.elide.core.request.EntityProjection)22 Date (java.util.Date)21 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)20 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)19 HashSet (java.util.HashSet)18