Class SqlFunctionUtils
- java.lang.Object
-
- org.apache.flink.table.runtime.functions.SqlFunctionUtils
-
public class SqlFunctionUtils extends Object
Built-in scalar runtime functions.NOTE: Before you add functions here, check if Calcite provides it in
org.apache.calcite.runtime.SqlFunctions
. Furthermore, make sure to implement the function efficiently. Sometimes it makes sense to create aorg.apache.flink.table.codegen.calls.CallGenerator
instead to avoid massive object creation and reuse instances.
-
-
Constructor Summary
Constructors Constructor Description SqlFunctionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte
abs(byte b0)
SQLABS
operator applied to byte values.static double
abs(double b0)
SQLABS
operator applied to double values.static float
abs(float b0)
SQLABS
operator applied to float values.static int
abs(int b0)
SQLABS
operator applied to int values.static long
abs(long b0)
SQLABS
operator applied to long values.static short
abs(short b0)
SQLABS
operator applied to short values.static DecimalData
abs(DecimalData a)
static double
acos(DecimalData a)
static double
asin(DecimalData a)
static double
atan(DecimalData a)
static double
atan2(DecimalData y, DecimalData x)
static Byte
bitAnd(Byte a, Byte b)
static Integer
bitAnd(Integer a, Integer b)
static Long
bitAnd(Long a, Long b)
static Short
bitAnd(Short a, Short b)
static Byte
bitNot(Byte a)
static Integer
bitNot(Integer a)
static Long
bitNot(Long a)
static Short
bitNot(Short a)
static Byte
bitOr(Byte a, Byte b)
static Integer
bitOr(Integer a, Integer b)
static Long
bitOr(Long a, Long b)
static Short
bitOr(Short a, Short b)
static Byte
bitXor(Byte a, Byte b)
static Integer
bitXor(Integer a, Integer b)
static Long
bitXor(Long a, Long b)
static Short
bitXor(Short a, Short b)
static int
byteArrayCompare(byte[] array1, byte[] array2)
Compares two byte arrays in lexicographical order.static double
ceil(double b0)
static float
ceil(float b0)
static int
ceil(int b0, int b1)
SQLCEIL
operator applied to int values.static long
ceil(long b0, long b1)
SQLCEIL
operator applied to long values.static DecimalData
ceil(DecimalData a)
static String
chr(long chr)
static double
cos(DecimalData a)
static double
cosh(DecimalData x)
static double
cot(double b0)
SQLCOT
operator applied to double values.static double
cot(DecimalData a)
static double
degrees(DecimalData angrad)
static int
divideInt(int a, int b)
static double
exp(DecimalData d)
static double
floor(double b0)
static float
floor(float b0)
static int
floor(int b0, int b1)
SQLFLOOR
operator applied to int values.static long
floor(long b0, long b1)
SQLFLOOR
operator applied to long values.static DecimalData
floor(DecimalData a)
static BinaryStringData
fromBase64(byte[] bytes)
static BinaryStringData
fromBase64(BinaryStringData bs)
static Matcher
getRegexpMatcher(StringData str, StringData regex)
Returns a Matcher object that represents the result of matching given StringData against a specified regular expression pattern.static String
hash(String algorithm, String str)
Calculate the hash value of a given string.static String
hash(String algorithm, String str, String charsetName)
Calculate the hash value of a given string.static Integer
hashCode(String str)
static String
hex(long x)
Returns the hex string of a long argument.static String
hex(String x)
Returns the hex string of a string argument.static String
initcap(String s)
SQL INITCAP(string) function.static int
instr(BinaryStringData str, BinaryStringData subString, int startPosition, int nthAppearance)
static boolean
isAlpha(Object obj)
static boolean
isDecimal(Object obj)
static boolean
isDigit(Object obj)
static BinaryStringData
keyValue(BinaryStringData str, BinaryStringData pairSeparator, BinaryStringData kvSeparator, BinaryStringData keyName)
Parse string as key-value string and return the value matches key name. example: keyvalue('k1=v1;k2=v2', ';', '=', 'k2') = 'v2' keyvalue('k1:v1,k2:v2', ',', ':', 'k3') = NULLstatic double
log(double x)
Returns the natural logarithm of "x".static double
log(double base, double x)
Returns the logarithm of "x" with base "base".static double
log(double base, DecimalData x)
static double
log(DecimalData x)
static double
log(DecimalData base, double x)
static double
log(DecimalData base, DecimalData x)
static double
log10(double x)
static double
log10(DecimalData x)
static double
log2(double x)
Returns the logarithm of "a" with base 2.static double
log2(DecimalData x)
static String
lpad(String base, int len, String pad)
Returns the string str left-padded with the string pad to a length of len characters.static String
overlay(String s, String r, long start)
static String
overlay(String s, String r, long start, long length)
static String
parseUrl(String urlStr, String partToExtract)
Parse url and return various components of the URL.static String
parseUrl(String urlStr, String partToExtract, String key)
Parse url and return various parameter of the URL.static int
position(BinaryStringData seek, BinaryStringData s)
static int
position(BinaryStringData seek, BinaryStringData s, int from)
static double
power(double base, DecimalData exponent)
static double
power(DecimalData base, double exponent)
static double
power(DecimalData base, DecimalData exponent)
static double
radians(DecimalData angdeg)
static Boolean
regExp(String s, String regex)
static String
regexpExtract(String str, String regex)
Returns the first string extracted with a specified regular expression.static String
regexpExtract(String str, String regex, int extractIndex)
Returns a string extracted with a specified regular expression and a regex match group index.static String
regexpExtract(String str, String regex, long extractIndex)
static String
regexpReplace(String str, String regex, String replacement)
Returns a string resulting from replacing all substrings that match the regular expression with replacement.static String
repeat(String str, int repeat)
Returns a string that repeats the base string n times.static String
replace(String str, String oldStr, String replacement)
Replaces all the old strings with the replacement string.static String
rpad(String base, int len, String pad)
Returns the string str right-padded with the string pad to a length of len characters.static DecimalData
sign(DecimalData b0)
static double
sin(DecimalData a)
static double
sinh(DecimalData a)
static String
splitIndex(String str, int character, int index)
Split target string with custom separator and pick the index-th(start with 0) result.static String
splitIndex(String str, String separator, int index)
Split target string with custom separator and pick the index-th(start with 0) result.static byte
sround(byte b0)
SQLROUND
operator applied to byte values.static byte
sround(byte b0, int b1)
SQLROUND
operator applied to byte values.static double
sround(double b0)
SQLROUND
operator applied to double values.static double
sround(double b0, int b1)
SQLROUND
operator applied to double values.static float
sround(float b0)
SQLROUND
operator applied to float values.static float
sround(float b0, int b1)
SQLROUND
operator applied to float values.static int
sround(int b0)
SQLROUND
operator applied to int values.static int
sround(int b0, int b1)
SQLROUND
operator applied to int values.static long
sround(long b0)
SQLROUND
operator applied to long values.static long
sround(long b0, int b1)
SQLROUND
operator applied to long values.static short
sround(short b0)
SQLROUND
operator applied to short values.static short
sround(short b0, int b1)
SQLROUND
operator applied to short values.static BigDecimal
sround(BigDecimal b0)
SQLROUND
operator applied to BigDecimal values.static BigDecimal
sround(BigDecimal b0, int b1)
SQLROUND
operator applied to BigDecimal values.static DecimalData
sround(DecimalData b0)
SQLROUND
operator applied to DecimalData values.static DecimalData
sround(DecimalData b0, int b1)
SQLROUND
operator applied to DecimalData values.static Map<String,String>
strToMap(String text)
Creates a map by parsing text.static Map<String,String>
strToMap(String text, String listDelimiter, String keyValueDelimiter)
Creates a map by parsing text.static double
struncate(double b0)
SQLTRUNCATE
operator applied to double values.static double
struncate(double b0, int b1)
static float
struncate(float b0)
SQLTRUNCATE
operator applied to double values.static float
struncate(float b0, int b1)
static int
struncate(int b0)
SQLTRUNCATE
operator applied to int values.static int
struncate(int b0, int b1)
static long
struncate(long b0)
SQLTRUNCATE
operator applied to long values.static long
struncate(long b0, int b1)
static DecimalData
struncate(DecimalData b0)
SQLTRUNCATE
operator applied to BigDecimal values.static DecimalData
struncate(DecimalData b0, int b1)
static String
subString(String str, long start)
static String
subString(String str, long start, long len)
static double
tan(DecimalData a)
static double
tanh(DecimalData a)
Calculates the hyperbolic tangent of a big decimal number.static String
toBase64(byte[] bytes)
static String
toBase64(BinaryStringData bs)
static String
uuid()
static String
uuid(byte[] b)
-
-
-
Method Detail
-
exp
public static double exp(DecimalData d)
-
power
public static double power(double base, DecimalData exponent)
-
power
public static double power(DecimalData base, DecimalData exponent)
-
power
public static double power(DecimalData base, double exponent)
-
cosh
public static double cosh(DecimalData x)
-
acos
public static double acos(DecimalData a)
-
asin
public static double asin(DecimalData a)
-
atan
public static double atan(DecimalData a)
-
atan2
public static double atan2(DecimalData y, DecimalData x)
-
sin
public static double sin(DecimalData a)
-
sinh
public static double sinh(DecimalData a)
-
cos
public static double cos(DecimalData a)
-
tan
public static double tan(DecimalData a)
-
tanh
public static double tanh(DecimalData a)
Calculates the hyperbolic tangent of a big decimal number.
-
cot
public static double cot(double b0)
SQLCOT
operator applied to double values.
-
cot
public static double cot(DecimalData a)
-
degrees
public static double degrees(DecimalData angrad)
-
radians
public static double radians(DecimalData angdeg)
-
abs
public static byte abs(byte b0)
SQLABS
operator applied to byte values.
-
abs
public static short abs(short b0)
SQLABS
operator applied to short values.
-
abs
public static int abs(int b0)
SQLABS
operator applied to int values.
-
abs
public static long abs(long b0)
SQLABS
operator applied to long values.
-
abs
public static float abs(float b0)
SQLABS
operator applied to float values.
-
abs
public static double abs(double b0)
SQLABS
operator applied to double values.
-
abs
public static DecimalData abs(DecimalData a)
-
floor
public static double floor(double b0)
-
floor
public static float floor(float b0)
-
floor
public static int floor(int b0, int b1)
SQLFLOOR
operator applied to int values.
-
floor
public static long floor(long b0, long b1)
SQLFLOOR
operator applied to long values.
-
floor
public static DecimalData floor(DecimalData a)
-
ceil
public static double ceil(double b0)
-
ceil
public static float ceil(float b0)
-
ceil
public static int ceil(int b0, int b1)
SQLCEIL
operator applied to int values.
-
ceil
public static long ceil(long b0, long b1)
SQLCEIL
operator applied to long values.
-
ceil
public static DecimalData ceil(DecimalData a)
-
log
public static double log(double x)
Returns the natural logarithm of "x".
-
log
public static double log(DecimalData x)
-
log
public static double log(double base, double x)
Returns the logarithm of "x" with base "base".
-
log
public static double log(double base, DecimalData x)
-
log
public static double log(DecimalData base, double x)
-
log
public static double log(DecimalData base, DecimalData x)
-
log2
public static double log2(double x)
Returns the logarithm of "a" with base 2.
-
log2
public static double log2(DecimalData x)
-
log10
public static double log10(double x)
-
log10
public static double log10(DecimalData x)
-
lpad
public static String lpad(String base, int len, String pad)
Returns the string str left-padded with the string pad to a length of len characters. If str is longer than len, the return value is shortened to len characters.
-
rpad
public static String rpad(String base, int len, String pad)
Returns the string str right-padded with the string pad to a length of len characters. If str is longer than len, the return value is shortened to len characters.
-
repeat
public static String repeat(String str, int repeat)
Returns a string that repeats the base string n times.
-
replace
public static String replace(String str, String oldStr, String replacement)
Replaces all the old strings with the replacement string.
-
splitIndex
public static String splitIndex(String str, String separator, int index)
Split target string with custom separator and pick the index-th(start with 0) result.- Parameters:
str
- target string.separator
- custom separator.index
- index of the result which you want.- Returns:
- the string at the index of split results.
-
splitIndex
public static String splitIndex(String str, int character, int index)
Split target string with custom separator and pick the index-th(start with 0) result.- Parameters:
str
- target string.character
- int value of the separator characterindex
- index of the result which you want.- Returns:
- the string at the index of split results.
-
regexpReplace
public static String regexpReplace(String str, String regex, String replacement)
Returns a string resulting from replacing all substrings that match the regular expression with replacement.
-
regexpExtract
public static String regexpExtract(String str, String regex, int extractIndex)
Returns a string extracted with a specified regular expression and a regex match group index.
-
regexpExtract
public static String regexpExtract(String str, String regex)
Returns the first string extracted with a specified regular expression.
-
getRegexpMatcher
public static Matcher getRegexpMatcher(@Nullable StringData str, @Nullable StringData regex)
Returns a Matcher object that represents the result of matching given StringData against a specified regular expression pattern.
-
keyValue
public static BinaryStringData keyValue(BinaryStringData str, BinaryStringData pairSeparator, BinaryStringData kvSeparator, BinaryStringData keyName)
Parse string as key-value string and return the value matches key name. example: keyvalue('k1=v1;k2=v2', ';', '=', 'k2') = 'v2' keyvalue('k1:v1,k2:v2', ',', ':', 'k3') = NULL- Parameters:
str
- target string.pairSeparator
- separator between key-value tuple.kvSeparator
- separator between key and value.keyName
- name of the key whose value you want return.- Returns:
- target value.
-
hash
public static String hash(String algorithm, String str)
Calculate the hash value of a given string.- Parameters:
algorithm
- message digest algorithm.str
- string to hash.- Returns:
- hash value of string.
-
hash
public static String hash(String algorithm, String str, String charsetName)
Calculate the hash value of a given string.- Parameters:
algorithm
- message digest algorithm.str
- string to hash.charsetName
- charset of string.- Returns:
- hash value of string.
-
parseUrl
public static String parseUrl(String urlStr, String partToExtract)
Parse url and return various components of the URL. If accept any null arguments, return null.- Parameters:
urlStr
- URL string.partToExtract
- determines which components would return. accept values: HOST,PATH,QUERY,REF, PROTOCOL,FILE,AUTHORITY,USERINFO- Returns:
- target value.
-
parseUrl
public static String parseUrl(String urlStr, String partToExtract, String key)
Parse url and return various parameter of the URL. If accept any null arguments, return null.- Parameters:
urlStr
- URL string.partToExtract
- must be QUERY, or return null.key
- parameter name.- Returns:
- target value.
-
divideInt
public static int divideInt(int a, int b)
-
chr
public static String chr(long chr)
-
position
public static int position(BinaryStringData seek, BinaryStringData s)
-
position
public static int position(BinaryStringData seek, BinaryStringData s, int from)
-
instr
public static int instr(BinaryStringData str, BinaryStringData subString, int startPosition, int nthAppearance)
-
hex
public static String hex(long x)
Returns the hex string of a long argument.
-
strToMap
public static Map<String,String> strToMap(String text)
Creates a map by parsing text. Split text into key-value pairs using two delimiters. The first delimiter separates pairs, and the second delimiter separates key and value. If only one parameter is given, default delimiters are used: ',' as delimiter1 and '=' as delimiter2. Both delimiters are treated as regular expressions.- Parameters:
text
- the input text- Returns:
- the map
-
strToMap
public static Map<String,String> strToMap(String text, String listDelimiter, String keyValueDelimiter)
Creates a map by parsing text. Split text into key-value pairs using two delimiters. The first delimiter separates pairs, and the second delimiter separates key and value. BothlistDelimiter
andkeyValueDelimiter
are treated as regular expressions.- Parameters:
text
- the input textlistDelimiter
- the delimiter to separates pairskeyValueDelimiter
- the delimiter to separates key and value- Returns:
- the map
-
sround
public static byte sround(byte b0)
SQLROUND
operator applied to byte values.
-
sround
public static byte sround(byte b0, int b1)
SQLROUND
operator applied to byte values.
-
sround
public static short sround(short b0)
SQLROUND
operator applied to short values.
-
sround
public static short sround(short b0, int b1)
SQLROUND
operator applied to short values.
-
sround
public static int sround(int b0)
SQLROUND
operator applied to int values.
-
sround
public static int sround(int b0, int b1)
SQLROUND
operator applied to int values.
-
sround
public static long sround(long b0)
SQLROUND
operator applied to long values.
-
sround
public static long sround(long b0, int b1)
SQLROUND
operator applied to long values.
-
sround
public static BigDecimal sround(BigDecimal b0)
SQLROUND
operator applied to BigDecimal values.
-
sround
public static BigDecimal sround(BigDecimal b0, int b1)
SQLROUND
operator applied to BigDecimal values.
-
sround
public static float sround(float b0)
SQLROUND
operator applied to float values.
-
sround
public static float sround(float b0, int b1)
SQLROUND
operator applied to float values.
-
sround
public static double sround(double b0)
SQLROUND
operator applied to double values.
-
sround
public static double sround(double b0, int b1)
SQLROUND
operator applied to double values.
-
sround
public static DecimalData sround(DecimalData b0)
SQLROUND
operator applied to DecimalData values.
-
sround
public static DecimalData sround(DecimalData b0, int b1)
SQLROUND
operator applied to DecimalData values.
-
sign
public static DecimalData sign(DecimalData b0)
-
isDecimal
public static boolean isDecimal(Object obj)
-
isDigit
public static boolean isDigit(Object obj)
-
isAlpha
public static boolean isAlpha(Object obj)
-
toBase64
public static String toBase64(BinaryStringData bs)
-
toBase64
public static String toBase64(byte[] bytes)
-
fromBase64
public static BinaryStringData fromBase64(BinaryStringData bs)
-
fromBase64
public static BinaryStringData fromBase64(byte[] bytes)
-
uuid
public static String uuid()
-
uuid
public static String uuid(byte[] b)
-
struncate
public static int struncate(int b0)
SQLTRUNCATE
operator applied to int values.
-
struncate
public static int struncate(int b0, int b1)
-
struncate
public static long struncate(long b0)
SQLTRUNCATE
operator applied to long values.
-
struncate
public static long struncate(long b0, int b1)
-
struncate
public static DecimalData struncate(DecimalData b0)
SQLTRUNCATE
operator applied to BigDecimal values.
-
struncate
public static DecimalData struncate(DecimalData b0, int b1)
-
struncate
public static float struncate(float b0)
SQLTRUNCATE
operator applied to double values.
-
struncate
public static float struncate(float b0, int b1)
-
struncate
public static double struncate(double b0)
SQLTRUNCATE
operator applied to double values.
-
struncate
public static double struncate(double b0, int b1)
-
byteArrayCompare
public static int byteArrayCompare(byte[] array1, byte[] array2)
Compares two byte arrays in lexicographical order.The result is positive if
array1
is great thanarray2
, negative ifarray1
is less thanarray2
and 0 ifarray1
is equal toarray2
.Note: Currently, this is used in
ScalarOperatorGens
for comparing two fields of binary or varbinary type.- Parameters:
array1
- byte array to compare.array2
- byte array to compare.- Returns:
- an Integer indicating which one is bigger
-
-