- 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:
ScalarValuedFunction
,DeriveFields
,FilterRows
-
-
Constructor Summary
Constructors Constructor Description Predicates()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ScalarValuedFunction
and(ScalarValuedFunction... ps)
Builds a record predicate which is a logical and of the specified predicates.static ScalarValuedFunction
and(List<ScalarValuedFunction> ps)
Builds a record predicate which is a logical and of the specified predicates.static ScalarValuedFunction
eq(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)
Builds a record predicate which tests the equality of the specified expressions.static ScalarValuedFunction
eq(String field, ScalarValued value)
Builds a record predicate which tests the equality of the specified field with a known value.static ScalarValuedFunction
eq(String leftField, String rightField)
Builds a record predicate which tests the equality of the specified fields.static List<ScalarValuedFunction>
getPredicateClauses(ScalarValuedFunction p)
Extracts the predicate clauses from an AND or OR predicate.static ScalarValuedFunction
gt(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)
Builds a record predicate which tests whether a specified expression is strictly greater than another.static ScalarValuedFunction
gt(String leftField, ScalarValued rightValue)
Builds a record predicate which tests whether a field is strictly greater than a known value.static ScalarValuedFunction
gt(String leftField, String rightField)
Builds a record predicate which tests whether a field is strictly greater than another field.static ScalarValuedFunction
gte(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)
Builds a record predicate which tests whether a specified expression is greater than or equal to another.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.static ScalarValuedFunction
gte(String leftField, String rightField)
Builds a record predicate which tests whether a field is greater than or equal to another field.static boolean
isConjunction(ScalarValuedFunction f)
Tests whether the specified function is an AND predicate.static boolean
isDisjunction(ScalarValuedFunction f)
Tests whether the specified function is an OR predicate.static ScalarValuedFunction
isFalse(ScalarValuedFunction p)
Builds a record predicate which tests whether the specified predicate is false.static ScalarValuedFunction
isNull(ScalarValuedFunction expr)
Builds a record predicate which tests whether the specified expression evaluates tonull
.static ScalarValuedFunction
isNull(String field)
Builds a record predicate which tests whether a record field is null-valued.static ScalarValuedFunction
isTrue(ScalarValuedFunction p)
Builds a record predicate which tests whether the specified predicate is true.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.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.static String
likeToRegex(String likePattern)
Converts a SQL LIKE pattern into an equivalent regular expression.static ScalarValuedFunction
lt(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)
Builds a record predicate which tests whether a specified expression is strictly less than another.static ScalarValuedFunction
lt(String leftField, ScalarValued rightValue)
Builds a record predicate which tests whether a field is strictly less than a known value.static ScalarValuedFunction
lt(String leftField, String rightField)
Builds a record predicate which tests whether a field is strictly less than another field.static ScalarValuedFunction
lte(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)
Builds a record predicate which tests whether a specified expression is less than or equal to another.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.static ScalarValuedFunction
lte(String leftField, String rightField)
Builds a record predicate which tests whether a field is less than or equal to another field.static ScalarValuedFunction
matches(ScalarValuedFunction expr, String pattern)
Builds a record predicate which tests whether the value of an expression matches a specified regular expression.static ScalarValuedFunction
matches(String field, String pattern)
Builds a record predicate which tests whether the value of a field matches a specified regular expression.static ScalarValuedFunction
neq(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)
Builds a record predicate which tests the inequality of the specified expressions.static ScalarValuedFunction
neq(String field, ScalarValued value)
Builds a record predicate which tests the inequality of the specified field with a known value.static ScalarValuedFunction
neq(String leftField, String rightField)
Builds a record predicate which tests the inequality of the specified fields.static ScalarValuedFunction
not(ScalarValuedFunction p)
Builds a record predicate which is a logical negation of specified predicate.static ScalarValuedFunction
notFalse(ScalarValuedFunction p)
Builds a record predicate which tests whether the specified predicate is not false.static ScalarValuedFunction
notNull(ScalarValuedFunction expr)
Builds a record predicate which tests whether the specified expression does not evaluate tonull
.static ScalarValuedFunction
notNull(String field)
Builds a record predicate which tests whether a record field is not null-valued.static ScalarValuedFunction
notTrue(ScalarValuedFunction p)
Builds a record predicate which tests whether the specified predicate is not true.static ScalarValuedFunction
or(ScalarValuedFunction... ps)
Builds a record predicate which is a logical or of the specified predicates.static ScalarValuedFunction
or(List<ScalarValuedFunction> ps)
Builds a record predicate which is a logical or of the specified predicates.
-
-
-
Method Detail
-
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:
and(ScalarValuedFunction...)
-
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:
or(ScalarValuedFunction...)
-
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:
or(ScalarValuedFunction...)
,and(ScalarValuedFunction...)
-
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 totrue
.false
if any subpredicate evaluates tofalse
.null
otherwise
This version of
and
is provided for use in a fluent style with other static methods producingRecordPredicate
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
public static ScalarValuedFunction and(List<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 totrue
.false
if any subpredicate evaluates tofalse
.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 totrue
if any subpredicate evaluates totrue
.false
if all subpredicates evaluate tofalse
.null
otherwise
This version of
or
is provided for use in a fluent style with other static methods producingRecordPredicate
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
public static ScalarValuedFunction or(List<ScalarValuedFunction> ps)
Builds a record predicate which is a logical or of the specified predicates. The resulting predicate evaluates totrue
if any subpredicate evaluates totrue
.false
if all subpredicates evaluate tofalse
.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
public static ScalarValuedFunction not(ScalarValuedFunction p)
Builds a record predicate which is a logical negation of specified predicate. The resulting predicate evaluates totrue
if the given predicate evaluates tofalse
.false
if the given predicate evaluates totrue
.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 totrue
if the given predicate evaluates totrue
.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 tofalse
if the given predicate evaluates totrue
.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 totrue
if the given predicate evaluates tofalse
.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 tofalse
if the given predicate evaluates tofalse
.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 tonull
.- Parameters:
leftField
- the first record field value in the comparisonrightField
- 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 tonull
, so does the predicate.- Parameters:
field
- the record field value in the comparisonvalue
- 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 tonull
, so does the predicate.- Parameters:
leftExpr
- the expression producing the left value in the comparisonrightExpr
- 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 tonull
.- Parameters:
leftField
- the first record field value in the comparisonrightField
- 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 tonull
, so does the predicate.- Parameters:
field
- the record field value in the comparisonvalue
- 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 tonull
, so does the predicate.- Parameters:
leftExpr
- the expression producing the left value in the comparisonrightExpr
- 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 tonull
.- Parameters:
leftField
- the record field value on the left side of the comparisonrightField
- 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 tonull
, so does the predicate.- Parameters:
leftField
- the record field value on the left side of the comparisonrightValue
- 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 tonull
, so does the predicate.- Parameters:
leftExpr
- the expression producing the left value in the comparisonrightExpr
- 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 tonull
.- Parameters:
leftField
- the record field value on the left side of the comparisonrightField
- 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 tonull
, so does the predicate.- Parameters:
leftField
- the record field value on the left side of the comparisonrightValue
- 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 tonull
, so does the predicate.- Parameters:
leftExpr
- the expression producing the left value in the comparisonrightExpr
- 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 tonull
.- Parameters:
leftField
- the record field value on the left side of the comparisonrightField
- 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 tonull
, so does the predicate.- Parameters:
leftField
- the record field value on the left side of the comparisonrightValue
- 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 tonull
, so does the predicate.- Parameters:
leftExpr
- the expression producing the left value in the comparisonrightExpr
- 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 tonull
.- Parameters:
leftField
- the record field value on the left side of the comparisonrightField
- 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 tonull
, so does the predicate.- Parameters:
leftField
- the record field value on the left side of the comparisonrightValue
- 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 tonull
, so does the predicate.- Parameters:
leftExpr
- the expression producing the left value in the comparisonrightExpr
- 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 yieldsnull
.- 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 tonull
. This predicate never yieldsnull
.- 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 yieldsnull
.- 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 tonull
. This predicate never yieldsnull
.- 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 tonull
, so does the predicate.- Parameters:
field
- the record field against which to matchpattern
- 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 tonull
, so does the predicate.- Parameters:
expr
- the expression to evaluate for the match operationpattern
- 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 tonull
, so does the predicate.- Parameters:
field
- the record field against which to matchpattern
- 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 tonull
, so does the predicate.- Parameters:
expr
- the expression to evaluate for the match operationpattern
- the string pattern to match- Returns:
- a function evaluating the predicate
-
-