InType
- The accepted type of input expressions, it is Expression
for Scala and
Object
for Java. Generally the expression DSL works on expressions, the reason why
Java accepts Object is to remove cumbersome call to lit()
for literals. Scala
alleviates this problem via implicit conversions.OutType
- The produced type of the DSL. It is ApiExpression
for Java and Expression
for Scala. In Scala the infix operations are included via implicit conversions.
In Java we introduced a wrapper that enables the operations without pulling them through the
whole stack.@PublicEvolving public abstract class BaseExpressions<InType,OutType> extends Object
Expression
AST for expression operations.Constructor and Description |
---|
BaseExpressions() |
Modifier and Type | Method and Description |
---|---|
OutType |
abs()
Calculates the absolute value of given value.
|
OutType |
acos()
Calculates the arc cosine of a given number.
|
OutType |
and(InType other)
Boolean AND in three-valued logic.
|
OutType |
as(String name,
String... extraNames)
Specifies a name for an expression i.e.
|
OutType |
asc()
Specifies ascending order of an expression i.e.
|
OutType |
asin()
Calculates the arc sine of a given number.
|
OutType |
at(InType index)
Accesses the element of an array or map based on a key or an index (starting at 1).
|
OutType |
atan()
Calculates the arc tangent of a given number.
|
OutType |
avg()
Returns the average (arithmetic mean) of the numeric field across all input values.
|
OutType |
between(InType lowerBound,
InType upperBound)
Returns true if the given expression is between lowerBound and upperBound (both inclusive).
|
OutType |
bin()
Returns a string representation of an integer numeric value in binary format.
|
OutType |
cardinality()
Returns the number of elements of an array or number of entries of a map.
|
OutType |
cast(DataType toType)
Converts a value to a given data type.
|
OutType |
cast(TypeInformation<?> toType)
Deprecated.
This method will be removed in future versions as it uses the old type system. It
is recommended to use
cast(DataType) instead which uses the new type system
based on DataTypes . Please make sure to use either the
old or the new type system consistently to avoid unintended behavior. See the website
documentation for more information. |
OutType |
ceil()
Calculates the smallest integer greater than or equal to a given number.
|
OutType |
ceil(TimeIntervalUnit timeIntervalUnit)
Rounds up a time point to the given unit.
|
OutType |
charLength()
Returns the length of a string.
|
OutType |
collect()
Returns multiset aggregate of a given expression.
|
OutType |
cos()
Calculates the cosine of a given number.
|
OutType |
cosh()
Calculates the hyperbolic cosine of a given value.
|
OutType |
cot()
Calculates the cotangent of a given number.
|
OutType |
count()
Returns the number of input rows for which the field is not null.
|
OutType |
day()
Creates an interval of the given number of days.
|
OutType |
days()
Creates an interval of the given number of days.
|
OutType |
degrees()
Converts numeric from radians to degrees.
|
OutType |
desc()
Specifies descending order of an expression i.e.
|
OutType |
distinct()
Similar to a SQL distinct aggregation clause such as COUNT(DISTINCT a), declares that an
aggregation function is only applied on distinct input values.
|
OutType |
dividedBy(InType other)
Returns left divided by right.
|
OutType |
element()
Returns the sole element of an array with a single element.
|
OutType |
end()
Returns the end time (exclusive) of a window when applied on a window reference.
|
OutType |
exp()
Calculates the Euler's number raised to the given power.
|
OutType |
extract(TimeIntervalUnit timeIntervalUnit)
Extracts parts of a time point or time interval.
|
OutType |
flatten()
Converts a Flink composite type (such as Tuple, POJO, etc.) and all of its direct subtypes
into a flat representation where every subtype is a separate field.
|
OutType |
floor()
Calculates the largest integer less than or equal to a given number.
|
OutType |
floor(TimeIntervalUnit timeIntervalUnit)
Rounds down a time point to the given unit.
|
OutType |
fromBase64()
Returns the base string decoded with base64.
|
OutType |
get(int index)
Accesses the field of a Flink composite type (such as Tuple, POJO, etc.) by index and returns
it's value.
|
OutType |
get(String name)
Accesses the field of a Flink composite type (such as Tuple, POJO, etc.) by name and returns
it's value.
|
OutType |
hex()
Returns a string representation of an integer numeric value or a string in hex format.
|
OutType |
hour()
Creates an interval of the given number of hours.
|
OutType |
hours()
Creates an interval of the given number of hours.
|
OutType |
in(InType... elements)
Returns true if an expression exists in a given list of expressions.
|
OutType |
in(Table table)
Returns true if an expression exists in a given table sub-query.
|
OutType |
initCap()
Converts the initial letter of each word in a string to uppercase.
|
OutType |
isEqual(InType other)
Equals.
|
OutType |
isFalse()
Returns true if given boolean expression is false.
|
OutType |
isGreater(InType other)
Greater than.
|
OutType |
isGreaterOrEqual(InType other)
Greater than or equal.
|
OutType |
isLess(InType other)
Less than.
|
OutType |
isLessOrEqual(InType other)
Less than or equal.
|
OutType |
isNotEqual(InType other)
Not equal.
|
OutType |
isNotFalse()
Returns true if given boolean expression is not false (for null and true).
|
OutType |
isNotNull()
Returns true if the given expression is not null.
|
OutType |
isNotTrue()
Returns true if given boolean expression is not true (for null and false).
|
OutType |
isNull()
Returns true if the given expression is null.
|
OutType |
isTrue()
Returns true if given boolean expression is true.
|
OutType |
like(InType pattern)
Returns true, if a string matches the specified LIKE pattern.
|
OutType |
ln()
Calculates the natural logarithm of the given value.
|
OutType |
log()
Calculates the natural logarithm of the given value.
|
OutType |
log(InType base)
Calculates the logarithm of the given value to the given base.
|
OutType |
log10()
Calculates the base 10 logarithm of the given value.
|
OutType |
log2()
Calculates the base 2 logarithm of the given value.
|
OutType |
lowerCase()
Returns all of the characters in a string in lower case using the rules of the default
locale.
|
OutType |
lpad(InType len,
InType pad)
Returns a string left-padded with the given pad string to a length of len characters.
|
OutType |
ltrim()
Returns a string that removes the left whitespaces from the given string.
|
OutType |
max()
Returns the maximum value of field across all input values.
|
OutType |
md5()
Returns the MD5 hash of the string argument; null if string is null.
|
OutType |
milli()
Creates an interval of the given number of milliseconds.
|
OutType |
millis()
Creates an interval of the given number of milliseconds.
|
OutType |
min()
Returns the minimum value of field across all input values.
|
OutType |
minus(InType other)
Returns left minus right.
|
OutType |
minute()
Creates an interval of the given number of minutes.
|
OutType |
minutes()
Creates an interval of the given number of minutes.
|
OutType |
mod(InType other)
Calculates the remainder of division the given number by another one.
|
OutType |
month()
Creates an interval of the given number of months.
|
OutType |
months()
Creates an interval of the given number of months.
|
OutType |
notBetween(InType lowerBound,
InType upperBound)
Returns true if the given expression is not between lowerBound and upperBound (both
inclusive).
|
OutType |
or(InType other)
Boolean OR in three-valued logic.
|
OutType |
over(InType alias)
Defines an aggregation to be used for a previously specified over window.
|
OutType |
overlay(InType newString,
InType starting)
Replaces a substring of string with a string starting at a position (starting at 1).
|
OutType |
overlay(InType newString,
InType starting,
InType length)
Replaces a substring of string with a string starting at a position (starting at 1).
|
OutType |
plus(InType other)
Returns left plus right.
|
OutType |
position(InType haystack)
Returns the position of string in an other string starting at 1.
|
OutType |
power(InType other)
Calculates the given number raised to the power of the other value.
|
OutType |
proctime()
Declares a field as the proctime attribute for indicating, accessing, and working in Flink's
processing time.
|
OutType |
quarter()
Creates an interval of the given number of quarters.
|
OutType |
quarters()
Creates an interval of the given number of quarters.
|
OutType |
radians()
Converts numeric from degrees to radians.
|
OutType |
regexpExtract(InType regex)
Returns a string extracted with a specified regular expression.
|
OutType |
regexpExtract(InType regex,
InType extractIndex)
Returns a string extracted with a specified regular expression and a regex match group index.
|
OutType |
regexpReplace(InType regex,
InType replacement)
Returns a string with all substrings that match the regular expression consecutively being
replaced.
|
OutType |
repeat(InType n)
Returns a string that repeats the base string n times.
|
OutType |
replace(InType search,
InType replacement)
Returns a new string which replaces all the occurrences of the search target with the
replacement string (non-overlapping).
|
OutType |
round(InType places)
Rounds the given number to integer places right to the decimal point.
|
OutType |
rowtime()
Declares a field as the rowtime attribute for indicating, accessing, and working in Flink's
event time.
|
OutType |
rpad(InType len,
InType pad)
Returns a string right-padded with the given pad string to a length of len characters.
|
OutType |
rtrim()
Returns a string that removes the right whitespaces from the given string.
|
OutType |
second()
Creates an interval of the given number of seconds.
|
OutType |
seconds()
Creates an interval of the given number of seconds.
|
OutType |
sha1()
Returns the SHA-1 hash of the string argument; null if string is null.
|
OutType |
sha2(InType hashLength)
Returns the hash for the given string expression using the SHA-2 family of hash functions
(SHA-224, SHA-256, SHA-384, or SHA-512).
|
OutType |
sha224()
Returns the SHA-224 hash of the string argument; null if string is null.
|
OutType |
sha256()
Returns the SHA-256 hash of the string argument; null if string is null.
|
OutType |
sha384()
Returns the SHA-384 hash of the string argument; null if string is null.
|
OutType |
sha512()
Returns the SHA-512 hash of the string argument; null if string is null.
|
OutType |
sign()
Calculates the signum of a given number.
|
OutType |
similar(InType pattern)
Returns true, if a string matches the specified SQL regex pattern.
|
OutType |
sin()
Calculates the sine of a given number.
|
OutType |
sinh()
Calculates the hyperbolic sine of a given value.
|
OutType |
sqrt()
Calculates the square root of a given value.
|
OutType |
start()
Returns the start time (inclusive) of a window when applied on a window reference.
|
OutType |
stddevPop()
Returns the population standard deviation of an expression (the square root of varPop()).
|
OutType |
stddevSamp()
Returns the sample standard deviation of an expression (the square root of varSamp()).
|
OutType |
substring(InType beginIndex)
Creates a substring of the given string beginning at the given index to the end.
|
OutType |
substring(InType beginIndex,
InType length)
Creates a substring of the given string at given index for a given length.
|
OutType |
sum()
Returns the sum of the numeric field across all input values.
|
OutType |
sum0()
Returns the sum of the numeric field across all input values.
|
OutType |
tan()
Calculates the tangent of a given number.
|
OutType |
tanh()
Calculates the hyperbolic tangent of a given number.
|
OutType |
then(InType ifTrue,
InType ifFalse)
Ternary conditional operator that decides which of two other expressions should be evaluated
based on a evaluated boolean condition.
|
OutType |
times(InType other)
Returns left multiplied by right.
|
protected abstract OutType |
toApiSpecificExpression(Expression expression) |
OutType |
toBase64()
Returns the base64-encoded result of the input string.
|
OutType |
toDate()
Parses a date string in the form "yyyy-MM-dd" to a SQL Date.
|
protected abstract Expression |
toExpr() |
OutType |
toTime()
Parses a time string in the form "HH:mm:ss" to a SQL Time.
|
OutType |
toTimestamp()
Parses a timestamp string in the form "yyyy-MM-dd HH:mm:ss[.SSS]" to a SQL Timestamp.
|
OutType |
trim()
Removes leading and trailing space characters from the given string.
|
OutType |
trim(InType character)
Removes leading and trailing characters from the given string.
|
OutType |
trimLeading()
Removes leading space characters from the given string.
|
OutType |
trimLeading(InType character)
Removes leading characters from the given string.
|
OutType |
trimTrailing()
Removes trailing space characters from the given string.
|
OutType |
trimTrailing(InType character)
Removes trailing characters from the given string.
|
OutType |
truncate()
Returns a number of truncated to 0 decimal places.
|
OutType |
truncate(InType n)
Returns a number of truncated to n decimal places.
|
OutType |
upperCase()
Returns all of the characters in a string in upper case using the rules of the default
locale.
|
OutType |
varPop()
Returns the population standard variance of an expression.
|
OutType |
varSamp()
Returns the sample variance of a given expression.
|
OutType |
week()
Creates an interval of the given number of weeks.
|
OutType |
weeks()
Creates an interval of the given number of weeks.
|
OutType |
year()
Creates an interval of the given number of years.
|
OutType |
years()
Creates an interval of the given number of years.
|
protected abstract Expression toExpr()
protected abstract OutType toApiSpecificExpression(Expression expression)
public OutType as(String name, String... extraNames)
name
- name for one fieldextraNames
- additional names if the expression expands to multiple fieldspublic OutType and(InType other)
Expressions.and(Object, Object, Object...)
for prefix notation with multiple arguments.public OutType or(InType other)
Expressions.or(Object, Object, Object...)
for prefix notation with multiple arguments.public OutType between(InType lowerBound, InType upperBound)
lowerBound
- numeric or comparable expressionupperBound
- numeric or comparable expressionpublic OutType notBetween(InType lowerBound, InType upperBound)
lowerBound
- numeric or comparable expressionupperBound
- numeric or comparable expressionpublic OutType then(InType ifTrue, InType ifFalse)
e.g. lit(42).isGreater(5).then("A", "B") leads to "A"
ifTrue
- expression to be evaluated if condition holdsifFalse
- expression to be evaluated if condition does not holdpublic OutType isNull()
public OutType isNotNull()
public OutType isTrue()
public OutType isFalse()
public OutType isNotTrue()
public OutType isNotFalse()
public OutType distinct()
For example:
orders
.groupBy($("a"))
.select($("a"), $("b").sum().distinct().as("d"))
public OutType sum()
public OutType sum0()
public OutType min()
public OutType max()
public OutType count()
public OutType avg()
public OutType stddevPop()
public OutType stddevSamp()
public OutType varPop()
public OutType varSamp()
public OutType collect()
public OutType cast(DataType toType)
e.g. "42".cast(DataTypes.INT()) leads to 42.
@Deprecated public OutType cast(TypeInformation<?> toType)
cast(DataType)
instead which uses the new type system
based on DataTypes
. Please make sure to use either the
old or the new type system consistently to avoid unintended behavior. See the website
documentation for more information.public OutType asc()
public OutType desc()
@SafeVarargs public final OutType in(InType... elements)
If the testing set contains null, the result will be null if the element can not be found and true if it can be found. If the element is null, the result is always null.
e.g. lit("42").in(1, 2, 3) leads to false.
public OutType in(Table table)
Note: This operation is not supported in a streaming environment yet.
public OutType start()
public OutType end()
e.g. if a window ends at 10:59:59.999 this property will return 11:00:00.000.
public OutType mod(InType other)
public OutType exp()
public OutType log10()
public OutType log2()
public OutType ln()
public OutType log()
public OutType power(InType other)
public OutType cosh()
public OutType sqrt()
public OutType abs()
public OutType floor()
public OutType sinh()
public OutType ceil()
public OutType sin()
public OutType cos()
public OutType tan()
public OutType cot()
public OutType asin()
public OutType acos()
public OutType atan()
public OutType tanh()
public OutType degrees()
public OutType radians()
public OutType sign()
public OutType round(InType places)
public OutType bin()
public OutType hex()
E.g. a numeric 20 leads to "14", a numeric 100 leads to "64", and a string "hello,world" leads to "68656c6c6f2c776f726c64".
public OutType truncate(InType n)
public OutType truncate()
public OutType substring(InType beginIndex, InType length)
beginIndex
- first character of the substring (starting at 1, inclusive)length
- number of characters of the substringpublic OutType substring(InType beginIndex)
beginIndex
- first character of the substring (starting at 1, inclusive)public OutType trimLeading()
public OutType trimLeading(InType character)
character
- string containing the characterpublic OutType trimTrailing()
public OutType trimTrailing(InType character)
character
- string containing the characterpublic OutType trim()
public OutType trim(InType character)
character
- string containing the characterpublic OutType replace(InType search, InType replacement)
public OutType charLength()
public OutType upperCase()
public OutType lowerCase()
public OutType initCap()
public OutType like(InType pattern)
e.g. "Jo_n%" matches all strings that start with "Jo(arbitrary letter)n"
public OutType similar(InType pattern)
e.g. "A+" matches all strings that consist of at least one A
public OutType position(InType haystack)
e.g. lit("a").position("bbbbba") leads to 6
public OutType lpad(InType len, InType pad)
e.g. lit("hi").lpad(4, "??") returns "??hi", lit("hi").lpad(1, '??') returns "h"
public OutType rpad(InType len, InType pad)
e.g. lit("hi").rpad(4, "??") returns "hi??", lit("hi").rpad(1, '??') returns "h"
public OutType over(InType alias)
For example:
table
.window(Over partitionBy 'c orderBy 'rowtime preceding 2.rows following CURRENT_ROW as 'w)
.select('c, 'a, 'a.count over 'w, 'a.sum over 'w)
public OutType overlay(InType newString, InType starting)
e.g. lit("xxxxxtest").overlay("xxxx", 6) leads to "xxxxxxxxx"
public OutType overlay(InType newString, InType starting, InType length)
e.g. lit("xxxxxtest").overlay("xxxx", 6, 2) leads to "xxxxxxxxxst"
public OutType regexpReplace(InType regex, InType replacement)
public OutType regexpExtract(InType regex, InType extractIndex)
public OutType regexpExtract(InType regex)
public OutType fromBase64()
public OutType toBase64()
public OutType ltrim()
public OutType rtrim()
public OutType toDate()
public OutType toTime()
public OutType toTimestamp()
public OutType extract(TimeIntervalUnit timeIntervalUnit)
e.g. lit("2006-06-05").toDate().extract(DAY) leads to 5
public OutType floor(TimeIntervalUnit timeIntervalUnit)
e.g. lit("12:44:31").toDate().floor(MINUTE) leads to 12:44:00
public OutType ceil(TimeIntervalUnit timeIntervalUnit)
e.g. lit("12:44:31").toDate().ceil(MINUTE) leads to 12:45:00
public OutType get(String name)
name
- name of the field (similar to Flink's field expressions)public OutType get(int index)
index
- position of the fieldpublic OutType flatten()
public OutType at(InType index)
index
- key or position of the element (array index starting at 1)public OutType cardinality()
public OutType element()
public OutType rowtime()
public OutType proctime()
public OutType year()
The produced expression is of type DataTypes.INTERVAL
public OutType years()
public OutType quarter()
public OutType quarters()
public OutType month()
public OutType months()
public OutType week()
public OutType weeks()
public OutType day()
public OutType days()
public OutType hour()
public OutType hours()
public OutType minute()
public OutType minutes()
public OutType second()
public OutType seconds()
public OutType milli()
public OutType millis()
public OutType md5()
public OutType sha1()
public OutType sha224()
public OutType sha256()
public OutType sha384()
public OutType sha512()
public OutType sha2(InType hashLength)
hashLength
- bit length of the result (either 224, 256, 384, or 512)Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.