Class BaseExpressions<InType,​OutType>

  • Type Parameters:
    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.
    Direct Known Subclasses:
    ApiExpression

    @PublicEvolving
    public abstract class BaseExpressions<InType,​OutType>
    extends Object
    These are Java and Scala common operations that can be used to construct an Expression AST for expression operations.
    • Constructor Detail

      • BaseExpressions

        public BaseExpressions()
    • Method Detail

      • toApiSpecificExpression

        protected abstract OutType toApiSpecificExpression​(Expression expression)
      • as

        public OutType as​(String name,
                          String... extraNames)
        Specifies a name for an expression i.e. a field.
        Parameters:
        name - name for one field
        extraNames - additional names if the expression expands to multiple fields
      • arrayExcept

        public OutType arrayExcept​(InType array)
        Returns an ARRAY that contains the elements from array1 that are not in array2. If no elements remain after excluding the elements in array2 from array1, the function returns an empty ARRAY.

        If one or both arguments are NULL, the function returns NULL. The order of the elements from array1 is kept.

      • arrayIntersect

        public OutType arrayIntersect​(InType array)
        Returns an ARRAY that contains the elements from array1 that are also in array2, without duplicates. If no elements that are both in array1 and array2, the function returns an empty ARRAY.

        If one or both arguments are NULL, the function returns NULL. The order of the elements from array1 is kept.

      • not

        public OutType not()
        Inverts a given boolean expression.

        This method supports a three-valued logic by preserving NULL. This means if the input expression is NULL, the result will also be NULL.

        The resulting type is nullable if and only if the input type is nullable.

        Examples:

        
         lit(true).not() // false
         lit(false).not() // true
         lit(null, DataTypes.BOOLEAN()).not() // null
         
      • isGreater

        public OutType isGreater​(InType other)
        Greater than.
      • isGreaterOrEqual

        public OutType isGreaterOrEqual​(InType other)
        Greater than or equal.
      • isLessOrEqual

        public OutType isLessOrEqual​(InType other)
        Less than or equal.
      • isNotEqual

        public OutType isNotEqual​(InType other)
        Not equal.
      • plus

        public OutType plus​(InType other)
        Returns left plus right.
      • minus

        public OutType minus​(InType other)
        Returns left minus right.
      • dividedBy

        public OutType dividedBy​(InType other)
        Returns left divided by right.
      • times

        public OutType times​(InType other)
        Returns left multiplied by right.
      • concat

        public OutType concat​(InType other)
        Concatenates two strings.
      • between

        public OutType between​(InType lowerBound,
                               InType upperBound)
        Returns true if the given expression is between lowerBound and upperBound (both inclusive). False otherwise. The parameters must be numeric types or identical comparable types.
        Parameters:
        lowerBound - numeric or comparable expression
        upperBound - numeric or comparable expression
      • notBetween

        public OutType notBetween​(InType lowerBound,
                                  InType upperBound)
        Returns true if the given expression is not between lowerBound and upperBound (both inclusive). False otherwise. The parameters must be numeric types or identical comparable types.
        Parameters:
        lowerBound - numeric or comparable expression
        upperBound - numeric or comparable expression
      • then

        public 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.

        e.g. lit(42).isGreater(5).then("A", "B") leads to "A"

        Parameters:
        ifTrue - expression to be evaluated if condition holds
        ifFalse - expression to be evaluated if condition does not hold
      • ifNull

        public OutType ifNull​(InType nullReplacement)
        Returns nullReplacement if the given expression is NULL; otherwise the expression is returned.

        This function returns a data type that is very specific in terms of nullability. The returned type is the common type of both arguments but only nullable if the nullReplacement is nullable.

        The function allows to pass nullable columns into a function or table that is declared with a NOT NULL constraint.

        E.g., $('nullable_column').ifNull(5) returns never NULL.

      • isNull

        public OutType isNull()
        Returns true if the given expression is null.
      • isNotNull

        public OutType isNotNull()
        Returns true if the given expression is not null.
      • isTrue

        public OutType isTrue()
        Returns true if given boolean expression is true. False otherwise (for null and false).
      • isFalse

        public OutType isFalse()
        Returns true if given boolean expression is false. False otherwise (for null and true).
      • isNotTrue

        public OutType isNotTrue()
        Returns true if given boolean expression is not true (for null and false). False otherwise.
      • isNotFalse

        public OutType isNotFalse()
        Returns true if given boolean expression is not false (for null and true). False otherwise.
      • distinct

        public 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.

        For example:

        
         orders
          .groupBy($("a"))
          .select($("a"), $("b").sum().distinct().as("d"))
         
      • sum

        public OutType sum()
        Returns the sum of the numeric field across all input values. If all values are null, null is returned.
      • sum0

        public OutType sum0()
        Returns the sum of the numeric field across all input values. If all values are null, 0 is returned.
      • min

        public OutType min()
        Returns the minimum value of field across all input values.
      • max

        public OutType max()
        Returns the maximum value of field across all input values.
      • count

        public OutType count()
        Returns the number of input rows for which the field is not null.
      • avg

        public OutType avg()
        Returns the average (arithmetic mean) of the numeric field across all input values.
      • firstValue

        public OutType firstValue()
        Returns the first value of field across all input values.
      • lastValue

        public OutType lastValue()
        Returns the last value of field across all input values.
      • listAgg

        public OutType listAgg()
        Concatenates the values of string expressions and places separator(,) values between them. The separator is not added at the end of string.
      • listAgg

        public OutType listAgg​(String separator)
        Concatenates the values of string expressions and places separator values between them. The separator is not added at the end of string. The default value of separator is ‘,’.
        Parameters:
        separator - string containing the character
      • stddevPop

        public OutType stddevPop()
        Returns the population standard deviation of an expression (the square root of varPop()).
      • stddevSamp

        public OutType stddevSamp()
        Returns the sample standard deviation of an expression (the square root of varSamp()).
      • varPop

        public OutType varPop()
        Returns the population standard variance of an expression.
      • varSamp

        public OutType varSamp()
        Returns the sample variance of a given expression.
      • collect

        public OutType collect()
        Returns multiset aggregate of a given expression.
      • arrayAgg

        public OutType arrayAgg()
        Returns array aggregate of a given expression.
      • tryCast

        public OutType tryCast​(DataType toType)
        Like cast(DataType), but in case of error, returns null rather than failing the job.

        E.g. "42".tryCast(DataTypes.INT()) returns 42; null.tryCast(DataTypes.STRING()) returns null of type DataTypes.STRING(); "non-number".tryCast(DataTypes.INT()) returns null of type DataTypes.INT(); coalesce("non-number".tryCast(DataTypes.INT()), 0) returns 0 of type DataTypes.INT().

      • cast

        @Deprecated
        public 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.
      • asc

        public OutType asc()
        Specifies ascending order of an expression i.e. a field for orderBy unresolvedCall.
      • desc

        public OutType desc()
        Specifies descending order of an expression i.e. a field for orderBy unresolvedCall.
      • in

        @SafeVarargs
        public final OutType in​(InType... elements)
        Returns true if an expression exists in a given list of expressions. This is a shorthand for multiple OR conditions.

        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.

      • in

        public OutType in​(Table table)
        Returns true if an expression exists in a given table sub-query. The sub-query table must consist of one column. This column must have the same data type as the expression.

        Note: This operation is not supported in a streaming environment yet.

      • start

        public OutType start()
        Returns the start time (inclusive) of a window when applied on a window reference.
      • end

        public OutType end()
        Returns the end time (exclusive) of a window when applied on a window reference.

        e.g. if a window ends at 10:59:59.999 this property will return 11:00:00.000.

      • mod

        public OutType mod​(InType other)
        Calculates the remainder of division the given number by another one.
      • exp

        public OutType exp()
        Calculates the Euler's number raised to the given power.
      • log10

        public OutType log10()
        Calculates the base 10 logarithm of the given value.
      • log2

        public OutType log2()
        Calculates the base 2 logarithm of the given value.
      • ln

        public OutType ln()
        Calculates the natural logarithm of the given value.
      • log

        public OutType log()
        Calculates the natural logarithm of the given value.
      • log

        public OutType log​(InType base)
        Calculates the logarithm of the given value to the given base.
      • power

        public OutType power​(InType other)
        Calculates the given number raised to the power of the other value.
      • cosh

        public OutType cosh()
        Calculates the hyperbolic cosine of a given value.
      • sqrt

        public OutType sqrt()
        Calculates the square root of a given value.
      • abs

        public OutType abs()
        Calculates the absolute value of given value.
      • floor

        public OutType floor()
        Calculates the largest integer less than or equal to a given number.
      • sinh

        public OutType sinh()
        Calculates the hyperbolic sine of a given value.
      • ceil

        public OutType ceil()
        Calculates the smallest integer greater than or equal to a given number.
      • sin

        public OutType sin()
        Calculates the sine of a given number.
      • cos

        public OutType cos()
        Calculates the cosine of a given number.
      • tan

        public OutType tan()
        Calculates the tangent of a given number.
      • cot

        public OutType cot()
        Calculates the cotangent of a given number.
      • asin

        public OutType asin()
        Calculates the arc sine of a given number.
      • acos

        public OutType acos()
        Calculates the arc cosine of a given number.
      • atan

        public OutType atan()
        Calculates the arc tangent of a given number.
      • tanh

        public OutType tanh()
        Calculates the hyperbolic tangent of a given number.
      • degrees

        public OutType degrees()
        Converts numeric from radians to degrees.
      • radians

        public OutType radians()
        Converts numeric from degrees to radians.
      • sign

        public OutType sign()
        Calculates the signum of a given number.
      • round

        public OutType round​(InType places)
        Rounds the given number to integer places right to the decimal point.
      • bin

        public OutType bin()
        Returns a string representation of an integer numeric value in binary format. Returns null if numeric is null. E.g. "4" leads to "100", "12" leads to "1100".
      • hex

        public OutType hex()
        Returns a string representation of an integer numeric value or a string in hex format. Returns null if numeric or string is null.

        E.g. a numeric 20 leads to "14", a numeric 100 leads to "64", and a string "hello,world" leads to "68656c6c6f2c776f726c64".

      • unhex

        public OutType unhex()
        Converts hexadecimal string expr to BINARY. If the length of expr is odd, the first character is discarded and the result is left padded with a null byte.
        Returns:
        a BINARY.
        null if expr is null or expr contains non-hex characters.
      • truncate

        public OutType truncate​(InType n)
        Returns a number of truncated to n decimal places. If n is 0,the result has no decimal point or fractional part. n can be negative to cause n digits left of the decimal point of the value to become zero. E.g. truncate(42.345, 2) to 42.34.
      • truncate

        public OutType truncate()
        Returns a number of truncated to 0 decimal places. E.g. truncate(42.345) to 42.0.
      • startsWith

        public OutType startsWith​(InType startExpr)
        Returns whether expr starts with startExpr. If startExpr is empty, the result is true.
        expr and startExpr should have same type.
        Parameters:
        startExpr - A STRING or BINARY expression.
        Returns:
        A BOOLEAN.
      • endsWith

        public OutType endsWith​(InType endExpr)
        Returns whether expr ends with endExpr. If endExpr is empty, the result is true.
        expr and endExpr should have same type.
        Parameters:
        endExpr - A STRING or BINARY expression.
        Returns:
        A BOOLEAN.
      • substring

        public OutType substring​(InType beginIndex,
                                 InType length)
        Creates a substring of the given string at given index for a given length.
        Parameters:
        beginIndex - first character of the substring (starting at 1, inclusive)
        length - number of characters of the substring
      • substring

        public OutType substring​(InType beginIndex)
        Creates a substring of the given string beginning at the given index to the end.
        Parameters:
        beginIndex - first character of the substring (starting at 1, inclusive)
      • substr

        public OutType substr​(InType beginIndex,
                              InType length)
        Creates a substring of the given string at given index for a given length.
        Parameters:
        beginIndex - first character of the substring (starting at 1, inclusive)
        length - number of characters of the substring
      • substr

        public OutType substr​(InType beginIndex)
        Creates a substring of the given string beginning at the given index to the end.
        Parameters:
        beginIndex - first character of the substring (starting at 1, inclusive)
      • translate

        public OutType translate​(InType fromStr,
                                 InType toStr)
        Translate an expr where all characters in fromStr have been replaced with those in toStr.
        NOTE: If toStr has a shorter length than fromStr, unmatched characters are removed.
        Parameters:
        fromStr - a STRING expression
        toStr - a STRING expression
      • trimLeading

        public OutType trimLeading()
        Removes leading space characters from the given string.
      • trimLeading

        public OutType trimLeading​(InType character)
        Removes leading characters from the given string.
        Parameters:
        character - string containing the character
      • trimTrailing

        public OutType trimTrailing()
        Removes trailing space characters from the given string.
      • trimTrailing

        public OutType trimTrailing​(InType character)
        Removes trailing characters from the given string.
        Parameters:
        character - string containing the character
      • trim

        public OutType trim()
        Removes leading and trailing space characters from the given string.
      • trim

        public OutType trim​(InType character)
        Removes leading and trailing characters from the given string.
        Parameters:
        character - string containing the character
      • replace

        public 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).
      • charLength

        public OutType charLength()
        Returns the length of a string.
      • upperCase

        public OutType upperCase()
        Returns all of the characters in a string in upper case using the rules of the default locale.
      • lowerCase

        public OutType lowerCase()
        Returns all of the characters in a string in lower case using the rules of the default locale.
      • initCap

        public OutType initCap()
        Converts the initial letter of each word in a string to uppercase. Assumes a string containing only [A-Za-z0-9], everything else is treated as whitespace.
      • like

        public OutType like​(InType pattern)
        Returns true, if a string matches the specified LIKE pattern with default escape character '/'.

        e.g. "Jo_n%" matches all strings that start with "Jo(arbitrary letter)n"

      • like

        public OutType like​(InType pattern,
                            InType escape)
        Returns true, if a string matches the specified LIKE pattern with specified escape character consisting of a single char.

        e.g. "Jo_n%" matches all strings that start with "Jo(arbitrary letter)n"

      • similar

        public OutType similar​(InType pattern)
        Returns true, if a string matches the specified SQL regex pattern.

        e.g. "A+" matches all strings that consist of at least one A

      • position

        public OutType position​(InType haystack)
        Returns the position of string in an other string starting at 1. Returns 0 if string could not be found.

        e.g. lit("a").position("bbbbba") leads to 6

      • lpad

        public OutType lpad​(InType len,
                            InType pad)
        Returns a string left-padded with the given pad string to a length of len characters. If the string is longer than len, the return value is shortened to len characters.

        e.g. lit("hi").lpad(4, "??") returns "??hi", lit("hi").lpad(1, '??') returns "h"

      • rpad

        public OutType rpad​(InType len,
                            InType pad)
        Returns a string right-padded with the given pad string to a length of len characters. If the string is longer than len, the return value is shortened to len characters.

        e.g. lit("hi").rpad(4, "??") returns "hi??", lit("hi").rpad(1, '??') returns "h"

      • over

        public OutType over​(InType alias)
        Defines an aggregation to be used for a previously specified over window.

        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)
         
      • overlay

        public OutType overlay​(InType newString,
                               InType starting)
        Replaces a substring of string with a string starting at a position (starting at 1).

        e.g. lit("xxxxxtest").overlay("xxxx", 6) leads to "xxxxxxxxx"

      • overlay

        public OutType overlay​(InType newString,
                               InType starting,
                               InType length)
        Replaces a substring of string with a string starting at a position (starting at 1). The length specifies how many characters should be removed.

        e.g. lit("xxxxxtest").overlay("xxxx", 6, 2) leads to "xxxxxxxxxst"

      • regexp

        public OutType regexp​(InType regex)
        Returns TRUE if any (possibly empty) substring matches the Java regular expression, otherwise FALSE. Returns NULL if any of arguments is NULL.
      • regexpCount

        public OutType regexpCount​(InType regex)
        Returns the number of times str matches the regex pattern. regex must be a Java regular expression.
        Parameters:
        regex - A STRING expression with a matching pattern.
        Returns:
        An INTEGER representation of the number of matches.
        null if any of the arguments are null or regex is invalid.
      • regexpReplace

        public OutType regexpReplace​(InType regex,
                                     InType replacement)
        Returns a string with all substrings that match the regular expression consecutively being replaced.
      • regexpExtract

        public OutType regexpExtract​(InType regex,
                                     InType extractIndex)
        Returns a string extracted with a specified regular expression and a regex match group index.
      • regexpExtract

        public OutType regexpExtract​(InType regex)
        Returns a string extracted with a specified regular expression.
      • regexpExtractAll

        public OutType regexpExtractAll​(InType regex,
                                        InType extractIndex)
        Extracts all the substrings in str that match the regex expression and correspond to the regex group extractIndex.
        regex may contain multiple groups. extractIndex indicates which regex group to extract and starts from 1, also the default value if not specified. 0 means matching the entire regular expression.
        Parameters:
        regex - A STRING expression with a matching pattern.
        extractIndex - An optional INTEGER expression with default 1.
        Returns:
        An ARRAY<STRING> of all the matched substrings.
        null if any of the arguments are null or invalid.
      • regexpExtractAll

        public OutType regexpExtractAll​(InType regex)
        Extracts all the strings in str that match the regex expression.
      • regexpInstr

        public OutType regexpInstr​(InType regex)
        Returns the position of the first substring in str that matches regex.
        Result indexes begin at 1, 0 if there is no match.
        Parameters:
        regex - A STRING expression with a matching pattern.
        Returns:
        An INTEGER representation of the first matched substring index.
        null if any of the arguments are null or regex is invalid.
      • regexpSubstr

        public OutType regexpSubstr​(InType regex)
        Returns the first substring in str that matches regex.
        Parameters:
        regex - A STRING expression with a matching pattern.
        Returns:
        A STRING representation of the first matched substring.
        null if any of the arguments are null or regex is invalid or pattern is not found.
      • jsonQuote

        public OutType jsonQuote()
        Returns a string by quotes a string as a JSON value and wrapping it with double quote characters.
      • jsonUnquote

        public OutType jsonUnquote()
        Returns a string by unquoting JSON value.
      • fromBase64

        public OutType fromBase64()
        Returns the base string decoded with base64.
      • toBase64

        public OutType toBase64()
        Returns the base64-encoded result of the input string.
      • ascii

        public OutType ascii()
        Returns the numeric value of the first character of the input string.
      • chr

        public OutType chr()
        Returns the ASCII character result of the input integer.
      • decode

        public OutType decode​(InType charset)
        Decodes the first argument into a String using the provided character set.
      • encode

        public OutType encode​(InType charset)
        Encodes the string into a BINARY using the provided character set.
      • left

        public OutType left​(InType len)
        Returns the leftmost integer characters from the input string.
      • right

        public OutType right​(InType len)
        Returns the rightmost integer characters from the input string.
      • instr

        public OutType instr​(InType str)
        Returns the position of the first occurrence of the input string.
      • locate

        public OutType locate​(InType str)
        Returns the position of the first occurrence in the input string.
      • locate

        public OutType locate​(InType str,
                              InType pos)
        Returns the position of the first occurrence in the input string after position integer.
      • urlDecode

        public OutType urlDecode()
        Decodes a given string in 'application/x-www-form-urlencoded' format using the UTF-8 encoding scheme. If the input is null, or there is an issue with the decoding process(such as encountering an illegal escape pattern), or the encoding scheme is not supported, will return null.
      • urlEncode

        public OutType urlEncode()
        Translates a string into 'application/x-www-form-urlencoded' format using the UTF-8 encoding scheme. If the input is null, or there is an issue with the encoding process, or the encoding scheme is not supported, will return null.
      • parseUrl

        public OutType parseUrl​(InType partToExtract)
        Parse url and return various parameter of the URL. If accept any null arguments, return null.
      • parseUrl

        public OutType parseUrl​(InType partToExtract,
                                InType key)
        Parse url and return various parameter of the URL. If accept any null arguments, return null.
      • printf

        public final OutType printf​(InType... obj)
        Returns a formatted string from printf-style format string. The function exploits the Formatter with Locale.US.
        Parameters:
        obj - any expression
        Returns:
        a formatted string. null if format is null or invalid.
      • ltrim

        public OutType ltrim()
        Returns a string that removes the left whitespaces from the given string.
      • ltrim

        public OutType ltrim​(InType trimStr)
        Returns a string that removes the left chars in trimStr from the given string.
      • rtrim

        public OutType rtrim()
        Returns a string that removes the right whitespaces from the given string.
      • rtrim

        public OutType rtrim​(InType trimStr)
        Returns a string that removes the right chars in trimStr from the given string.
      • btrim

        public OutType btrim()
        Returns a string that removes the left and right whitespaces from the given string.
      • btrim

        public OutType btrim​(InType trimStr)
        Returns a string that removes the left and right chars in trimStr from the given string.
      • repeat

        public OutType repeat​(InType n)
        Returns a string that repeats the base string n times.
      • reverse

        public OutType reverse()
        Reverse each character in current string.
        Returns:
        a new string which character order is reverse to current string.
      • splitIndex

        public OutType splitIndex​(InType separator,
                                  InType index)
        Split target string with custom separator and pick the index-th(start with 0) result.
        Parameters:
        separator - custom separator.
        index - index of the result which you want.
        Returns:
        the string at the index of split results.
      • strToMap

        public OutType strToMap()
        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.
        Returns:
        the map
      • strToMap

        public OutType strToMap​(InType listDelimiter,
                                InType 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. Both listDelimiter and keyValueDelimiter are treated as regular expressions.
        Parameters:
        listDelimiter - the delimiter to separates pairs
        keyValueDelimiter - the delimiter to separates key and value
        Returns:
        the map
      • elt

        public OutType elt​(InType expr,
                           InType... exprs)
        Returns the index-th expression. index must be an integer between 1 and the number of expressions.
        Parameters:
        expr - a STRING or BINARY expression
        exprs - a STRING or BINARY expression
        Returns:
        result type is the least common type of all expressions.
        null if index is null or out of range.
      • toDate

        public OutType toDate()
        Parses a date string in the form "yyyy-MM-dd" to a SQL Date.
      • toTime

        public OutType toTime()
        Parses a time string in the form "HH:mm:ss" to a SQL Time.
      • toTimestamp

        public OutType toTimestamp()
        Parses a timestamp string in the form "yyyy-MM-dd HH:mm:ss[.SSS]" to a SQL Timestamp.
      • extract

        public OutType extract​(TimeIntervalUnit timeIntervalUnit)
        Extracts parts of a time point or time interval. Returns the part as a long value.

        e.g. lit("2006-06-05").toDate().extract(DAY) leads to 5

      • floor

        public OutType floor​(TimeIntervalUnit timeIntervalUnit)
        Rounds down a time point to the given unit.

        e.g. lit("12:44:31").toDate().floor(MINUTE) leads to 12:44:00

      • ceil

        public OutType ceil​(TimeIntervalUnit timeIntervalUnit)
        Rounds up a time point to the given unit.

        e.g. lit("12:44:31").toDate().ceil(MINUTE) leads to 12:45:00

      • get

        public OutType get​(String name)
        Accesses the field of a Flink composite type (such as Tuple, POJO, etc.) by name and returns it's value.
        Parameters:
        name - name of the field (similar to Flink's field expressions)
      • get

        public OutType get​(int index)
        Accesses the field of a Flink composite type (such as Tuple, POJO, etc.) by index and returns it's value.
        Parameters:
        index - position of the field
      • flatten

        public 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.
      • at

        public OutType at​(InType index)
        Accesses the element of an array or map based on a key or an index (starting at 1).
        Parameters:
        index - key or position of the element (array index starting at 1)
      • cardinality

        public OutType cardinality()
        Returns the number of elements of an array or number of entries of a map.
      • element

        public OutType element()
        Returns the sole element of an array with a single element. Returns null if the array is empty. Throws an exception if the array has more than one element.
      • arrayAppend

        public OutType arrayAppend​(InType element)
        Appends an element to the end of the array and returns the result.

        If the array itself is null, the function will return null. If an element to add is null, the null element will be added to the end of the array. The given element is cast implicitly to the array's element type if necessary.

      • arrayContains

        public OutType arrayContains​(InType needle)
        Returns whether the given element exists in an array.

        Checking for null elements in the array is supported. If the array itself is null, the function will return null. The given element is cast implicitly to the array's element type if necessary.

      • arrayDistinct

        public OutType arrayDistinct()
        Returns an array with unique elements.

        If the array itself is null, the function will return null. Keeps ordering of elements.

      • arrayPosition

        public OutType arrayPosition​(InType needle)
        Returns the position of the first occurrence of element in the given array as int. Returns 0 if the given value could not be found in the array. Returns null if either of the arguments are null

        NOTE: that this is not zero based, but 1-based index. The first element in the array has index 1.

      • arrayPrepend

        public OutType arrayPrepend​(InType element)
        Appends an element to the beginning of the array and returns the result.

        If the array itself is null, the function will return null. If an element to add is null, the null element will be added to the beginning of the array. The given element is cast implicitly to the array's element type if necessary.

      • arrayRemove

        public OutType arrayRemove​(InType needle)
        Removes all elements that equal to element from array.

        If the array itself is null, the function will return null. Keeps ordering of elements.

      • arrayReverse

        public OutType arrayReverse()
        Returns an array in reverse order.

        If the array itself is null, the function will return null.

      • arraySlice

        public OutType arraySlice​(InType startOffset,
                                  InType endOffset)
        Returns a subarray of the input array between 'start_offset' and 'end_offset' inclusive. The offsets are 1-based however 0 is also treated as the beginning of the array. Positive values are counted from the beginning of the array while negative from the end. If 'end_offset' is omitted then this offset is treated as the length of the array. If 'start_offset' is after 'end_offset' or both are out of array bounds an empty array will be returned.

        Returns null if any input is null.

      • arrayUnion

        public OutType arrayUnion​(InType array)
        Returns an array of the elements in the union of array1 and array2, without duplicates.

        If any of the array is null, the function will return null.

      • arrayConcat

        public OutType arrayConcat​(InType... arrays)
        Returns an array that is the result of concatenating at least one array. This array contains all the elements in the first array, followed by all the elements in the second array, and so forth, up to the Nth array.

        If any input array is NULL, the function returns NULL.

      • arrayMax

        public OutType arrayMax()
        Returns the maximum value from the array.

        if array itself is null, the function returns null.

      • arrayMin

        public OutType arrayMin()
        Returns the minimum value from the array.

        if array itself is null, the function returns null.

      • split

        public OutType split​(InType delimiter)
        Returns an array of substrings by splitting the input string based on a given delimiter.

        If the delimiter is not found in the string, the original string is returned as the only element in the array. If the delimiter is empty, every character in the string is split. If the string or delimiter is null, a null value is returned. If the delimiter is found at the beginning or end of the string, or there are contiguous delimiters, then an empty string is added to the array.

      • mapKeys

        public OutType mapKeys()
        Returns the keys of the map as an array.
      • mapValues

        public OutType mapValues()
        Returns the values of the map as an array.
      • mapEntries

        public OutType mapEntries()
        Returns an array of all entries in the given map.
      • mapUnion

        public OutType mapUnion​(InType... inputs)
        Returns a map created by merging at least one map. These maps should have a common map type. If there are overlapping keys, the value from 'map2' will overwrite the value from 'map1', the value from 'map3' will overwrite the value from 'map2', the value from 'mapn' will overwrite the value from 'map(n-1)'. If any of maps is null, return null.
      • rowtime

        public OutType rowtime()
        Declares a field as the rowtime attribute for indicating, accessing, and working in Flink's event time.
      • proctime

        public OutType proctime()
        Declares a field as the proctime attribute for indicating, accessing, and working in Flink's processing time.
      • year

        public OutType year()
        Creates an interval of the given number of years.

        The produced expression is of type DataTypes.INTERVAL

      • years

        public OutType years()
        Creates an interval of the given number of years.
      • quarter

        public OutType quarter()
        Creates an interval of the given number of quarters.
      • quarters

        public OutType quarters()
        Creates an interval of the given number of quarters.
      • month

        public OutType month()
        Creates an interval of the given number of months.
      • months

        public OutType months()
        Creates an interval of the given number of months.
      • week

        public OutType week()
        Creates an interval of the given number of weeks.
      • weeks

        public OutType weeks()
        Creates an interval of the given number of weeks.
      • day

        public OutType day()
        Creates an interval of the given number of days.
      • days

        public OutType days()
        Creates an interval of the given number of days.
      • hour

        public OutType hour()
        Creates an interval of the given number of hours.
      • hours

        public OutType hours()
        Creates an interval of the given number of hours.
      • minute

        public OutType minute()
        Creates an interval of the given number of minutes.
      • minutes

        public OutType minutes()
        Creates an interval of the given number of minutes.
      • second

        public OutType second()
        Creates an interval of the given number of seconds.
      • seconds

        public OutType seconds()
        Creates an interval of the given number of seconds.
      • milli

        public OutType milli()
        Creates an interval of the given number of milliseconds.
      • millis

        public OutType millis()
        Creates an interval of the given number of milliseconds.
      • md5

        public OutType md5()
        Returns the MD5 hash of the string argument; null if string is null.
        Returns:
        string of 32 hexadecimal digits or null
      • sha1

        public OutType sha1()
        Returns the SHA-1 hash of the string argument; null if string is null.
        Returns:
        string of 40 hexadecimal digits or null
      • sha224

        public OutType sha224()
        Returns the SHA-224 hash of the string argument; null if string is null.
        Returns:
        string of 56 hexadecimal digits or null
      • sha256

        public OutType sha256()
        Returns the SHA-256 hash of the string argument; null if string is null.
        Returns:
        string of 64 hexadecimal digits or null
      • sha384

        public OutType sha384()
        Returns the SHA-384 hash of the string argument; null if string is null.
        Returns:
        string of 96 hexadecimal digits or null
      • sha512

        public OutType sha512()
        Returns the SHA-512 hash of the string argument; null if string is null.
        Returns:
        string of 128 hexadecimal digits or null
      • sha2

        public 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).
        Parameters:
        hashLength - bit length of the result (either 224, 256, 384, or 512)
        Returns:
        string or null if one of the arguments is null.
      • isJson

        public OutType isJson​(JsonType type)
        Determine whether a given string is valid JSON.

        Specifying the optional {@param type} argument puts a constraint on which type of JSON object is allowed. If the string is valid JSON, but not that type, false is returned. The default is JsonType.VALUE.

        Examples:

        
         lit("1").isJson() // true
         lit("[]").isJson() // true
         lit("{}").isJson() // true
        
         lit("\"abc\"").isJson() // true
         lit("abc").isJson() // false
         nullOf(DataTypes.STRING()).isJson() // false
        
         lit("1").isJson(JsonType.SCALAR) // true
         lit("1").isJson(JsonType.ARRAY) // false
         lit("1").isJson(JsonType.OBJECT) // false
        
         lit("{}").isJson(JsonType.SCALAR) // false
         lit("{}").isJson(JsonType.ARRAY) // false
         lit("{}").isJson(JsonType.OBJECT) // true
         
        Parameters:
        type - The type of JSON object to validate against.
        Returns:
        true if the string is a valid JSON of the given {@param type}, false otherwise.
      • isJson

        public OutType isJson()
        Determine whether a given string is valid JSON.

        This is a shortcut for isJson(JsonType.VALUE). See isJson(JsonType).

        Returns:
        true if the string is a valid JSON value, false otherwise.
      • jsonExists

        public OutType jsonExists​(String path,
                                  JsonExistsOnError onError)
        Returns whether a JSON string satisfies a given search criterion.

        This follows the ISO/IEC TR 19075-6 specification for JSON support in SQL.

        Examples:

        
         // true
         lit("{\"a\": true}").jsonExists("$.a")
         // false
         lit("{\"a\": true}").jsonExists("$.b")
         // true
         lit("{\"a\": [{ \"b\": 1 }]}").jsonExists("$.a[0].b")
        
         // true
         lit("{\"a\": true}").jsonExists("strict $.b", JsonExistsOnError.TRUE)
         // false
         lit("{\"a\": true}").jsonExists("strict $.b", JsonExistsOnError.FALSE)
         
        Parameters:
        path - JSON path to search for.
        onError - Behavior in case of an error.
        Returns:
        true if the JSON string satisfies the search criterion.
      • jsonExists

        public OutType jsonExists​(String path)
        Determines whether a JSON string satisfies a given search criterion.

        This follows the ISO/IEC TR 19075-6 specification for JSON support in SQL.

        Examples:

        
         // true
         lit("{\"a\": true}").jsonExists("$.a")
         // false
         lit("{\"a\": true}").jsonExists("$.b")
         // true
         lit("{\"a\": [{ \"b\": 1 }]}").jsonExists("$.a[0].b")
        
         // true
         lit("{\"a\": true}").jsonExists("strict $.b", JsonExistsOnError.TRUE)
         // false
         lit("{\"a\": true}").jsonExists("strict $.b", JsonExistsOnError.FALSE)
         
        Parameters:
        path - JSON path to search for.
        Returns:
        true if the JSON string satisfies the search criterion.
      • jsonValue

        public OutType jsonValue​(String path,
                                 DataType returningType,
                                 JsonValueOnEmptyOrError onEmpty,
                                 InType defaultOnEmpty,
                                 JsonValueOnEmptyOrError onError,
                                 InType defaultOnError)
        Extracts a scalar from a JSON string.

        This method searches a JSON string for a given path expression and returns the value if the value at that path is scalar. Non-scalar values cannot be returned. By default, the value is returned as DataTypes.STRING(). Using {@param returningType} a different type can be chosen, with the following types being supported:

        For empty path expressions or errors a behavior can be defined to either return null, raise an error or return a defined default value instead.

        See jsonQuery(String, JsonQueryWrapper, JsonQueryOnEmptyOrError, JsonQueryOnEmptyOrError) for extracting non-scalar values from a JSON string.

        Examples:

        
         // STRING: "true"
         lit("{\"a\": true}").jsonValue("$.a")
        
         // DOUBLE: 0.998
         lit("{\"a.b\": [0.998,0.996]}").jsonValue("$.['a.b'][0]", DataTypes.DOUBLE())
        
         // BOOLEAN: true
         lit("{\"a\": true}").jsonValue("$.a", DataTypes.BOOLEAN())
        
         // BOOLEAN: "false"
         lit("{\"a\": true}").jsonValue("lax $.b",
             JsonValueOnEmptyOrError.DEFAULT, false, JsonValueOnEmptyOrError.NULL, null)
        
         // BOOLEAN: "false"
         lit("{\"a\": true}").jsonValue("strict $.b",
             JsonValueOnEmptyOrError.NULL, null, JsonValueOnEmptyOrError.DEFAULT, false)
         
        Parameters:
        path - JSON path to extract.
        returningType - Type to convert the extracted scalar to, otherwise defaults to DataTypes.STRING().
        onEmpty - Behavior in case the path expression is empty.
        defaultOnEmpty - Default value to return if the path expression is empty and {@param onEmpty} is set to JsonValueOnEmptyOrError.DEFAULT.
        onError - Behavior in case of an error.
        defaultOnError - Default value to return if there is an error and {@param onError} is set to JsonValueOnEmptyOrError.DEFAULT.
        Returns:
        The extracted scalar value.
      • jsonQuery

        public OutType jsonQuery​(String path,
                                 DataType returnType,
                                 JsonQueryWrapper wrappingBehavior,
                                 JsonQueryOnEmptyOrError onEmpty,
                                 JsonQueryOnEmptyOrError onError)
        Extracts JSON values from a JSON string.

        This follows the ISO/IEC TR 19075-6 specification for JSON support in SQL. The result is always returned as a DataTypes.STRING().

        The {@param wrappingBehavior} determines whether the extracted value should be wrapped into an array, and whether to do so unconditionally or only if the value itself isn't an array already.

        {@param onEmpty} and {@param onError} determine the behavior in case the path expression is empty, or in case an error was raised, respectively. By default, in both cases null is returned. Other choices are to use an empty array, an empty object, or to raise an error.

        See jsonValue(String, DataType, JsonValueOnEmptyOrError, Object, JsonValueOnEmptyOrError, Object) for extracting scalars from a JSON string.

        Examples:

        
         lit("{ \"a\": { \"b\": 1 } }").jsonQuery("$.a") // "{ \"b\": 1 }"
         lit("[1, 2]").jsonQuery("$") // "[1, 2]"
         nullOf(DataTypes.STRING()).jsonQuery("$") // null
        
         // Wrap result into an array
         lit("{}").jsonQuery("$", JsonQueryWrapper.CONDITIONAL_ARRAY) // "[{}]"
         lit("[1, 2]").jsonQuery("$", JsonQueryWrapper.CONDITIONAL_ARRAY) // "[1, 2]"
         lit("[1, 2]").jsonQuery("$", JsonQueryWrapper.UNCONDITIONAL_ARRAY) // "[[1, 2]]"
        
         // Scalars must be wrapped to be returned
         lit(1).jsonQuery("$") // null
         lit(1).jsonQuery("$", JsonQueryWrapper.CONDITIONAL_ARRAY) // "[1]"
        
         // Behavior if path expression is empty / there is an error
         // "{}"
         lit("{}").jsonQuery("lax $.invalid", JsonQueryWrapper.WITHOUT_ARRAY,
             JsonQueryOnEmptyOrError.EMPTY_OBJECT, JsonQueryOnEmptyOrError.NULL)
         // "[]"
         lit("{}").jsonQuery("strict $.invalid", JsonQueryWrapper.WITHOUT_ARRAY,
             JsonQueryOnEmptyOrError.NULL, JsonQueryOnEmptyOrError.EMPTY_ARRAY)
        
         // Return results as an array instead of a string
         lit("[1, 2]").jsonQuery("$", DataTypes.ARRAY(DataTypes.STRING()),
             JsonQueryWrapper.CONDITIONAL_ARRAY) // ["1", "2"]
         lit("[1, 2]").jsonQuery("$", DataTypes.ARRAY(DataTypes.STRING()),
             JsonQueryWrapper.UNCONDITIONAL_ARRAY) // ["[1, 2]"]
         
        Parameters:
        path - JSON path to search for.
        returnType - Type to convert the extracted array to, otherwise defaults to DataTypes.STRING().
        wrappingBehavior - Determine if and when to wrap the resulting value into an array.
        onEmpty - Behavior in case the path expression is empty.
        onError - Behavior in case of an error.
        Returns:
        The extracted JSON value.
      • jsonQuery

        public OutType jsonQuery​(String path,
                                 JsonQueryWrapper wrappingBehavior)
        Extracts JSON values from a JSON string.

        The {@param wrappingBehavior} determines whether the extracted value should be wrapped into an array, and whether to do so unconditionally or only if the value itself isn't an array already.

        See also jsonQuery(String, JsonQueryWrapper, JsonQueryOnEmptyOrError, JsonQueryOnEmptyOrError).

        Parameters:
        path - JSON path to search for.
        wrappingBehavior - Determine if and when to wrap the resulting value into an array.
        Returns:
        The extracted JSON value.
      • percentile

        public OutType percentile​(InType percentage,
                                  InType frequency)
        Returns the exact percentile value of expr at the specified percentage in a group.

        percentage must be a literal numeric value between [0.0, 1.0] or an array of such values. If a variable expression is passed to this function, the result will be calculated using any one of them.

        frequency describes how many times expr should be counted, the default value is 1.

        If no expr lies exactly at the desired percentile, the result is calculated using linear interpolation of the two nearest exprs. If expr or frequency is null, or frequency is not positive, the input row will be ignored.

        NOTE: It is recommended to use this function in a window scenario, as it typically offers better performance. In a regular group aggregation scenario, users should be aware of the performance overhead caused by a full sort triggered by each record.

        Parameters:
        percentage - A NUMERIC NOT NULL or ARRAY<NUMERIC NOT NULL> NOT NULL expression.
        frequency - An optional INTEGER_NUMERIC expression.
        Returns:
        A DOUBLE if percentage is numeric, or an ARRAY<DOUBLE> if percentage is an array. null if percentage is an empty array.