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.CallGeneratorinstead 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 byteabs(byte b0)SQLABSoperator applied to byte values.static doubleabs(double b0)SQLABSoperator applied to double values.static floatabs(float b0)SQLABSoperator applied to float values.static intabs(int b0)SQLABSoperator applied to int values.static longabs(long b0)SQLABSoperator applied to long values.static shortabs(short b0)SQLABSoperator applied to short values.static org.apache.flink.table.data.DecimalDataabs(org.apache.flink.table.data.DecimalData a)static doubleacos(org.apache.flink.table.data.DecimalData a)static doubleasin(org.apache.flink.table.data.DecimalData a)static doubleatan(org.apache.flink.table.data.DecimalData a)static doubleatan2(org.apache.flink.table.data.DecimalData y, org.apache.flink.table.data.DecimalData x)static BytebitAnd(Byte a, Byte b)static IntegerbitAnd(Integer a, Integer b)static LongbitAnd(Long a, Long b)static ShortbitAnd(Short a, Short b)static BytebitNot(Byte a)static IntegerbitNot(Integer a)static LongbitNot(Long a)static ShortbitNot(Short a)static BytebitOr(Byte a, Byte b)static IntegerbitOr(Integer a, Integer b)static LongbitOr(Long a, Long b)static ShortbitOr(Short a, Short b)static BytebitXor(Byte a, Byte b)static IntegerbitXor(Integer a, Integer b)static LongbitXor(Long a, Long b)static ShortbitXor(Short a, Short b)static intbyteArrayCompare(byte[] array1, byte[] array2)Compares two byte arrays in lexicographical order.static doubleceil(double b0)static floatceil(float b0)static intceil(int b0, int b1)SQLCEILoperator applied to int values.static longceil(long b0, long b1)SQLCEILoperator applied to long values.static org.apache.flink.table.data.DecimalDataceil(org.apache.flink.table.data.DecimalData a)static Stringchr(long chr)static doublecos(org.apache.flink.table.data.DecimalData a)static doublecosh(org.apache.flink.table.data.DecimalData x)static doublecot(double b0)SQLCOToperator applied to double values.static doublecot(org.apache.flink.table.data.DecimalData a)static doubledegrees(org.apache.flink.table.data.DecimalData angrad)static intdivideInt(int a, int b)static doubleexp(org.apache.flink.table.data.DecimalData d)static doublefloor(double b0)static floatfloor(float b0)static intfloor(int b0, int b1)SQLFLOORoperator applied to int values.static longfloor(long b0, long b1)SQLFLOORoperator applied to long values.static org.apache.flink.table.data.DecimalDatafloor(org.apache.flink.table.data.DecimalData a)static org.apache.flink.table.data.binary.BinaryStringDatafromBase64(byte[] bytes)static org.apache.flink.table.data.binary.BinaryStringDatafromBase64(org.apache.flink.table.data.binary.BinaryStringData bs)static MatchergetRegexpMatcher(org.apache.flink.table.data.StringData str, org.apache.flink.table.data.StringData regex)Returns a Matcher object that represents the result of matching given StringData against a specified regular expression pattern.static Stringhash(String algorithm, String str)Calculate the hash value of a given string.static Stringhash(String algorithm, String str, String charsetName)Calculate the hash value of a given string.static IntegerhashCode(String str)static Stringhex(long x)Returns the hex string of a long argument.static Stringhex(String x)Returns the hex string of a string argument.static Stringinitcap(String s)SQL INITCAP(string) function.static intinstr(org.apache.flink.table.data.binary.BinaryStringData str, org.apache.flink.table.data.binary.BinaryStringData subString, int startPosition, int nthAppearance)static booleanisAlpha(Object obj)static booleanisDecimal(Object obj)static booleanisDigit(Object obj)static org.apache.flink.table.data.binary.BinaryStringDatakeyValue(org.apache.flink.table.data.binary.BinaryStringData str, org.apache.flink.table.data.binary.BinaryStringData pairSeparator, org.apache.flink.table.data.binary.BinaryStringData kvSeparator, org.apache.flink.table.data.binary.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 doublelog(double x)Returns the natural logarithm of "x".static doublelog(double base, double x)Returns the logarithm of "x" with base "base".static doublelog(double base, org.apache.flink.table.data.DecimalData x)static doublelog(org.apache.flink.table.data.DecimalData x)static doublelog(org.apache.flink.table.data.DecimalData base, double x)static doublelog(org.apache.flink.table.data.DecimalData base, org.apache.flink.table.data.DecimalData x)static doublelog10(double x)static doublelog10(org.apache.flink.table.data.DecimalData x)static doublelog2(double x)Returns the logarithm of "a" with base 2.static doublelog2(org.apache.flink.table.data.DecimalData x)static Stringlpad(String base, int len, String pad)Returns the string str left-padded with the string pad to a length of len characters.static Stringoverlay(String s, String r, long start)static Stringoverlay(String s, String r, long start, long length)static StringparseUrl(String urlStr, String partToExtract)Parse url and return various components of the URL.static StringparseUrl(String urlStr, String partToExtract, String key)Parse url and return various parameter of the URL.static intposition(org.apache.flink.table.data.binary.BinaryStringData seek, org.apache.flink.table.data.binary.BinaryStringData s)static intposition(org.apache.flink.table.data.binary.BinaryStringData seek, org.apache.flink.table.data.binary.BinaryStringData s, int from)static doublepower(double base, org.apache.flink.table.data.DecimalData exponent)static doublepower(org.apache.flink.table.data.DecimalData base, double exponent)static doublepower(org.apache.flink.table.data.DecimalData base, org.apache.flink.table.data.DecimalData exponent)static doubleradians(org.apache.flink.table.data.DecimalData angdeg)static BooleanregExp(String s, String regex)static StringregexpExtract(String str, String regex)Returns the first string extracted with a specified regular expression.static StringregexpExtract(String str, String regex, int extractIndex)Returns a string extracted with a specified regular expression and a regex match group index.static StringregexpExtract(String str, String regex, long extractIndex)static StringregexpReplace(String str, String regex, String replacement)Returns a string resulting from replacing all substrings that match the regular expression with replacement.static Stringrepeat(String str, int repeat)Returns a string that repeats the base string n times.static Stringreplace(String str, String oldStr, String replacement)Replaces all the old strings with the replacement string.static Stringrpad(String base, int len, String pad)Returns the string str right-padded with the string pad to a length of len characters.static org.apache.flink.table.data.DecimalDatasign(org.apache.flink.table.data.DecimalData b0)static doublesin(org.apache.flink.table.data.DecimalData a)static doublesinh(org.apache.flink.table.data.DecimalData a)static StringsplitIndex(String str, int character, int index)Split target string with custom separator and pick the index-th(start with 0) result.static StringsplitIndex(String str, String separator, int index)Split target string with custom separator and pick the index-th(start with 0) result.static bytesround(byte b0)SQLROUNDoperator applied to byte values.static bytesround(byte b0, int b1)SQLROUNDoperator applied to byte values.static doublesround(double b0)SQLROUNDoperator applied to double values.static doublesround(double b0, int b1)SQLROUNDoperator applied to double values.static floatsround(float b0)SQLROUNDoperator applied to float values.static floatsround(float b0, int b1)SQLROUNDoperator applied to float values.static intsround(int b0)SQLROUNDoperator applied to int values.static intsround(int b0, int b1)SQLROUNDoperator applied to int values.static longsround(long b0)SQLROUNDoperator applied to long values.static longsround(long b0, int b1)SQLROUNDoperator applied to long values.static shortsround(short b0)SQLROUNDoperator applied to short values.static shortsround(short b0, int b1)SQLROUNDoperator applied to short values.static BigDecimalsround(BigDecimal b0)SQLROUNDoperator applied to BigDecimal values.static BigDecimalsround(BigDecimal b0, int b1)SQLROUNDoperator applied to BigDecimal values.static org.apache.flink.table.data.DecimalDatasround(org.apache.flink.table.data.DecimalData b0)SQLROUNDoperator applied to DecimalData values.static org.apache.flink.table.data.DecimalDatasround(org.apache.flink.table.data.DecimalData b0, int b1)SQLROUNDoperator 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 doublestruncate(double b0)SQLTRUNCATEoperator applied to double values.static doublestruncate(double b0, int b1)static floatstruncate(float b0)SQLTRUNCATEoperator applied to double values.static floatstruncate(float b0, int b1)static intstruncate(int b0)SQLTRUNCATEoperator applied to int values.static intstruncate(int b0, int b1)static longstruncate(long b0)SQLTRUNCATEoperator applied to long values.static longstruncate(long b0, int b1)static org.apache.flink.table.data.DecimalDatastruncate(org.apache.flink.table.data.DecimalData b0)SQLTRUNCATEoperator applied to BigDecimal values.static org.apache.flink.table.data.DecimalDatastruncate(org.apache.flink.table.data.DecimalData b0, int b1)static StringsubString(String str, long start)static StringsubString(String str, long start, long len)static doubletan(org.apache.flink.table.data.DecimalData a)static doubletanh(org.apache.flink.table.data.DecimalData a)Calculates the hyperbolic tangent of a big decimal number.static StringtoBase64(byte[] bytes)static StringtoBase64(org.apache.flink.table.data.binary.BinaryStringData bs)static Stringuuid()static Stringuuid(byte[] b)
-
-
-
Method Detail
-
exp
public static double exp(org.apache.flink.table.data.DecimalData d)
-
power
public static double power(double base, org.apache.flink.table.data.DecimalData exponent)
-
power
public static double power(org.apache.flink.table.data.DecimalData base, org.apache.flink.table.data.DecimalData exponent)
-
power
public static double power(org.apache.flink.table.data.DecimalData base, double exponent)
-
cosh
public static double cosh(org.apache.flink.table.data.DecimalData x)
-
acos
public static double acos(org.apache.flink.table.data.DecimalData a)
-
asin
public static double asin(org.apache.flink.table.data.DecimalData a)
-
atan
public static double atan(org.apache.flink.table.data.DecimalData a)
-
atan2
public static double atan2(org.apache.flink.table.data.DecimalData y, org.apache.flink.table.data.DecimalData x)
-
sin
public static double sin(org.apache.flink.table.data.DecimalData a)
-
sinh
public static double sinh(org.apache.flink.table.data.DecimalData a)
-
cos
public static double cos(org.apache.flink.table.data.DecimalData a)
-
tan
public static double tan(org.apache.flink.table.data.DecimalData a)
-
tanh
public static double tanh(org.apache.flink.table.data.DecimalData a)
Calculates the hyperbolic tangent of a big decimal number.
-
cot
public static double cot(double b0)
SQLCOToperator applied to double values.
-
cot
public static double cot(org.apache.flink.table.data.DecimalData a)
-
degrees
public static double degrees(org.apache.flink.table.data.DecimalData angrad)
-
radians
public static double radians(org.apache.flink.table.data.DecimalData angdeg)
-
abs
public static byte abs(byte b0)
SQLABSoperator applied to byte values.
-
abs
public static short abs(short b0)
SQLABSoperator applied to short values.
-
abs
public static int abs(int b0)
SQLABSoperator applied to int values.
-
abs
public static long abs(long b0)
SQLABSoperator applied to long values.
-
abs
public static float abs(float b0)
SQLABSoperator applied to float values.
-
abs
public static double abs(double b0)
SQLABSoperator applied to double values.
-
abs
public static org.apache.flink.table.data.DecimalData abs(org.apache.flink.table.data.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)SQLFLOORoperator applied to int values.
-
floor
public static long floor(long b0, long b1)SQLFLOORoperator applied to long values.
-
floor
public static org.apache.flink.table.data.DecimalData floor(org.apache.flink.table.data.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)SQLCEILoperator applied to int values.
-
ceil
public static long ceil(long b0, long b1)SQLCEILoperator applied to long values.
-
ceil
public static org.apache.flink.table.data.DecimalData ceil(org.apache.flink.table.data.DecimalData a)
-
log
public static double log(double x)
Returns the natural logarithm of "x".
-
log
public static double log(org.apache.flink.table.data.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, org.apache.flink.table.data.DecimalData x)
-
log
public static double log(org.apache.flink.table.data.DecimalData base, double x)
-
log
public static double log(org.apache.flink.table.data.DecimalData base, org.apache.flink.table.data.DecimalData x)
-
log2
public static double log2(double x)
Returns the logarithm of "a" with base 2.
-
log2
public static double log2(org.apache.flink.table.data.DecimalData x)
-
log10
public static double log10(double x)
-
log10
public static double log10(org.apache.flink.table.data.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 org.apache.flink.table.data.StringData str, @Nullable org.apache.flink.table.data.StringData regex)
Returns a Matcher object that represents the result of matching given StringData against a specified regular expression pattern.
-
keyValue
public static org.apache.flink.table.data.binary.BinaryStringData keyValue(org.apache.flink.table.data.binary.BinaryStringData str, org.apache.flink.table.data.binary.BinaryStringData pairSeparator, org.apache.flink.table.data.binary.BinaryStringData kvSeparator, org.apache.flink.table.data.binary.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(org.apache.flink.table.data.binary.BinaryStringData seek, org.apache.flink.table.data.binary.BinaryStringData s)
-
position
public static int position(org.apache.flink.table.data.binary.BinaryStringData seek, org.apache.flink.table.data.binary.BinaryStringData s, int from)
-
instr
public static int instr(org.apache.flink.table.data.binary.BinaryStringData str, org.apache.flink.table.data.binary.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. BothlistDelimiterandkeyValueDelimiterare 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)
SQLROUNDoperator applied to byte values.
-
sround
public static byte sround(byte b0, int b1)SQLROUNDoperator applied to byte values.
-
sround
public static short sround(short b0)
SQLROUNDoperator applied to short values.
-
sround
public static short sround(short b0, int b1)SQLROUNDoperator applied to short values.
-
sround
public static int sround(int b0)
SQLROUNDoperator applied to int values.
-
sround
public static int sround(int b0, int b1)SQLROUNDoperator applied to int values.
-
sround
public static long sround(long b0)
SQLROUNDoperator applied to long values.
-
sround
public static long sround(long b0, int b1)SQLROUNDoperator applied to long values.
-
sround
public static BigDecimal sround(BigDecimal b0)
SQLROUNDoperator applied to BigDecimal values.
-
sround
public static BigDecimal sround(BigDecimal b0, int b1)
SQLROUNDoperator applied to BigDecimal values.
-
sround
public static float sround(float b0)
SQLROUNDoperator applied to float values.
-
sround
public static float sround(float b0, int b1)SQLROUNDoperator applied to float values.
-
sround
public static double sround(double b0)
SQLROUNDoperator applied to double values.
-
sround
public static double sround(double b0, int b1)SQLROUNDoperator applied to double values.
-
sround
public static org.apache.flink.table.data.DecimalData sround(org.apache.flink.table.data.DecimalData b0)
SQLROUNDoperator applied to DecimalData values.
-
sround
public static org.apache.flink.table.data.DecimalData sround(org.apache.flink.table.data.DecimalData b0, int b1)SQLROUNDoperator applied to DecimalData values.
-
sign
public static org.apache.flink.table.data.DecimalData sign(org.apache.flink.table.data.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(org.apache.flink.table.data.binary.BinaryStringData bs)
-
toBase64
public static String toBase64(byte[] bytes)
-
fromBase64
public static org.apache.flink.table.data.binary.BinaryStringData fromBase64(org.apache.flink.table.data.binary.BinaryStringData bs)
-
fromBase64
public static org.apache.flink.table.data.binary.BinaryStringData fromBase64(byte[] bytes)
-
uuid
public static String uuid()
-
uuid
public static String uuid(byte[] b)
-
struncate
public static int struncate(int b0)
SQLTRUNCATEoperator applied to int values.
-
struncate
public static int struncate(int b0, int b1)
-
struncate
public static long struncate(long b0)
SQLTRUNCATEoperator applied to long values.
-
struncate
public static long struncate(long b0, int b1)
-
struncate
public static org.apache.flink.table.data.DecimalData struncate(org.apache.flink.table.data.DecimalData b0)
SQLTRUNCATEoperator applied to BigDecimal values.
-
struncate
public static org.apache.flink.table.data.DecimalData struncate(org.apache.flink.table.data.DecimalData b0, int b1)
-
struncate
public static float struncate(float b0)
SQLTRUNCATEoperator applied to double values.
-
struncate
public static float struncate(float b0, int b1)
-
struncate
public static double struncate(double b0)
SQLTRUNCATEoperator 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
array1is great thanarray2, negative ifarray1is less thanarray2and 0 ifarray1is equal toarray2.Note: Currently, this is used in
ScalarOperatorGensfor 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
-
-