use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class DefaultQueryValidator method validateWhereClause.
@Override
public void validateWhereClause(Query query) {
FilterExpression whereClause = query.getWhereFilter();
if (whereClause == null) {
return;
}
whereClause.accept(new PredicateExtractionVisitor()).forEach(predicate -> {
Path path = predicate.getPath();
if (path.getPathElements().size() > 1) {
throw new InvalidOperationException("Relationship traversal not supported for analytic queries.");
}
validatePredicate(query, predicate);
});
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class EntityProjectionTranslator method splitFilters.
/**
* Gets whereFilter and havingFilter based on provided filter expression from {@link EntityProjection}.
*/
private void splitFilters() {
FilterExpression filterExpression = entityProjection.getFilterExpression();
if (filterExpression == null) {
whereFilter = null;
havingFilter = null;
return;
}
SplitFilterExpressionVisitor visitor = new SplitFilterExpressionVisitor(queriedTable);
FilterConstraints constraints = filterExpression.accept(visitor);
whereFilter = constraints.getWhereExpression();
havingFilter = constraints.getHavingExpression();
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class Queryable method getFilterProjections.
default List<ColumnProjection> getFilterProjections(FilterExpression expression) {
List<ColumnProjection> results = new ArrayList<>();
if (expression == null) {
return results;
}
Collection<FilterPredicate> predicates = expression.accept(new PredicateExtractionVisitor());
predicates.stream().forEach((predicate -> {
Map<String, Argument> arguments = new HashMap<>();
predicate.getPath().lastElement().get().getArguments().forEach(argument -> arguments.put(argument.getName(), argument));
ColumnProjection projection = getSource().getColumnProjection(predicate.getField(), arguments);
results.add(projection);
}));
return results;
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class Queryable method extractFilterProjections.
/**
* Converts a filter expression into a set of ColumnProjections.
* @param query The parent query.
* @param expression The filter expression to extract.
* @return A set of zero or more column projections with their arguments.
*/
static Set<ColumnProjection> extractFilterProjections(Queryable query, FilterExpression expression) {
if (expression == null) {
return new LinkedHashSet<>();
}
Collection<FilterPredicate> predicates = expression.accept(new PredicateExtractionVisitor());
Set<ColumnProjection> filterProjections = new LinkedHashSet<>();
predicates.stream().forEach((predicate -> {
Map<String, Argument> arguments = new HashMap<>();
predicate.getPath().lastElement().get().getArguments().forEach(argument -> arguments.put(argument.getName(), argument));
ColumnProjection projection = query.getSource().getColumnProjection(predicate.getField(), arguments);
if (projection != null) {
filterProjections.add(projection);
}
}));
return filterProjections;
}
use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.
the class FilteredIteratorTest method testFilteredResult.
@Test
public void testFilteredResult() throws Exception {
EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(Book.class);
Book book1 = new Book();
book1.setTitle("foo");
Book book2 = new Book();
book2.setTitle("bar");
Book book3 = new Book();
book3.setTitle("foobar");
List<Book> books = List.of(book1, book2, book3);
RSQLFilterDialect filterDialect = RSQLFilterDialect.builder().dictionary(dictionary).build();
FilterExpression expression = filterDialect.parse(ClassType.of(Book.class), new HashSet<>(), "title==*bar", NO_VERSION);
RequestScope scope = new TestRequestScope(null, null, dictionary);
Iterator<Book> bookIterator = new FilteredIterator<>(expression, scope, books.iterator());
assertTrue(bookIterator.hasNext());
assertEquals("bar", bookIterator.next().getTitle());
assertTrue(bookIterator.hasNext());
assertEquals("foobar", bookIterator.next().getTitle());
assertFalse(bookIterator.hasNext());
}
Aggregations