public class SqlFunctionUtils extends Object
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 a org.apache.flink.table.codegen.calls.CallGenerator
instead to avoid massive object creation and
reuse instances.
Constructor and Description |
---|
SqlFunctionUtils() |
Modifier and Type | Method and Description |
---|---|
static byte |
abs(byte b0)
SQL
ABS operator applied to byte values. |
static DecimalData |
abs(DecimalData a) |
static double |
abs(double b0)
SQL
ABS operator applied to double values. |
static float |
abs(float b0)
SQL
ABS operator applied to float values. |
static int |
abs(int b0)
SQL
ABS operator applied to int values. |
static long |
abs(long b0)
SQL
ABS operator applied to long values. |
static short |
abs(short b0)
SQL
ABS operator applied to short values. |
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 DecimalData |
ceil(DecimalData a) |
static double |
ceil(double b0) |
static float |
ceil(float b0) |
static int |
ceil(int b0,
int b1)
SQL
CEIL operator applied to int values. |
static long |
ceil(long b0,
long b1)
SQL
CEIL operator applied to long values. |
static String |
chr(long chr) |
static double |
cos(DecimalData a) |
static double |
cosh(DecimalData x) |
static double |
cot(DecimalData a) |
static double |
cot(double b0)
SQL
COT operator applied to double values. |
static double |
degrees(DecimalData angrad) |
static int |
divideInt(int a,
int b) |
static double |
exp(DecimalData d) |
static DecimalData |
floor(DecimalData a) |
static double |
floor(double b0) |
static float |
floor(float b0) |
static int |
floor(int b0,
int b1)
SQL
FLOOR operator applied to int values. |
static long |
floor(long b0,
long b1)
SQL
FLOOR operator applied to long values. |
static BinaryStringData |
fromBase64(BinaryStringData bs) |
static BinaryStringData |
fromBase64(byte[] bytes) |
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.
|
static double |
log(DecimalData x) |
static double |
log(DecimalData base,
DecimalData x) |
static double |
log(DecimalData base,
double x) |
static double |
log(double x)
Returns the natural logarithm of "x".
|
static double |
log(double base,
DecimalData x) |
static double |
log(double base,
double x)
Returns the logarithm of "x" with base "base".
|
static double |
log10(DecimalData x) |
static double |
log10(double x) |
static double |
log2(DecimalData x) |
static double |
log2(double x)
Returns the logarithm of "a" with base 2.
|
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(DecimalData base,
DecimalData exponent) |
static double |
power(DecimalData base,
double exponent) |
static double |
power(double 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 BigDecimal |
sround(BigDecimal b0)
SQL
ROUND operator applied to BigDecimal values. |
static BigDecimal |
sround(BigDecimal b0,
int b1)
SQL
ROUND operator applied to BigDecimal values. |
static byte |
sround(byte b0)
SQL
ROUND operator applied to byte values. |
static byte |
sround(byte b0,
int b1)
SQL
ROUND operator applied to byte values. |
static DecimalData |
sround(DecimalData b0)
SQL
ROUND operator applied to DecimalData values. |
static DecimalData |
sround(DecimalData b0,
int b1)
SQL
ROUND operator applied to DecimalData values. |
static double |
sround(double b0)
SQL
ROUND operator applied to double values. |
static double |
sround(double b0,
int b1)
SQL
ROUND operator applied to double values. |
static float |
sround(float b0)
SQL
ROUND operator applied to float values. |
static float |
sround(float b0,
int b1)
SQL
ROUND operator applied to float values. |
static int |
sround(int b0)
SQL
ROUND operator applied to int values. |
static int |
sround(int b0,
int b1)
SQL
ROUND operator applied to int values. |
static long |
sround(long b0)
SQL
ROUND operator applied to long values. |
static long |
sround(long b0,
int b1)
SQL
ROUND operator applied to long values. |
static short |
sround(short b0)
SQL
ROUND operator applied to short values. |
static short |
sround(short b0,
int b1)
SQL
ROUND operator applied to short 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 DecimalData |
struncate(DecimalData b0)
SQL
TRUNCATE operator applied to BigDecimal values. |
static DecimalData |
struncate(DecimalData b0,
int b1) |
static double |
struncate(double b0)
SQL
TRUNCATE operator applied to double values. |
static double |
struncate(double b0,
int b1) |
static float |
struncate(float b0)
SQL
TRUNCATE operator applied to double values. |
static float |
struncate(float b0,
int b1) |
static int |
struncate(int b0)
SQL
TRUNCATE operator applied to int values. |
static int |
struncate(int b0,
int b1) |
static long |
struncate(long b0)
SQL
TRUNCATE operator applied to long values. |
static long |
struncate(long 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(BinaryStringData bs) |
static String |
toBase64(byte[] bytes) |
static String |
uuid() |
static String |
uuid(byte[] b) |
public static double exp(DecimalData d)
public static double power(double base, DecimalData exponent)
public static double power(DecimalData base, DecimalData exponent)
public static double power(DecimalData base, double exponent)
public static double cosh(DecimalData x)
public static double acos(DecimalData a)
public static double asin(DecimalData a)
public static double atan(DecimalData a)
public static double atan2(DecimalData y, DecimalData x)
public static double sin(DecimalData a)
public static double sinh(DecimalData a)
public static double cos(DecimalData a)
public static double tan(DecimalData a)
public static double tanh(DecimalData a)
public static double cot(double b0)
COT
operator applied to double values.public static double cot(DecimalData a)
public static double degrees(DecimalData angrad)
public static double radians(DecimalData angdeg)
public static byte abs(byte b0)
ABS
operator applied to byte values.public static short abs(short b0)
ABS
operator applied to short values.public static int abs(int b0)
ABS
operator applied to int values.public static long abs(long b0)
ABS
operator applied to long values.public static float abs(float b0)
ABS
operator applied to float values.public static double abs(double b0)
ABS
operator applied to double values.public static DecimalData abs(DecimalData a)
public static double floor(double b0)
public static float floor(float b0)
public static int floor(int b0, int b1)
FLOOR
operator applied to int values.public static long floor(long b0, long b1)
FLOOR
operator applied to long values.public static DecimalData floor(DecimalData a)
public static double ceil(double b0)
public static float ceil(float b0)
public static int ceil(int b0, int b1)
CEIL
operator applied to int values.public static long ceil(long b0, long b1)
CEIL
operator applied to long values.public static DecimalData ceil(DecimalData a)
public static double log(double x)
public static double log(DecimalData x)
public static double log(double base, double x)
public static double log(double base, DecimalData x)
public static double log(DecimalData base, double x)
public static double log(DecimalData base, DecimalData x)
public static double log2(double x)
public static double log2(DecimalData x)
public static double log10(double x)
public static double log10(DecimalData x)
public static String lpad(String base, int len, String pad)
public static String rpad(String base, int len, String pad)
public static String repeat(String str, int repeat)
public static String replace(String str, String oldStr, String replacement)
public static String splitIndex(String str, String separator, int index)
str
- target string.separator
- custom separator.index
- index of the result which you want.public static String splitIndex(String str, int character, int index)
str
- target string.character
- int value of the separator characterindex
- index of the result which you want.public static String regexpReplace(String str, String regex, String replacement)
public static String regexpExtract(String str, String regex, int extractIndex)
public static String regexpExtract(String str, String regex)
public static BinaryStringData keyValue(BinaryStringData str, BinaryStringData pairSeparator, BinaryStringData kvSeparator, BinaryStringData keyName)
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.public static String hash(String algorithm, String str)
algorithm
- message digest algorithm.str
- string to hash.public static String hash(String algorithm, String str, String charsetName)
algorithm
- message digest algorithm.str
- string to hash.charsetName
- charset of string.public static String parseUrl(String urlStr, String partToExtract)
urlStr
- URL string.partToExtract
- determines which components would return. accept values:
HOST,PATH,QUERY,REF, PROTOCOL,FILE,AUTHORITY,USERINFOpublic static String parseUrl(String urlStr, String partToExtract, String key)
urlStr
- URL string.partToExtract
- must be QUERY, or return null.key
- parameter name.public static int divideInt(int a, int b)
public static String chr(long chr)
public static int position(BinaryStringData seek, BinaryStringData s)
public static int position(BinaryStringData seek, BinaryStringData s, int from)
public static int instr(BinaryStringData str, BinaryStringData subString, int startPosition, int nthAppearance)
public static String hex(long x)
public static Map<String,String> strToMap(String text)
text
- the input textpublic static Map<String,String> strToMap(String text, String listDelimiter, String keyValueDelimiter)
listDelimiter
and keyValueDelimiter
are treated as regular expressions.text
- the input textlistDelimiter
- the delimiter to separates pairskeyValueDelimiter
- the delimiter to separates key and valuepublic static byte sround(byte b0)
ROUND
operator applied to byte values.public static byte sround(byte b0, int b1)
ROUND
operator applied to byte values.public static short sround(short b0)
ROUND
operator applied to short values.public static short sround(short b0, int b1)
ROUND
operator applied to short values.public static int sround(int b0)
ROUND
operator applied to int values.public static int sround(int b0, int b1)
ROUND
operator applied to int values.public static long sround(long b0)
ROUND
operator applied to long values.public static long sround(long b0, int b1)
ROUND
operator applied to long values.public static BigDecimal sround(BigDecimal b0)
ROUND
operator applied to BigDecimal values.public static BigDecimal sround(BigDecimal b0, int b1)
ROUND
operator applied to BigDecimal values.public static float sround(float b0)
ROUND
operator applied to float values.public static float sround(float b0, int b1)
ROUND
operator applied to float values.public static double sround(double b0)
ROUND
operator applied to double values.public static double sround(double b0, int b1)
ROUND
operator applied to double values.public static DecimalData sround(DecimalData b0)
ROUND
operator applied to DecimalData values.public static DecimalData sround(DecimalData b0, int b1)
ROUND
operator applied to DecimalData values.public static DecimalData sign(DecimalData b0)
public static boolean isDecimal(Object obj)
public static boolean isDigit(Object obj)
public static boolean isAlpha(Object obj)
public static String toBase64(BinaryStringData bs)
public static String toBase64(byte[] bytes)
public static BinaryStringData fromBase64(BinaryStringData bs)
public static BinaryStringData fromBase64(byte[] bytes)
public static String uuid()
public static String uuid(byte[] b)
public static int struncate(int b0)
TRUNCATE
operator applied to int values.public static int struncate(int b0, int b1)
public static long struncate(long b0)
TRUNCATE
operator applied to long values.public static long struncate(long b0, int b1)
public static DecimalData struncate(DecimalData b0)
TRUNCATE
operator applied to BigDecimal values.public static DecimalData struncate(DecimalData b0, int b1)
public static float struncate(float b0)
TRUNCATE
operator applied to double values.public static float struncate(float b0, int b1)
public static double struncate(double b0)
TRUNCATE
operator applied to double values.public static double struncate(double b0, int b1)
public static int byteArrayCompare(byte[] array1, byte[] array2)
The result is positive if array1
is great than array2
, negative if array1
is less than array2
and 0 if array1
is equal to array2
.
Note: Currently, this is used in ScalarOperatorGens
for comparing two fields of
binary or varbinary type.
array1
- byte array to compare.array2
- byte array to compare.Copyright © 2014–2023 The Apache Software Foundation. All rights reserved.