Class PredicateUtils


  • public class PredicateUtils
    extends java.lang.Object
    A collection of helpful utilities that can be used for generating, analyzing and manipulating predicates.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private PredicateUtils()
      This class should not be instantiated.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void collectConjuncts​(Expression expr, java.util.Collection<Expression> conjuncts)
      This method takes a predicate expr and stores all of its conjuncts into the specified collection of conjuncts.
      static void findExprsUsingSchemas​(java.util.Collection<Expression> srcExprs, boolean remove, java.util.Collection<Expression> dstExprs, Schema... schemas)
      This method takes a collection of expressions, and finds those expressions that can be evaluated solely against the provided schemas.
      static Expression makePredicate​(Expression... conjuncts)  
      static Expression makePredicate​(java.util.Collection<Expression> conjuncts)
      This helper function takes a collection of conjuncts that should comprise a predicate, and creates a predicate for evaluating these conjuncts.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PredicateUtils

        private PredicateUtils()
        This class should not be instantiated.
    • Method Detail

      • makePredicate

        public static Expression makePredicate​(java.util.Collection<Expression> conjuncts)
        This helper function takes a collection of conjuncts that should comprise a predicate, and creates a predicate for evaluating these conjuncts. The exact nature of the predicate depends on the conjuncts:
        • If the collection contains only one conjunct, the method simply returns that one conjunct.
        • If the collection contains two or more conjuncts, the method returns a BooleanOperator that performs an AND of all conjuncts.
        • If the collection contains no conjuncts then the method returns null.
        Parameters:
        conjuncts - the collection of conjuncts to combine into a predicate.
        Returns:
        a predicate for evaluating the conjuncts, or null if the input collection contained no conjuncts.
      • collectConjuncts

        public static void collectConjuncts​(Expression expr,
                                            java.util.Collection<Expression> conjuncts)

        This method takes a predicate expr and stores all of its conjuncts into the specified collection of conjuncts. Specifically, if the predicate is a Boolean AND operation then each term will individually be added to the collection of conjuncts. Any other kind of predicate will be stored as-is into the collection.

        Note that this method is not clever enough to handle many basic scenarios, such as P1 AND (P2 AND P3), and so forth.

        Also, note that the input expression is not modified; references to the various conjuncts are simply collected into the specified collection.

        Parameters:
        expr - the expression to pull the conjuncts out of
        conjuncts - the collection of conjuncts to add the predicate (or its components) to.
      • findExprsUsingSchemas

        public static void findExprsUsingSchemas​(java.util.Collection<Expression> srcExprs,
                                                 boolean remove,
                                                 java.util.Collection<Expression> dstExprs,
                                                 Schema... schemas)

        This method takes a collection of expressions, and finds those expressions that can be evaluated solely against the provided schemas. In other words, if an expression doesn't refer to any symbols outside of the specified schemas, then it will be included in the result collection.

        The last argument to this method is a series of Schema objects to check expressions against. For example, we can perform operations like this:

           Schema s1 = ...;
           Schema s2 = ...;
        
           // Find expressions in srcExprs that can be evaluated against s1, and
           // add them to dstExprs.  Do not remove matching exprs from srcExprs.
           findExprsUsingSchemas(srcExprs, false, dstExprs, s1);
        
           // Find expressions in srcExprs that can be evaluated against the
           // combination of s1 and s2, and add them to dstExprs.  Remove
           // matching exprs from srcExprs.
           findExprsUsingSchemas(srcExprs, true, dstExprs, s1, s2);
         
        Parameters:
        srcExprs - the input collection of expressions to check against the provided schemas.
        remove - if true, the matching expressions will be removed from the srcExprs collection. Otherwise, the srcExprs collection is left unchanged.
        dstExprs - the collection to add the matching expressions to. This collection is not cleared by this method; any previous contents in the collection will be left unchanged.
        schemas - an array of one or more schemas to check the input expressions against. If an expression can be evaluated solely against these schemas then it will be added to the results.