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 DecimalData |
abs(DecimalData a) |
static double |
acos(DecimalData a) |
static int |
addMonths(int date,
int m) |
static long |
addMonths(long timestamp,
int m)
TODO: remove addMonths and subtractMonths if CALCITE-3881 fixed.
|
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 String |
chr(long chr) |
static double |
cos(DecimalData a) |
static double |
cosh(DecimalData x) |
static double |
cot(DecimalData a) |
static double |
degrees(DecimalData angrad) |
static int |
divideInt(int a,
int b) |
static double |
exp(DecimalData d) |
static DecimalData |
floor(DecimalData a) |
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 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 String |
jsonValue(String jsonString,
String pathString) |
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 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 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 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 float |
struncate(float b0)
SQL
TRUNCATE operator applied to double values. |
static float |
struncate(float b0,
int b1) |
static String |
subString(String str,
long start) |
static String |
subString(String str,
long start,
long len) |
static int |
subtractMonths(int date0,
int date1) |
static int |
subtractMonths(long t0,
long t1) |
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(DecimalData a)
public static double degrees(DecimalData angrad)
public static double radians(DecimalData angdeg)
public static DecimalData abs(DecimalData a)
public static DecimalData floor(DecimalData a)
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)
text
- the input textlistDelimiter
- the delimiter to separates pairskeyValueDelimiter
- the delimiter to separates key and valuepublic 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 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 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 long addMonths(long timestamp, int m)
public static int addMonths(int date, int m)
public static int subtractMonths(int date0, int date1)
public static int subtractMonths(long t0, long t1)
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–2021 The Apache Software Foundation. All rights reserved.