Class Strings


  • public class Strings
    extends Object
    Provides implementations of common string functions.
    See Also:
    ScalarValuedFunction, DeriveFields
    • Constructor Detail

      • Strings

        public Strings()
    • 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 is null, the return length is also null.
        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 is null, the return length is also null.
        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 is null, the result is null.
        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 is null, the result is null.
        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 is null, the result is null.
        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 is null, the result is null.
        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 is null, the result is null.
        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 is null, the result is null.
        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 null if the input string is null.

        Parameters:
        field - the record field from which to get a substring
        start - 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 null if the input string is null. 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 substring
        start - the beginning index of the substring, inclusive
        end - 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 null if the input string is null.

        Parameters:
        expr - a string expression from which to get a substring
        start - 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 null if the input string is null. 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 substring
        start - the beginning index of the substring, inclusive
        end - 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 null if the input string is null.

        Parameters:
        expr - a string expression from which to get a substring
        start - 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 null if the input string is null. 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 substring
        start - an integer expression for the beginning index of the substring, inclusive
        end - 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 null if the input string is null. If the length is negative the result will be an empty string.

        Parameters:
        field - the record field value from which to get a substring
        index - the beginning index of the substring
        length - 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 null if the input string is null. If the length is negative the result will be an empty string.

        Parameters:
        expr - a string expression from which to get a substring
        index - the beginning index of the substring
        length - 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 null if the input string is null. If the length is negative the result will be an empty string.

        Parameters:
        expr - a string expression from which to get a substring
        index - an integer expression for the beginning index of the substring
        length - 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 null if the input string is null. If the length is negative the result will be an empty string.

        Parameters:
        expr - a string expression from which to get a substring
        index - the beginning index of the substring
        length - 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 null if the input string is null. If the length is negative the result will be an empty string.

        Parameters:
        expr - a string expression from which to get a substring
        index - an integer expression for the beginning index of the substring
        length - 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 as Conversions.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 use concat(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 as Conversions.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 use concat(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 as Conversions.toText(String, java.text.Format). Null-valued arguments are
        Parameters:
        nullHandling - indicates how to deal with null-valued arguments
        exprs - 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 as Conversions.toText(String, java.text.Format).
        Parameters:
        nullHandling - indicates how to deal with null-valued arguments
        exprs - 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 replacement
        pattern - a regular expression describing the pattern to replace
        replacement - 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 replacement
        pattern - a regular expression describing the pattern to replace
        replacement - 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 replacement
        pattern - a regular expression describing the pattern to replace
        replacement - 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 replacement
        pattern - a regular expression describing the pattern to replace
        replacement - 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 replacement
        pattern - a regular expression describing the pattern to replace
        replacement - 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 replacement
        pattern - a regular expression describing the pattern to replace
        replacement - 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 string
        str - 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 value
        str - 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 value
        string - 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 string
        str - 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 value
        str - 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 value
        string - 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 string
        pattern - 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 value
        pattern - a regular expression describing the pattern to search for
        Returns:
        a function evaluating the expression