Class Predicates

java.lang.Object
com.pervasive.datarush.functions.Predicates

public class Predicates extends Object
Provides implementations of common boolean and logical functions. These functions can also be combined to construct more complex predicates.

Most predicate functions follow three-valued logic (true, false, null) except where otherwise noted.

See Also:
  • Constructor Details

    • Predicates

      public Predicates()
  • Method Details

    • isConjunction

      public static boolean isConjunction(ScalarValuedFunction f)
      Tests whether the specified function is an AND predicate.
      Parameters:
      f - the function to test
      Returns:
      true if the function is an AND; false otherwise
      See Also:
    • isDisjunction

      public static boolean isDisjunction(ScalarValuedFunction f)
      Tests whether the specified function is an OR predicate.
      Parameters:
      f - the function to test
      Returns:
      true if the function is an OR; false otherwise
      See Also:
    • getPredicateClauses

      public static List<ScalarValuedFunction> getPredicateClauses(ScalarValuedFunction p)
      Extracts the predicate clauses from an AND or OR predicate.
      Parameters:
      p - the predicate to break into constituent clauses
      Returns:
      the subexpressions defining the clauses of the predicate
      Throws:
      IllegalArgumentException - if the predicate is not an AND or an OR
      See Also:
    • and

      public static ScalarValuedFunction and(ScalarValuedFunction... ps)
      Builds a record predicate which is a logical and of the specified predicates. The resulting predicate evaluates to:
      • true if all subpredicates evaluate to true.
      • false if any subpredicate evaluates to false.
      • null otherwise

      This version of and is provided for use in a fluent style with other static methods producing RecordPredicate objects, as illustrated by the following code fragment:
      and(eq("field1", "field2"),gt("field1","field3"))

      Parameters:
      ps - the predicates to be combined
      Returns:
      a new predicate evaluating to an and of the predicates under three-valued logic
    • and

      Builds a record predicate which is a logical and of the specified predicates. The resulting predicate evaluates to:
      • true if all subpredicates evaluate to true.
      • false if any subpredicate evaluates to false.
      • null otherwise
      Parameters:
      ps - the predicates to be combined
      Returns:
      a new predicate evaluating to an and of the predicates under three-valued logic
    • or

      public static ScalarValuedFunction or(ScalarValuedFunction... ps)
      Builds a record predicate which is a logical or of the specified predicates. The resulting predicate evaluates to
      • true if any subpredicate evaluates to true.
      • false if all subpredicates evaluate to false.
      • null otherwise

      This version of or is provided for use in a fluent style with other static methods producing RecordPredicate objects, as illustrated by the following code fragment:
      or(eq("field1", "field2"),gt("field1","field3"))

      Parameters:
      ps - the predicates to be combined
      Returns:
      a new predicate evaluating to an or of the predicates under three-valued logic
    • or

      Builds a record predicate which is a logical or of the specified predicates. The resulting predicate evaluates to
      • true if any subpredicate evaluates to true.
      • false if all subpredicates evaluate to false.
      • null otherwise
      Parameters:
      ps - the predicates to be combined
      Returns:
      a new predicate evaluating to an or of the predicates under three-valued logic
    • not

      Builds a record predicate which is a logical negation of specified predicate. The resulting predicate evaluates to
      • true if the given predicate evaluates to false.
      • false if the given predicate evaluates to true.
      • null otherwise
      Parameters:
      p - the predicates to be negated
      Returns:
      a new predicate evaluating to a negation of the predicate under three-valued logic
    • isTrue

      public static ScalarValuedFunction isTrue(ScalarValuedFunction p)
      Builds a record predicate which tests whether the specified predicate is true. The resulting predicate evaluates to
      • true if the given predicate evaluates to true.
      • false otherwise
      Parameters:
      p - the predicate to be tested
      Returns:
      a new predicate evaluating to a check of the truth of the predicate
    • notTrue

      public static ScalarValuedFunction notTrue(ScalarValuedFunction p)
      Builds a record predicate which tests whether the specified predicate is not true. The resulting predicate evaluates to
      • false if the given predicate evaluates to true.
      • true otherwise
      Parameters:
      p - the predicate to be tested
      Returns:
      a new predicate evaluating to a check of the non-truth of the predicate
    • isFalse

      public static ScalarValuedFunction isFalse(ScalarValuedFunction p)
      Builds a record predicate which tests whether the specified predicate is false. The resulting predicate evaluates to
      • true if the given predicate evaluates to false.
      • false otherwise
      Parameters:
      p - the predicate to be tested
      Returns:
      a new predicate evaluating to a check of the falsity of the predicate
    • notFalse

      public static ScalarValuedFunction notFalse(ScalarValuedFunction p)
      Builds a record predicate which tests whether the specified predicate is not false. The resulting predicate evaluates to
      • false if the given predicate evaluates to false.
      • true otherwise
      Parameters:
      p - the predicate to be tested
      Returns:
      a new predicate evaluating to a check of the non-falsity of the predicate
    • eq

      public static ScalarValuedFunction eq(String leftField, String rightField)
      Builds a record predicate which tests the equality of the specified fields. The fields must be of compatible types for comparison. If either field is null-valued, the predicate evaluates to null.
      Parameters:
      leftField - the first record field value in the comparison
      rightField - the second record field value in the comparison
      Returns:
      a function evaluating the predicate
    • eq

      public static ScalarValuedFunction eq(String field, ScalarValued value)
      Builds a record predicate which tests the equality of the specified field with a known value. The field and value must be of compatible types for comparison. If either value evaluates to null, so does the predicate.
      Parameters:
      field - the record field value in the comparison
      value - the known value in the comparison
      Returns:
      a function evaluating the predicate
    • eq

      public static ScalarValuedFunction eq(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)
      Builds a record predicate which tests the equality of the specified expressions. The expressions must evaluate to compatible types for comparison. If either expression evaluates to null, so does the predicate.
      Parameters:
      leftExpr - the expression producing the left value in the comparison
      rightExpr - the expression producing the right value in the comparison
      Returns:
      a function evaluating the predicate
    • neq

      public static ScalarValuedFunction neq(String leftField, String rightField)
      Builds a record predicate which tests the inequality of the specified fields. The fields must be of compatible types for comparison. If either field is null-valued, the predicate evaluates to null.
      Parameters:
      leftField - the first record field value in the comparison
      rightField - the second record field value in the comparison
      Returns:
      a function evaluating the predicate
    • neq

      public static ScalarValuedFunction neq(String field, ScalarValued value)
      Builds a record predicate which tests the inequality of the specified field with a known value. The field and value must be of compatible types for comparison. If either value evaluates to null, so does the predicate.
      Parameters:
      field - the record field value in the comparison
      value - the known value in the comparison
      Returns:
      a function evaluating the predicate
    • neq

      public static ScalarValuedFunction neq(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)
      Builds a record predicate which tests the inequality of the specified expressions. The expressions must evaluate to compatible types for comparison. If either expression evaluates to null, so does the predicate.
      Parameters:
      leftExpr - the expression producing the left value in the comparison
      rightExpr - the expression producing the right value in the comparison
      Returns:
      a function evaluating the predicate
    • lt

      public static ScalarValuedFunction lt(String leftField, String rightField)
      Builds a record predicate which tests whether a field is strictly less than another field. The fields must be of compatible types for comparison. If either field is null-valued, the predicate evaluates to null.
      Parameters:
      leftField - the record field value on the left side of the comparison
      rightField - the record field value on the right side of the comparison
      Returns:
      a function evaluating the predicate
    • lt

      public static ScalarValuedFunction lt(String leftField, ScalarValued rightValue)
      Builds a record predicate which tests whether a field is strictly less than a known value. The field and value must be of compatible types for comparison. If either value evaluates to null, so does the predicate.
      Parameters:
      leftField - the record field value on the left side of the comparison
      rightValue - the known value on the right side of the comparison
      Returns:
      a function evaluating the predicate
    • lt

      public static ScalarValuedFunction lt(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)
      Builds a record predicate which tests whether a specified expression is strictly less than another. The expressions must evaluate to compatible types for comparison. If either expression evaluates to null, so does the predicate.
      Parameters:
      leftExpr - the expression producing the left value in the comparison
      rightExpr - the expression producing the right value in the comparison
      Returns:
      a function evaluating the predicate
    • gt

      public static ScalarValuedFunction gt(String leftField, String rightField)
      Builds a record predicate which tests whether a field is strictly greater than another field. The fields must be of compatible types for comparison. If either field is null-valued, the predicate evaluates to null.
      Parameters:
      leftField - the record field value on the left side of the comparison
      rightField - the record field value on the right side of the comparison
      Returns:
      a function evaluating the predicate
    • gt

      public static ScalarValuedFunction gt(String leftField, ScalarValued rightValue)
      Builds a record predicate which tests whether a field is strictly greater than a known value. The field and value must be of compatible types for comparison. If either value evaluates to null, so does the predicate.
      Parameters:
      leftField - the record field value on the left side of the comparison
      rightValue - the known value on the right side of the comparison
      Returns:
      a function evaluating the predicate
    • gt

      public static ScalarValuedFunction gt(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)
      Builds a record predicate which tests whether a specified expression is strictly greater than another. The expressions must evaluate to compatible types for comparison. If either expression evaluates to null, so does the predicate.
      Parameters:
      leftExpr - the expression producing the left value in the comparison
      rightExpr - the expression producing the right value in the comparison
      Returns:
      a function evaluating the predicate
    • lte

      public static ScalarValuedFunction lte(String leftField, String rightField)
      Builds a record predicate which tests whether a field is less than or equal to another field. The fields must be of compatible types for comparison. If either field is null-valued, the predicate evaluates to null.
      Parameters:
      leftField - the record field value on the left side of the comparison
      rightField - the record field value on the right side of the comparison
      Returns:
      a function evaluating the predicate
    • lte

      public static ScalarValuedFunction lte(String leftField, ScalarValued rightValue)
      Builds a record predicate which tests whether a field is less than or equal to a known value. The field and value must be of compatible types for comparison. If either value evaluates to null, so does the predicate.
      Parameters:
      leftField - the record field value on the left side of the comparison
      rightValue - the known value on the right side of the comparison
      Returns:
      a function evaluating the predicate
    • lte

      public static ScalarValuedFunction lte(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)
      Builds a record predicate which tests whether a specified expression is less than or equal to another. The expressions must evaluate to compatible types for comparison. If either expression evaluates to null, so does the predicate.
      Parameters:
      leftExpr - the expression producing the left value in the comparison
      rightExpr - the expression producing the right value in the comparison
      Returns:
      a function evaluating the predicate
    • gte

      public static ScalarValuedFunction gte(String leftField, String rightField)
      Builds a record predicate which tests whether a field is greater than or equal to another field. The fields must be of compatible types for comparison. If either field is null-valued, the predicate evaluates to null.
      Parameters:
      leftField - the record field value on the left side of the comparison
      rightField - the record field value on the right side of the comparison
      Returns:
      a function evaluating the predicate
    • gte

      public static ScalarValuedFunction gte(String leftField, ScalarValued rightValue)
      Builds a record predicate which tests whether a field is greater than or equal to a known value. The field and value must be of compatible types for comparison. If either value evaluates to null, so does the predicate.
      Parameters:
      leftField - the record field value on the left side of the comparison
      rightValue - the known value on the right side of the comparison
      Returns:
      a function evaluating the predicate
    • gte

      public static ScalarValuedFunction gte(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)
      Builds a record predicate which tests whether a specified expression is greater than or equal to another. The expressions must evaluate to compatible types for comparison. If either expression evaluates to null, so does the predicate.
      Parameters:
      leftExpr - the expression producing the left value in the comparison
      rightExpr - the expression producing the right value in the comparison
      Returns:
      a function evaluating the predicate
    • isNull

      public static ScalarValuedFunction isNull(String field)
      Builds a record predicate which tests whether a record field is null-valued. This predicate never yields null.
      Parameters:
      field - the record field value to test
      Returns:
      a function evaluating the predicate
    • isNull

      public static ScalarValuedFunction isNull(ScalarValuedFunction expr)
      Builds a record predicate which tests whether the specified expression evaluates to null. This predicate never yields null.
      Parameters:
      expr - the expression to test
      Returns:
      a function evaluating the predicate
    • notNull

      public static ScalarValuedFunction notNull(String field)
      Builds a record predicate which tests whether a record field is not null-valued. This predicate never yields null.
      Parameters:
      field - the record field value to test
      Returns:
      a function evaluating the predicate
    • notNull

      public static ScalarValuedFunction notNull(ScalarValuedFunction expr)
      Builds a record predicate which tests whether the specified expression does not evaluate to null. This predicate never yields null.
      Parameters:
      expr - the expression to test
      Returns:
      a function evaluating the predicate
    • like

      public static ScalarValuedFunction like(String field, String pattern)
      Builds a record predicate which tests whether the value of a field matches a specified SQL LIKE pattern. The field must contain a string value. If the field evaluates to null, so does the predicate.
      Parameters:
      field - the record field against which to match
      pattern - the string pattern to match
      Returns:
      a function evaluating the predicate
    • like

      public static ScalarValuedFunction like(ScalarValuedFunction expr, String pattern)
      Builds a record predicate which tests whether the value of an expression matches a specified SQL LIKE pattern. The expression must evaluate to a string value. If the expression evaluates to null, so does the predicate.
      Parameters:
      expr - the expression to evaluate for the match operation
      pattern - the string pattern to match
      Returns:
      a function evaluating the predicate
    • likeToRegex

      public static String likeToRegex(String likePattern)
      Converts a SQL LIKE pattern into an equivalent regular expression. Essentially the following transformation is made:
      • % is converted to .*
      • _ is converted to .
      • character ranges are preserved as is, excepting that negated ranges convert the initial ! to a ^
      Parameters:
      likePattern - the pattern match for the LIKE operation
      Returns:
      an equivalent regular expression
    • matches

      public static ScalarValuedFunction matches(String field, String pattern)
      Builds a record predicate which tests whether the value of a field matches a specified regular expression. The field must contain a string value. If the field evaluates to null, so does the predicate.
      Parameters:
      field - the record field against which to match
      pattern - the string pattern to match
      Returns:
      a function evaluating the predicate
    • matches

      public static ScalarValuedFunction matches(ScalarValuedFunction expr, String pattern)
      Builds a record predicate which tests whether the value of an expression matches a specified regular expression. The expression must evaluate to a string value. If the expression evaluates to null, so does the predicate.
      Parameters:
      expr - the expression to evaluate for the match operation
      pattern - the string pattern to match
      Returns:
      a function evaluating the predicate