This topic describes how to use the FIRST_VALUE function. This function returns the first non-null record of a data stream.
Limits
This function is supported only in Realtime Compute for Apache Flink that uses Ververica Runtime (VVR) 3.0.0 or later.
Syntax
FIRST_VALUE( T value )
FIRST_VALUE( T value, BIGINT order )
Input parameters
Parameter | Data type | Description |
---|---|---|
value | Any data type | A data stream. Note If all input data is NULL, NULL is returned. |
order | BIGINT | The non-null record that has the smallest order value is considered the first non-null record. |
Important All input parameters must be of the same data type.
Example
- Test data
Table 1. T1 a(BIGINT) b(INT) c(VARCHAR) 1 1 Hello 2 2 Hello 3 3 Hello 4 4 Hello 5 5 Hello 6 6 Hello 7 7 NULL 8 7 Hello World 9 8 Hello World 10 20 Hello World - Test statement
SELECT c,FIRST_VALUE(b) OVER (PARTITION BY c ORDER BY PROCTIME() RANGE UNBOUNDED PRECEDING) AS var1 FROM T1;
- Test result
c(VARCHAR) var1(INT) Hello 1 Hello 1 Hello 1 Hello 1 Hello 1 Hello 1 NULL 7 Hello World 7 Hello World 7 Hello World 7