- 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 ScalarValuedFunctionand(ScalarValuedFunction... ps)Builds a record predicate which is a logical and of the specified predicates.static ScalarValuedFunctionand(List<ScalarValuedFunction> ps)Builds a record predicate which is a logical and of the specified predicates.static ScalarValuedFunctioneq(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)Builds a record predicate which tests the equality of the specified expressions.static ScalarValuedFunctioneq(String field, ScalarValued value)Builds a record predicate which tests the equality of the specified field with a known value.static ScalarValuedFunctioneq(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 ScalarValuedFunctiongt(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)Builds a record predicate which tests whether a specified expression is strictly greater than another.static ScalarValuedFunctiongt(String leftField, ScalarValued rightValue)Builds a record predicate which tests whether a field is strictly greater than a known value.static ScalarValuedFunctiongt(String leftField, String rightField)Builds a record predicate which tests whether a field is strictly greater than another field.static ScalarValuedFunctiongte(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)Builds a record predicate which tests whether a specified expression is greater than or equal to another.static ScalarValuedFunctiongte(String leftField, ScalarValued rightValue)Builds a record predicate which tests whether a field is greater than or equal to a known value.static ScalarValuedFunctiongte(String leftField, String rightField)Builds a record predicate which tests whether a field is greater than or equal to another field.static booleanisConjunction(ScalarValuedFunction f)Tests whether the specified function is an AND predicate.static booleanisDisjunction(ScalarValuedFunction f)Tests whether the specified function is an OR predicate.static ScalarValuedFunctionisFalse(ScalarValuedFunction p)Builds a record predicate which tests whether the specified predicate is false.static ScalarValuedFunctionisNull(ScalarValuedFunction expr)Builds a record predicate which tests whether the specified expression evaluates tonull.static ScalarValuedFunctionisNull(String field)Builds a record predicate which tests whether a record field is null-valued.static ScalarValuedFunctionisTrue(ScalarValuedFunction p)Builds a record predicate which tests whether the specified predicate is true.static ScalarValuedFunctionlike(ScalarValuedFunction expr, String pattern)Builds a record predicate which tests whether the value of an expression matches a specified SQL LIKE pattern.static ScalarValuedFunctionlike(String field, String pattern)Builds a record predicate which tests whether the value of a field matches a specified SQL LIKE pattern.static StringlikeToRegex(String likePattern)Converts a SQL LIKE pattern into an equivalent regular expression.static ScalarValuedFunctionlt(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)Builds a record predicate which tests whether a specified expression is strictly less than another.static ScalarValuedFunctionlt(String leftField, ScalarValued rightValue)Builds a record predicate which tests whether a field is strictly less than a known value.static ScalarValuedFunctionlt(String leftField, String rightField)Builds a record predicate which tests whether a field is strictly less than another field.static ScalarValuedFunctionlte(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)Builds a record predicate which tests whether a specified expression is less than or equal to another.static ScalarValuedFunctionlte(String leftField, ScalarValued rightValue)Builds a record predicate which tests whether a field is less than or equal to a known value.static ScalarValuedFunctionlte(String leftField, String rightField)Builds a record predicate which tests whether a field is less than or equal to another field.static ScalarValuedFunctionmatches(ScalarValuedFunction expr, String pattern)Builds a record predicate which tests whether the value of an expression matches a specified regular expression.static ScalarValuedFunctionmatches(String field, String pattern)Builds a record predicate which tests whether the value of a field matches a specified regular expression.static ScalarValuedFunctionneq(ScalarValuedFunction leftExpr, ScalarValuedFunction rightExpr)Builds a record predicate which tests the inequality of the specified expressions.static ScalarValuedFunctionneq(String field, ScalarValued value)Builds a record predicate which tests the inequality of the specified field with a known value.static ScalarValuedFunctionneq(String leftField, String rightField)Builds a record predicate which tests the inequality of the specified fields.static ScalarValuedFunctionnot(ScalarValuedFunction p)Builds a record predicate which is a logical negation of specified predicate.static ScalarValuedFunctionnotFalse(ScalarValuedFunction p)Builds a record predicate which tests whether the specified predicate is not false.static ScalarValuedFunctionnotNull(ScalarValuedFunction expr)Builds a record predicate which tests whether the specified expression does not evaluate tonull.static ScalarValuedFunctionnotNull(String field)Builds a record predicate which tests whether a record field is not null-valued.static ScalarValuedFunctionnotTrue(ScalarValuedFunction p)Builds a record predicate which tests whether the specified predicate is not true.static ScalarValuedFunctionor(ScalarValuedFunction... ps)Builds a record predicate which is a logical or of the specified predicates.static ScalarValuedFunctionor(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:
trueif the function is an AND;falseotherwise- 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:
trueif the function is an OR;falseotherwise- 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:trueif all subpredicates evaluate totrue.falseif any subpredicate evaluates tofalse.nullotherwise
This version of
andis provided for use in a fluent style with other static methods producingRecordPredicateobjects, 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:trueif all subpredicates evaluate totrue.falseif any subpredicate evaluates tofalse.nullotherwise
- 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 totrueif any subpredicate evaluates totrue.falseif all subpredicates evaluate tofalse.nullotherwise
This version of
oris provided for use in a fluent style with other static methods producingRecordPredicateobjects, 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 totrueif any subpredicate evaluates totrue.falseif all subpredicates evaluate tofalse.nullotherwise
- 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 totrueif the given predicate evaluates tofalse.falseif the given predicate evaluates totrue.nullotherwise
- 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 totrueif the given predicate evaluates totrue.falseotherwise
- 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 tofalseif the given predicate evaluates totrue.trueotherwise
- 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 totrueif the given predicate evaluates tofalse.falseotherwise
- 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 tofalseif the given predicate evaluates tofalse.trueotherwise
- 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
-
-