Class StringFunctions


  • public class StringFunctions
    extends Object
    Inbuilt String Transformation Functions The functions can be used as UDFs in Query when added in the FunctionRegistry.
    • Method Detail

      • lower

        public static String lower​(String input)
        Parameters:
        input -
        Returns:
        string in lower case format
      • substr

        public static String substr​(String input,
                                    int beginIndex)
        Parameters:
        input - Parent string
        beginIndex - index from which substring should be created
        Returns:
        substring from beginIndex to end of the parent string
        See Also:
        String.substring(int)
      • substr

        public static String substr​(String input,
                                    int beginIndex,
                                    int endIndex)
        Returns the substring of the main string from beginIndex to endIndex. If endIndex is -1 returns the substring from begingIndex to end of the string.
        Parameters:
        input - Parent string
        beginIndex - index from which substring should be created
        endIndex - index at which substring should be terminated
        Returns:
        substring from beginIndex to endIndex
        See Also:
        String.substring(int, int)
      • concat

        public static String concat​(String input1,
                                    String input2,
                                    String seperator)
        Join two input string with seperator in between
        Parameters:
        input1 -
        input2 -
        seperator -
        Returns:
        The two input strings joined by the seperator
      • trim

        public static String trim​(String input)
        Parameters:
        input -
        Returns:
        trim spaces from both ends of the string
        See Also:
        String.trim()
      • trim

        public static String trim​(String end,
                                  String characters,
                                  String value)
        Standard SQL trim function.
        Parameters:
        end - BOTH|LEADING|TRAILING
        characters - characters to be trimmed off
        value - value to trim
        Returns:
        trim the characters from both/leading/trailing end of the string
      • ltrim

        public static String ltrim​(String input)
        Parameters:
        input -
        Returns:
        trim spaces from left side of the string
      • rtrim

        public static String rtrim​(String input)
        Parameters:
        input -
        Returns:
        trim spaces from right side of the string
      • regexpExtract

        public static String regexpExtract​(String value,
                                           String regexp)
        Parameters:
        value -
        regexp -
        Returns:
        the matched result.
      • regexpExtract

        public static String regexpExtract​(String value,
                                           String regexp,
                                           int group)
        Parameters:
        value -
        regexp -
        group -
        Returns:
        the matched result.
      • regexpExtract

        public static String regexpExtract​(String value,
                                           String regexp,
                                           int group,
                                           String defaultValue)
        Regular expression that extract first matched substring.
        Parameters:
        value - input value
        regexp - regular expression
        group - the group number within the regular expression to extract.
        defaultValue - the default value if no match found
        Returns:
        the matched result
      • length

        public static int length​(String input)
        Parameters:
        input -
        Returns:
        length of the string
        See Also:
        String.length()
      • strpos

        public static int strpos​(String input,
                                 String find,
                                 int instance)
        Parameters:
        input -
        find - substring to find
        instance - Integer denoting the instance no.
        Returns:
        start index of the Nth instance of substring in main string
        See Also:
        Return the Nth occurence of a substring within the String
      • strpos

        public static int strpos​(String input,
                                 String find)
        Parameters:
        input -
        find - substring to find
        Returns:
        start index of the 1st instance of substring in main string
        See Also:
        Return the 1st occurence of a substring within the String
      • strrpos

        public static int strrpos​(String input,
                                  String find)
        Parameters:
        input -
        find - substring to find
        Returns:
        start index of the last instance of substring in main string
        See Also:
        Return the last occurence of a substring within the String
      • strrpos

        public static int strrpos​(String input,
                                  String find,
                                  int instance)
        Parameters:
        input -
        find - substring to find
        instance - Integer denoting the instance no.
        Returns:
        start index of the Nth instance of substring in main string starting from the end of the string.
        See Also:
        Return the Nth occurence of a substring in string starting from the end of the string.
      • startsWith

        public static boolean startsWith​(String input,
                                         String prefix)
        Parameters:
        input -
        prefix - substring to check if it is the prefix
        Returns:
        true if string starts with prefix, false o.w.
        See Also:
        String.startsWith(String)
      • rpad

        public static String rpad​(String input,
                                  int size,
                                  String pad)
        Parameters:
        input -
        size - final size of the string
        pad - pad string to be used
        Returns:
        string padded from the right side with pad to reach final size
        See Also:
        StringUtils.rightPad(String, int, char)
      • lpad

        public static String lpad​(String input,
                                  int size,
                                  String pad)
        Parameters:
        input -
        size - final size of the string
        pad - pad string to be used
        Returns:
        string padded from the left side with pad to reach final size
        See Also:
        StringUtils.leftPad(String, int, char)
      • codepoint

        public static int codepoint​(String input)
        Parameters:
        input -
        Returns:
        the Unicode codepoint of the first character of the string
        See Also:
        String.codePointAt(int)
      • chr

        public static String chr​(int codepoint)
        Parameters:
        codepoint -
        Returns:
        the character corresponding to the Unicode codepoint
        See Also:
        Character.toChars(int)
      • toUtf8

        public static byte[] toUtf8​(String input)
        Parameters:
        input -
        Returns:
        bytes
      • normalize

        public static String normalize​(String input)
        see Normalizer#normalize(String, Form)
        Parameters:
        input -
        Returns:
        transforms string with NFC normalization form.
      • normalize

        public static String normalize​(String input,
                                       String form)
        see Normalizer#normalize(String, Form)
        Parameters:
        input -
        form -
        Returns:
        transforms string with the specified normalization form
      • split

        public static String[] split​(String input,
                                     String delimiter)
        see String#split(String)
        Parameters:
        input -
        delimiter -
        Returns:
        splits string on specified delimiter and returns an array.
      • remove

        public static String remove​(String input,
                                    String search)
        see String#replaceAll(String, String)
        Parameters:
        input -
        search -
        Returns:
        removes all instances of search from string
      • hammingDistance

        public static int hammingDistance​(String input1,
                                          String input2)
        Parameters:
        input1 -
        input2 -
        Returns:
        returns the Hamming distance of input1 and input2, note that the two strings must have the same length.
      • contains

        public static boolean contains​(String input,
                                       String substring)
        see String#contains(String)
        Parameters:
        input -
        substring -
        Returns:
        returns true if substring present in main string else false.
      • strcmp

        public static int strcmp​(String input1,
                                 String input2)
        Compare input strings lexicographically.
        Returns:
        the value 0 if the first string argument is equal to second string; a value less than 0 if first string argument is lexicographically less than the second string argument; and a value greater than 0 if the first string argument is lexicographically greater than the second string argument.