IKH

Functions

In the previous segment, you learnt about various SQL functionalities that are supported by Flink. In this segment, you will take a look at some functions in the Table API and SQL.

Let’s summarise the topics covered in this video.
Flink allows users to perform data transformations with functions. The following  two types of functions are available in Flink:

System (built-in) functions

Flink provides users with built-in functions to perform transformations. Some of the built-in functions that are available are as follows:

  • Comparison functions: These functions are used to make a comparison between two elements such as equality, greater than and less than. 
  • Logical functions: These functions are used to perform logical operations such as OR, AND and NOT.
  • Arithmetic functions: These functions are used to perform arithmetic operations such as sum, absolute value, negative of a number and square root.
  • String functions: These functions are used to perform operations on Strings such as concatenation, change to uppercase or lowercase and trim.
  • Temporal functions: These functions are used to work with queries related to time such as date, time and current date.
  • Conditional functions: These are conditional statements and return the values that fulfil the specified conditions. IF, IF_DECIMAL and IS_DIGIT are some of the examples of conditional functions in SQL.

The following table presents the difference in syntax of the aforementioned function in the Table API and SQL.

FunctionTable APISQL
Comparisonvalue1 === value2value1 = value2
LogicalBOOLEAN1 || BOOLEAN2boolean1 OR boolean2
ArithmeticNUMERIC_VALUE.abs()ABS(numeric_value)
StringSTRING_VALUE.upperCase()UPPER(string_value)
TemporalcurrentDate()CURRENT_DATE


Various other built-in functions are available. You can read about them in detail here.

User-defined functions

If a user needs a function that is not available as a built-in function, then it can be implemented using user-defined functions. These functions can be implemented in Java, Scala or Python. Third-party libraries can be used inside user-defined functions.

Report an error