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

ParameterData typeDescription
valueAny data typeA data stream.
Note If all input data is NULL, NULL is returned.
orderBIGINTThe 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)
    11Hello
    22Hello
    33Hello
    44Hello
    55Hello
    66Hello
    77NULL
    87Hello World
    98Hello World
    1020Hello 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)
    Hello1
    Hello1
    Hello1
    Hello1
    Hello1
    Hello1
    NULL7
    Hello World7
    Hello World7
    Hello World7