Class StringFunctions
- java.lang.Object
-
- org.apache.pinot.common.function.scalar.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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringchr(int codepoint)static intcodepoint(String input)static Stringconcat(String input1, String input2, String seperator)Join two input string with seperator in betweenstatic booleancontains(String input, String substring)see String#contains(String)static inthammingDistance(String input1, String input2)static intlength(String input)static Stringlower(String input)static Stringlpad(String input, int size, String pad)static Stringltrim(String input)static Stringnormalize(String input)see Normalizer#normalize(String, Form)static Stringnormalize(String input, String form)see Normalizer#normalize(String, Form)static StringregexpExtract(String value, String regexp)static StringregexpExtract(String value, String regexp, int group)static StringregexpExtract(String value, String regexp, int group, String defaultValue)Regular expression that extract first matched substring.static Stringremove(String input, String search)see String#replaceAll(String, String)static Stringreplace(String input, String find, String substitute)static Stringreverse(String input)static Stringrpad(String input, int size, String pad)static Stringrtrim(String input)static String[]split(String input, String delimiter)see String#split(String)static booleanstartsWith(String input, String prefix)static intstrcmp(String input1, String input2)Compare input strings lexicographically.static intstrpos(String input, String find)static intstrpos(String input, String find, int instance)static intstrrpos(String input, String find)static intstrrpos(String input, String find, int instance)static Stringsubstr(String input, int beginIndex)static Stringsubstr(String input, int beginIndex, int endIndex)Returns the substring of the main string from beginIndex to endIndex.static byte[]toUtf8(String input)static Stringtrim(String input)static Stringtrim(String end, String characters, String value)Standard SQL trim function.static Stringupper(String input)
-
-
-
Method Detail
-
reverse
public static String reverse(String input)
- Parameters:
input-- Returns:
- reversed input in from end to start
- See Also:
StringBuilder.reverse()
-
lower
public static String lower(String input)
- Parameters:
input-- Returns:
- string in lower case format
-
upper
public static String upper(String input)
- Parameters:
input-- Returns:
- string in upper case format
- See Also:
String.toUpperCase()
-
substr
public static String substr(String input, int beginIndex)
- Parameters:
input- Parent stringbeginIndex- 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 stringbeginIndex- index from which substring should be createdendIndex- 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|TRAILINGcharacters- characters to be trimmed offvalue- 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 valueregexp- regular expressiongroup- 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 findinstance- 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 findinstance- 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)
-
replace
public static String replace(String input, String find, String substitute)
- Parameters:
input-find- target substring to replacesubstitute- new substring to be replaced with target- See Also:
String.replaceAll(String, String)
-
rpad
public static String rpad(String input, int size, String pad)
- Parameters:
input-size- final size of the stringpad- 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 stringpad- 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.
-
-