Search in sources :

Example 1 with FilterExpressionNormalizationVisitor

use of com.yahoo.elide.core.filter.visitors.FilterExpressionNormalizationVisitor in project elide by yahoo.

the class MatchesTemplateVisitor method isValid.

/**
 * Determines if a client filter matches or contains a subexpression that matches a template filter.
 * @param templateFilter A templated filter expression
 * @param clientFilter The client provided filter expression.
 * @param arguments If the client filter matches, extract any table arguments.
 * @return True if the client filter matches.  False otherwise.
 */
public static boolean isValid(FilterExpression templateFilter, FilterExpression clientFilter, Map<String, Argument> arguments) {
    Preconditions.checkNotNull(templateFilter);
    if (clientFilter == null) {
        return false;
    }
    // First we normalize the filters so any NOT clauses are pushed down immediately in front of a predicate.
    // This lets us treat logical AND and OR without regard for any preceding NOT clauses.
    FilterExpression normalizedTemplateFilter = templateFilter.accept(new FilterExpressionNormalizationVisitor());
    FilterExpression normalizedClientFilter = clientFilter.accept(new FilterExpressionNormalizationVisitor());
    MatchesTemplateVisitor templateVisitor = new MatchesTemplateVisitor(normalizedTemplateFilter);
    boolean matches = normalizedClientFilter.accept(templateVisitor);
    if (matches) {
        arguments.putAll(templateVisitor.arguments);
    }
    return matches;
}
Also used : FilterExpressionNormalizationVisitor(com.yahoo.elide.core.filter.visitors.FilterExpressionNormalizationVisitor) NotFilterExpression(com.yahoo.elide.core.filter.expression.NotFilterExpression) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) AndFilterExpression(com.yahoo.elide.core.filter.expression.AndFilterExpression) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression)

Example 2 with FilterExpressionNormalizationVisitor

use of com.yahoo.elide.core.filter.visitors.FilterExpressionNormalizationVisitor in project elide by yahoo.

the class SubqueryFilterSplitter method splitFilter.

public static SplitFilter splitFilter(MetaDataStore metaDataStore, FilterExpression expression) {
    if (expression == null) {
        return SplitFilter.builder().build();
    }
    FilterExpressionNormalizationVisitor normalizer = new FilterExpressionNormalizationVisitor();
    FilterExpression normalizedExpression = expression.accept(normalizer);
    return normalizedExpression.accept(new SubqueryFilterSplitter(metaDataStore));
}
Also used : FilterExpressionNormalizationVisitor(com.yahoo.elide.core.filter.visitors.FilterExpressionNormalizationVisitor) NotFilterExpression(com.yahoo.elide.core.filter.expression.NotFilterExpression) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) AndFilterExpression(com.yahoo.elide.core.filter.expression.AndFilterExpression) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression)

Example 3 with FilterExpressionNormalizationVisitor

use of com.yahoo.elide.core.filter.visitors.FilterExpressionNormalizationVisitor in project elide by yahoo.

the class FilterPredicatePushdownExtractor method extractPushDownPredicate.

/**
 * @param dictionary
 * @param expression
 * @return A filter expression that can be safely executed in the data store.
 */
public static FilterExpression extractPushDownPredicate(EntityDictionary dictionary, FilterExpression expression) {
    FilterExpressionNormalizationVisitor normalizationVisitor = new FilterExpressionNormalizationVisitor();
    FilterExpression normalizedExpression = expression.accept(normalizationVisitor);
    FilterPredicatePushdownExtractor verifier = new FilterPredicatePushdownExtractor(dictionary);
    return normalizedExpression.accept(verifier);
}
Also used : FilterExpressionNormalizationVisitor(com.yahoo.elide.core.filter.visitors.FilterExpressionNormalizationVisitor)

Aggregations

FilterExpressionNormalizationVisitor (com.yahoo.elide.core.filter.visitors.FilterExpressionNormalizationVisitor)3 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)2 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)2 NotFilterExpression (com.yahoo.elide.core.filter.expression.NotFilterExpression)2 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)2