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());
}
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);
}
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());
}
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);
}
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());
}
Aggregations