Search in sources :

Example 76 with Path

use of com.yahoo.elide.core.Path in project elide by yahoo.

the class ExpressionScopingVisitorTest method testExpressionCopy.

@Test
public void testExpressionCopy() throws Exception {
    Path p1Path = new Path(Arrays.asList(new PathElement(Book.class, Author.class, "authors"), new PathElement(Author.class, String.class, NAME)));
    FilterPredicate p1 = new InPredicate(p1Path, "foo", "bar");
    FilterPredicate p2 = new InPredicate(new PathElement(Book.class, String.class, NAME), "blah%");
    FilterPredicate p3 = new InPredicate(new PathElement(Book.class, String.class, GENRE), SCIFI);
    // P4 is a duplicate of P3
    FilterPredicate p4 = new InPredicate(new PathElement(Book.class, String.class, GENRE), SCIFI);
    OrFilterExpression or = new OrFilterExpression(p2, p3);
    AndFilterExpression and1 = new AndFilterExpression(or, p1);
    AndFilterExpression and2 = new AndFilterExpression(and1, p4);
    NotFilterExpression not = new NotFilterExpression(and2);
    PathElement scope = new PathElement(Author.class, String.class, NAME);
    ExpressionScopingVisitor scopingVisitor = new ExpressionScopingVisitor(scope);
    FilterExpression copy = not.accept(scopingVisitor);
    assertNotEquals(not, copy);
    List<FilterPredicate> predicates = (List) copy.accept(new PredicateExtractionVisitor(new ArrayList<>()));
    List<FilterPredicate> toCompare = Arrays.asList(p2.scopedBy(scope), p3.scopedBy(scope), p1.scopedBy(scope), p4.scopedBy(scope));
    for (int i = 0; i < predicates.size(); i++) {
        FilterPredicate predicateOriginal = toCompare.get(i);
        FilterPredicate predicateCopy = predicates.get(i);
        assertEquals(predicateOriginal, predicateCopy);
        assertTrue(predicateCopy != predicateOriginal);
    }
    assertEquals("example_Author_name", predicates.get(0).getPath().getAlias());
    assertTrue(predicates.get(0).getParameters().get(0).getPlaceholder().startsWith(":name_name_"));
    assertEquals("blah\\%", predicates.get(0).getParameters().get(0).escapeMatching());
}
Also used : Path(com.yahoo.elide.core.Path) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) PathElement(com.yahoo.elide.core.Path.PathElement) Book(example.Book) ArrayList(java.util.ArrayList) List(java.util.List) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Test(org.junit.jupiter.api.Test)

Example 77 with Path

use of com.yahoo.elide.core.Path in project elide by yahoo.

the class FilterPredicatePushdownExtractorTest method testPartialPredicateExtraction.

@Test
public void testPartialPredicateExtraction() {
    FilterExpression dataStoreExpression = new InPredicate(new Path(Book.class, dictionary, "genre"), "Literary Fiction");
    FilterExpression inMemoryExpression = new InPredicate(new Path(Book.class, dictionary, "editor.firstName"), "Literary Fiction");
    FilterExpression finalExpression = new NotFilterExpression(new OrFilterExpression(dataStoreExpression, inMemoryExpression));
    FilterExpression extracted = FilterPredicatePushdownExtractor.extractPushDownPredicate(dictionary, finalExpression);
    assertEquals(((InPredicate) dataStoreExpression).negate(), extracted);
}
Also used : Path(com.yahoo.elide.core.Path) Book(example.Book) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) Test(org.junit.jupiter.api.Test)

Example 78 with Path

use of com.yahoo.elide.core.Path in project elide by yahoo.

the class FilterPredicatePushdownExtractorTest method testPath.

@Test
public void testPath() {
    Path path = new Path(Book.class, dictionary, "genre");
    ImmutableList<PathElement> pathElements = ImmutableList.of(new PathElement(Book.class, String.class, "genre"));
    assertEquals("example_Book", path.getAlias());
    assertEquals("genre", path.getFieldPath());
    assertEquals(pathElements, path.getPathElements());
    assertEquals(Optional.of(pathElements.get(0)), path.lastElement());
    assertEquals("[Book].genre", path.toString());
    path = new Path(Book.class, dictionary, "this.editor.firstName");
    pathElements = ImmutableList.of(new PathElement(Book.class, null, "this"), new PathElement(Book.class, Editor.class, "editor"), new PathElement(Editor.class, String.class, "firstName"));
    assertEquals("example_Book_editor", path.getAlias());
    assertEquals("this.editor.firstName", path.getFieldPath());
    assertEquals(pathElements, path.getPathElements());
    assertEquals(Optional.of(pathElements.get(2)), path.lastElement());
    assertEquals("[Book].this/[Book].editor/[Editor].firstName", path.toString());
}
Also used : Path(com.yahoo.elide.core.Path) PathElement(com.yahoo.elide.core.Path.PathElement) Book(example.Book) Test(org.junit.jupiter.api.Test)

Example 79 with Path

use of com.yahoo.elide.core.Path in project elide by yahoo.

the class FilterPredicatePushdownExtractorTest method testOrPartialPredicateExtraction.

@Test
public void testOrPartialPredicateExtraction() {
    FilterExpression dataStoreExpression = new InPredicate(new Path(Book.class, dictionary, "genre"), "Literary Fiction");
    FilterExpression anotherDataStoreExpression = new InPredicate(new Path(Book.class, dictionary, "genre"), "Science Fiction");
    FilterExpression expectedExpression = new OrFilterExpression(dataStoreExpression, anotherDataStoreExpression);
    FilterExpression inMemoryExpression = new InPredicate(new Path(Book.class, dictionary, "editor.firstName"), "Jane");
    FilterExpression finalExpression = new OrFilterExpression(new AndFilterExpression(dataStoreExpression, inMemoryExpression), anotherDataStoreExpression);
    FilterExpression extracted = FilterPredicatePushdownExtractor.extractPushDownPredicate(dictionary, finalExpression);
    assertEquals(expectedExpression, extracted);
}
Also used : Path(com.yahoo.elide.core.Path) Book(example.Book) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) Test(org.junit.jupiter.api.Test)

Example 80 with Path

use of com.yahoo.elide.core.Path in project elide by yahoo.

the class FilterPredicatePushdownExtractorTest method testInvalidField.

@Test
public void testInvalidField() {
    InvalidValueException e = assertThrows(InvalidValueException.class, () -> new InPredicate(new Path(Book.class, dictionary, "badfield"), "Literary Fiction"));
    assertEquals("Invalid value: book does not contain the field badfield", e.getMessage());
}
Also used : InvalidValueException(com.yahoo.elide.core.exceptions.InvalidValueException) Path(com.yahoo.elide.core.Path) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) Test(org.junit.jupiter.api.Test)

Aggregations

Path (com.yahoo.elide.core.Path)88 Test (org.junit.jupiter.api.Test)67 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)51 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)41 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)35 Query (com.yahoo.elide.datastores.aggregation.query.Query)35 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)34 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)33 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)31 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)29 Book (example.Book)29 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)22 Date (java.util.Date)19 Argument (com.yahoo.elide.core.request.Argument)14 EntityProjection (com.yahoo.elide.core.request.EntityProjection)14 GameRevenue (example.GameRevenue)14 HashSet (java.util.HashSet)14 Author (example.Author)12 Publisher (example.Publisher)9 Sorting (com.yahoo.elide.core.request.Sorting)8