- java.lang.Object
-
- com.pervasive.datarush.functions.Strings
-
public class Strings extends Object
Provides implementations of common string functions.- See Also:
ScalarValuedFunction,DeriveFields
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStrings.NullConcatenationSpecifies behavior of null values for string concatenation.
-
Constructor Summary
Constructors Constructor Description Strings()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ScalarValuedFunctionconcat(ScalarValuedFunction... exprs)Builds a function returning a concatenation of the string representations of the evaluated expressions.static ScalarValuedFunctionconcat(Strings.NullConcatenation nullHandling, ScalarValuedFunction... exprs)Builds a function returning a concatenation of the string representations of the evaluated expressions.static ScalarValuedFunctionconcat(Strings.NullConcatenation nullHandling, List<ScalarValuedFunction> exprs)Builds a function returning a concatenation of the string representations of the evaluated expressions.static ScalarValuedFunctionconcat(List<ScalarValuedFunction> exprs)Builds a function returning a concatenation of the string representations of the evaluated expressions.static ScalarValuedFunctionfind(ScalarValuedFunction value, String pattern)Builds a function returning the first index of the substring that matches the provided pattern in the string value to which the specified expression evaluates.static ScalarValuedFunctionfind(String field, String pattern)Builds a function returning the first index of the substring that matches the provided pattern in the specified string field.static ScalarValuedFunctionindexOf(ScalarValuedFunction value, ScalarValuedFunction string)Builds a function returning the first index of the specified string that occurs in the string value to which the specified expression evaluates.static ScalarValuedFunctionindexOf(ScalarValuedFunction value, String str)Builds a function returning the first index of the specified string that occurs in the string value to which the specified expression evaluates.static ScalarValuedFunctionindexOf(String field, String str)Builds a function returning the first index of the specified substring in the specified string field.static ScalarValuedFunctionlastIndexOf(ScalarValuedFunction value, ScalarValuedFunction string)Builds a function returning the last index of the specified string that occurs in the string value to which the specified expression evaluates.static ScalarValuedFunctionlastIndexOf(ScalarValuedFunction value, String str)Builds a function returning the last index of the specified string that occurs in the string value to which the specified expression evaluates.static ScalarValuedFunctionlastIndexOf(String field, String str)Builds a function returning the last index of the specified substring in the specified string field.static ScalarValuedFunctionlength(ScalarValuedFunction expr)Builds a function returning the length of the string value to which the given expression evaluates.static ScalarValuedFunctionlength(String field)Builds a function returning the length of the string value in the specified field.static ScalarValuedFunctionmid(ScalarValuedFunction expr, int index, int length)Builds a function returning a substring of the string value to which the specified expression evaluates.static ScalarValuedFunctionmid(ScalarValuedFunction expr, int index, ScalarValuedFunction length)Builds a function returning a substring of the string value to which the specified expression evaluates.static ScalarValuedFunctionmid(ScalarValuedFunction expr, ScalarValuedFunction index, int length)Builds a function returning a substring of the string value to which the specified expression evaluates.static ScalarValuedFunctionmid(ScalarValuedFunction expr, ScalarValuedFunction index, ScalarValuedFunction length)Builds a function returning a substring of the string value to which the specified expression evaluates.static ScalarValuedFunctionmid(String field, int index, int length)Builds a function returning a substring of the string value in the specified field.static ScalarValuedFunctionreplaceAll(ScalarValuedFunction value, String pattern, ScalarValuedFunction replacement)Builds a function replacing all occurrences of a given pattern in the result of a specified expression.static ScalarValuedFunctionreplaceAll(ScalarValuedFunction value, String pattern, String replacement)Builds a function replacing all occurrences of a given pattern in the result of a specified expression.static ScalarValuedFunctionreplaceAll(String field, String pattern, String replacement)Builds a function replacing all occurrences of a given pattern in the specified field value.static ScalarValuedFunctionreplaceFirst(ScalarValuedFunction value, String pattern, ScalarValuedFunction replacement)Builds a function replacing the first occurrence of a given pattern in the result of a specified expression.static ScalarValuedFunctionreplaceFirst(ScalarValuedFunction value, String pattern, String replacement)Builds a function replacing the first occurrence of a given pattern in the result of a specified expression.static ScalarValuedFunctionreplaceFirst(String field, String pattern, String replacement)Builds a function replacing the first occurrence of a given pattern in the specified field value.static ScalarValuedFunctionsubstr(ScalarValuedFunction expr, int start)Builds a function returning a substring of the string value to which the specified expression evaluates, starting at a specified index.static ScalarValuedFunctionsubstr(ScalarValuedFunction expr, int start, int end)Builds a function returning a substring of the string value to which the specified expression evaluates, between specified indexes.static ScalarValuedFunctionsubstr(ScalarValuedFunction expr, ScalarValuedFunction start)Builds a function returning a substring of the string value to which the specified expression evaluates, starting at a specified index.static ScalarValuedFunctionsubstr(ScalarValuedFunction expr, ScalarValuedFunction start, ScalarValuedFunction end)Builds a function returning a substring of the string value to which the specified expression evaluates, between specified indexes.static ScalarValuedFunctionsubstr(String field, int start)Builds a function returning a substring of the string value in the specified field, starting at a specified index.static ScalarValuedFunctionsubstr(String field, int start, int end)Builds a function returning a substring of the string value in the specified field, between specified indexes.static ScalarValuedFunctiontoLowerCase(ScalarValuedFunction expr)Builds a function returning the lower case string value of the string to which the given expression evaluates.static ScalarValuedFunctiontoLowerCase(String field)Builds a function returning the lower case string value in the specified field.static ScalarValuedFunctiontoUpperCase(ScalarValuedFunction expr)Builds a function returning the upper case string value of the string to which the given expression evaluates.static ScalarValuedFunctiontoUpperCase(String field)Builds a function returning the upper case string value in the specified field.static ScalarValuedFunctiontrim(ScalarValuedFunction expr)Builds a function returning the whitespace trimmed string value of the string to which the given expression evaluates.static ScalarValuedFunctiontrim(String field)Builds a function returning the whitespace trimmed string value in the specified field.
-
-
-
Method Detail
-
length
public static ScalarValuedFunction length(String field)
Builds a function returning the length of the string value in the specified field. If the value isnull, the return length is alsonull.- Parameters:
field- the record field value on which to calculate the string length- Returns:
- a function evaluating the expression
-
length
public static ScalarValuedFunction length(ScalarValuedFunction expr)
Builds a function returning the length of the string value to which the given expression evaluates. If the value isnull, the return length is alsonull.- Parameters:
expr- the expression producing the string value- Returns:
- a function evaluating the expression
-
trim
public static ScalarValuedFunction trim(String field)
Builds a function returning the whitespace trimmed string value in the specified field. If the value isnull, the result isnull.- Parameters:
field- the record field value to trim- Returns:
- a function evaluating the expression
-
trim
public static ScalarValuedFunction trim(ScalarValuedFunction expr)
Builds a function returning the whitespace trimmed string value of the string to which the given expression evaluates. If the value isnull, the result isnull.- Parameters:
expr- the expression producing the string value to trim- Returns:
- a function evaluating the expression
-
toUpperCase
public static ScalarValuedFunction toUpperCase(String field)
Builds a function returning the upper case string value in the specified field. If the value isnull, the result isnull.- Parameters:
field- the record field value to convert to upper case- Returns:
- a function evaluating the expression
-
toUpperCase
public static ScalarValuedFunction toUpperCase(ScalarValuedFunction expr)
Builds a function returning the upper case string value of the string to which the given expression evaluates. If the value isnull, the result isnull.- Parameters:
expr- the expression producing the string value to cast to upper case- Returns:
- a function evaluating the expression
-
toLowerCase
public static ScalarValuedFunction toLowerCase(String field)
Builds a function returning the lower case string value in the specified field. If the value isnull, the result isnull.- Parameters:
field- the record field value to convert to lower case- Returns:
- a function evaluating the expression
-
toLowerCase
public static ScalarValuedFunction toLowerCase(ScalarValuedFunction expr)
Builds a function returning the lower case string value of the string to which the given expression evaluates. If the value isnull, the result isnull.- Parameters:
expr- the expression producing the string value to cast to lower case- Returns:
- a function evaluating the expression
-
substr
public static ScalarValuedFunction substr(String field, int start)
Builds a function returning a substring of the string value in the specified field, starting at a specified index. If an index falls outside the bounds of the string value, it is truncated to the nearest boundary.The result will be
nullif the input string isnull.- Parameters:
field- the record field from which to get a substringstart- the beginning index of the substring, inclusive. The substring includes all characters up to the end of the string.- Returns:
- a function evaluating the expression
-
substr
public static ScalarValuedFunction substr(String field, int start, int end)
Builds a function returning a substring of the string value in the specified field, between specified indexes. If an index falls outside the bounds of the string value, it is truncated to the nearest boundary.The result will be
nullif the input string isnull. If the start index is greater than the end index, the result is the empty string.- Parameters:
field- the record field value from which to get a substringstart- the beginning index of the substring, inclusiveend- the ending index of the substring, exclusive. If the end index is beyond the end of the string, the substring will be taken up to the end of the string.- Returns:
- a function evaluating the expression
-
substr
public static ScalarValuedFunction substr(ScalarValuedFunction expr, int start)
Builds a function returning a substring of the string value to which the specified expression evaluates, starting at a specified index. If an index falls outside the bounds of the string value, it is truncated to the nearest boundary.The result will be
nullif the input string isnull.- Parameters:
expr- a string expression from which to get a substringstart- the beginning index of the substring, inclusive. The substring includes all characters up to the end of the string.- Returns:
- a function evaluating the expression
-
substr
public static ScalarValuedFunction substr(ScalarValuedFunction expr, int start, int end)
Builds a function returning a substring of the string value to which the specified expression evaluates, between specified indexes. If an index falls outside the bounds of the string value, it is truncated to the nearest boundary.The result will be
nullif the input string isnull. If the start index is greater than the end index, the result is the empty string.- Parameters:
expr- a string expression from which to get a substringstart- the beginning index of the substring, inclusiveend- the ending index of the substring, exclusive. If the end index is beyond the end of the string, the substring will be taken up to the end of the string.- Returns:
- a function evaluating the expression
-
substr
public static ScalarValuedFunction substr(ScalarValuedFunction expr, ScalarValuedFunction start)
Builds a function returning a substring of the string value to which the specified expression evaluates, starting at a specified index. If an index falls outside the bounds of the string value, it is truncated to the nearest boundary.The result will be
nullif the input string isnull.- Parameters:
expr- a string expression from which to get a substringstart- an integer expression for the beginning index of the substring, inclusive. The substring includes all characters up to the end of the string.- Returns:
- a function evaluating the expression
-
substr
public static ScalarValuedFunction substr(ScalarValuedFunction expr, ScalarValuedFunction start, ScalarValuedFunction end)
Builds a function returning a substring of the string value to which the specified expression evaluates, between specified indexes. If an index falls outside the bounds of the string value, it is truncated to the nearest boundary.The result will be
nullif the input string isnull. If the start index is greater than the end index, the result is the empty string.- Parameters:
expr- a string expression from which to get a substringstart- an integer expression for the beginning index of the substring, inclusiveend- an integer expression for the ending index of the substring, exclusive. If the result is beyond the end of the string, the substring will be taken up to the end of the string.- Returns:
- a function evaluating the expression
-
mid
public static ScalarValuedFunction mid(String field, int index, int length)
Builds a function returning a substring of the string value in the specified field. The substring starts at the given offset index and has the length specified. If the index falls outside the bounds of the string value, it is truncated to the nearest boundary. If the length number of characters are not available the remainder of the string will be returned.The result will be
nullif the input string isnull. If the length is negative the result will be an empty string.- Parameters:
field- the record field value from which to get a substringindex- the beginning index of the substringlength- the number of characters to include in the substring including the initial character at the index- Returns:
- a function evaluating the expression
-
mid
public static ScalarValuedFunction mid(ScalarValuedFunction expr, int index, int length)
Builds a function returning a substring of the string value to which the specified expression evaluates. The substring starts at the given offset index and has the length specified. If the index falls outside the bounds of the string value, it is truncated to the nearest boundary. If the length number of characters are not available the remainder of the string will be returned.The result will be
nullif the input string isnull. If the length is negative the result will be an empty string.- Parameters:
expr- a string expression from which to get a substringindex- the beginning index of the substringlength- the number of characters to include in the substring including the initial character at the index- Returns:
- a function evaluating the expression
-
mid
public static ScalarValuedFunction mid(ScalarValuedFunction expr, ScalarValuedFunction index, int length)
Builds a function returning a substring of the string value to which the specified expression evaluates. The substring starts at the given offset index and has the length specified. If the index falls outside the bounds of the string value, it is truncated to the nearest boundary. If the length number of characters are not available the remainder of the string will be returned.The result will be
nullif the input string isnull. If the length is negative the result will be an empty string.- Parameters:
expr- a string expression from which to get a substringindex- an integer expression for the beginning index of the substringlength- the number of characters to include in the substring including the initial character at the index- Returns:
- a function evaluating the expression
-
mid
public static ScalarValuedFunction mid(ScalarValuedFunction expr, int index, ScalarValuedFunction length)
Builds a function returning a substring of the string value to which the specified expression evaluates. The substring starts at the given offset index and has the length specified. If the index falls outside the bounds of the string value, it is truncated to the nearest boundary. If the length number of characters are not available the remainder of the string will be returned.The result will be
nullif the input string isnull. If the length is negative the result will be an empty string.- Parameters:
expr- a string expression from which to get a substringindex- the beginning index of the substringlength- an integer expression for the number of characters to include in the substring including the initial character at the index- Returns:
- a function evaluating the expression
-
mid
public static ScalarValuedFunction mid(ScalarValuedFunction expr, ScalarValuedFunction index, ScalarValuedFunction length)
Builds a function returning a substring of the string value to which the specified expression evaluates. The substring starts at the given offset index and has the length specified. If the index falls outside the bounds of the string value, it is truncated to the nearest boundary. If the length number of characters are not available the remainder of the string will be returned.The result will be
nullif the input string isnull. If the length is negative the result will be an empty string.- Parameters:
expr- a string expression from which to get a substringindex- an integer expression for the beginning index of the substringlength- an integer expression for the number of characters to include in the substring including the initial character at the index- Returns:
- a function evaluating the expression
-
concat
public static ScalarValuedFunction concat(ScalarValuedFunction... exprs)
Builds a function returning a concatenation of the string representations of the evaluated expressions. Non-string values are converted to strings using default formatting. If this is not desired, use an expression which performs the desired formatting, such asConversions.toText(String, java.text.Format). Null-valued arguments are ignored; this is equivalent to treating them as the empty string. To control behavior for null useconcat(NullConcatenation, ScalarValuedFunction...).- Parameters:
exprs- expressions from which to concatenate values- Returns:
- a function evaluating the expression
-
concat
public static ScalarValuedFunction concat(List<ScalarValuedFunction> exprs)
Builds a function returning a concatenation of the string representations of the evaluated expressions. Non-string values are converted to strings using default formatting. If this is not desired, use an expression which performs the desired formatting, such asConversions.toText(String, java.text.Format). Null-valued arguments are ignored; this is equivalent to treating them as the empty string. To control behavior for null useconcat(NullConcatenation, List).- Parameters:
exprs- expressions from which to concatenate values- Returns:
- a function evaluating the expression
-
concat
public static ScalarValuedFunction concat(Strings.NullConcatenation nullHandling, ScalarValuedFunction... exprs)
Builds a function returning a concatenation of the string representations of the evaluated expressions. Non-string values are converted to strings using default formatting. If this is not desired, use an expression which performs the desired formatting, such asConversions.toText(String, java.text.Format). Null-valued arguments are- Parameters:
nullHandling- indicates how to deal with null-valued argumentsexprs- expressions from which to concatenate values- Returns:
- a function evaluating the expression
-
concat
public static ScalarValuedFunction concat(Strings.NullConcatenation nullHandling, List<ScalarValuedFunction> exprs)
Builds a function returning a concatenation of the string representations of the evaluated expressions. Nulls are handled as specified. Non-string values are converted to strings using default formatting. If this is not desired, use an expression which performs the desired formatting, such asConversions.toText(String, java.text.Format).- Parameters:
nullHandling- indicates how to deal with null-valued argumentsexprs- expressions from which to concatenate values- Returns:
- a function evaluating the expression
-
replaceAll
public static ScalarValuedFunction replaceAll(String field, String pattern, String replacement)
Builds a function replacing all occurrences of a given pattern in the specified field value. If the pattern is not matched, the value is unchanged.- Parameters:
field- the record field value on which to perform replacementpattern- a regular expression describing the pattern to replacereplacement- the value with which to replace any matches- Returns:
- a function evaluating the expression
-
replaceAll
public static ScalarValuedFunction replaceAll(ScalarValuedFunction value, String pattern, String replacement)
Builds a function replacing all occurrences of a given pattern in the result of a specified expression. If the pattern is not matched, the value is unchanged.- Parameters:
value- a string expression on which to perform pattern replacementpattern- a regular expression describing the pattern to replacereplacement- the value with which to replace any matches- Returns:
- a function evaluating the expression
-
replaceAll
public static ScalarValuedFunction replaceAll(ScalarValuedFunction value, String pattern, ScalarValuedFunction replacement)
Builds a function replacing all occurrences of a given pattern in the result of a specified expression. If the pattern is not matched, the value is unchanged. The replacement value is obtained by evaluating a provided string expression.- Parameters:
value- a string expression on which to perform pattern replacementpattern- a regular expression describing the pattern to replacereplacement- a string expression with which to replace any matches- Returns:
- a function evaluating the expression
-
replaceFirst
public static ScalarValuedFunction replaceFirst(String field, String pattern, String replacement)
Builds a function replacing the first occurrence of a given pattern in the specified field value. If the pattern is not matched, the value is unchanged.- Parameters:
field- the record field value on which to perform replacementpattern- a regular expression describing the pattern to replacereplacement- the value with which to replace any matches- Returns:
- a function evaluating the expression
-
replaceFirst
public static ScalarValuedFunction replaceFirst(ScalarValuedFunction value, String pattern, String replacement)
Builds a function replacing the first occurrence of a given pattern in the result of a specified expression. If the pattern is not matched, the value is unchanged.- Parameters:
value- a string expression on which to perform pattern replacementpattern- a regular expression describing the pattern to replacereplacement- the value with which to replace any matches- Returns:
- a function evaluating the expression
-
replaceFirst
public static ScalarValuedFunction replaceFirst(ScalarValuedFunction value, String pattern, ScalarValuedFunction replacement)
Builds a function replacing the first occurrence of a given pattern in the result of a specified expression. If the pattern is not matched, the value is unchanged. The replacement value is obtained by evaluating a provided string expression.- Parameters:
value- a string expression on which to perform pattern replacementpattern- a regular expression describing the pattern to replacereplacement- a string expression with which to replace any matches- Returns:
- a function evaluating the expression
-
indexOf
public static ScalarValuedFunction indexOf(String field, String str)
Builds a function returning the first index of the specified substring in the specified string field. If the string is not found -1 will be returned.- Parameters:
field- the record field value to search for the stringstr- the string to search for- Returns:
- a function evaluating the expression
-
indexOf
public static ScalarValuedFunction indexOf(ScalarValuedFunction value, String str)
Builds a function returning the first index of the specified string that occurs in the string value to which the specified expression evaluates. If the string is not found -1 will be returned.- Parameters:
value- the expression producing the string valuestr- the string to search for- Returns:
- a function evaluating the expression
-
indexOf
public static ScalarValuedFunction indexOf(ScalarValuedFunction value, ScalarValuedFunction string)
Builds a function returning the first index of the specified string that occurs in the string value to which the specified expression evaluates. If the string is not found -1 will be returned.- Parameters:
value- the expression producing the string valuestring- the string to search for- Returns:
- a function evaluating the expression
-
lastIndexOf
public static ScalarValuedFunction lastIndexOf(String field, String str)
Builds a function returning the last index of the specified substring in the specified string field. If the string is not found -1 will be returned.- Parameters:
field- the record field value to search for the stringstr- the string to search for- Returns:
- a function evaluating the expression
-
lastIndexOf
public static ScalarValuedFunction lastIndexOf(ScalarValuedFunction value, String str)
Builds a function returning the last index of the specified string that occurs in the string value to which the specified expression evaluates. If the string is not found -1 will be returned.- Parameters:
value- the expression producing the string valuestr- the string to search for- Returns:
- a function evaluating the expression
-
lastIndexOf
public static ScalarValuedFunction lastIndexOf(ScalarValuedFunction value, ScalarValuedFunction string)
Builds a function returning the last index of the specified string that occurs in the string value to which the specified expression evaluates. If the string is not found -1 will be returned.- Parameters:
value- the expression producing the string valuestring- the string to search for- Returns:
- a function evaluating the expression
-
find
public static ScalarValuedFunction find(String field, String pattern)
Builds a function returning the first index of the substring that matches the provided pattern in the specified string field. If a substring matching the pattern is not found -1 will be returned.- Parameters:
field- the record field value to search for the stringpattern- a regular expression describing the pattern to search for- Returns:
- a function evaluating the expression
-
find
public static ScalarValuedFunction find(ScalarValuedFunction value, String pattern)
Builds a function returning the first index of the substring that matches the provided pattern in the string value to which the specified expression evaluates. If a substring matching the pattern is not found -1 will be returned.- Parameters:
value- the expression producing the string valuepattern- a regular expression describing the pattern to search for- Returns:
- a function evaluating the expression
-
-