All Products
Search
Document Center

Realtime Compute for Apache Flink:GENERATE_SERIES

Last Updated:May 26, 2023

This topic describes how to use the GENERATE_SERIES function. This function generates a series of padding data based on the rule of from, from+1, from+2 ... to-1.

Limits

This function is supported only in Realtime Compute for Apache Flink that uses Ververica Runtime (VVR) 3.0.0 or later.

Syntax

GENERATE_SERIES(BIGINT from, BIGINT to)

Input parameters

Parameter

Data type

from

The lower boundary of a series of values, including the lower boundary. This parameter is of the BIGINT type.

to

The upper boundary of a series of values, excluding the upper boundary. This parameter is of the BIGINT type.

Example

  • Test data

    Table 1. T1

    s(BIGINT NOT NULL)

    e(BIGINT NOT NULL)

    1

    3

    -2

    1

  • Test statement

    CREATE TEMPORARY TABLE input_table(
      s BIGINT NOT NULL, 
      e BIGINT NOT NULL
    ) WITH (
      'connector' = 'datagen'
    );
    
    CREATE TEMPORARY TABLE output_table(
      s BIGINT NOT NULL, 
      e BIGINT NOT NULL, 
      v BIGINT NOT NULL
    ) WITH (
      'connector' = 'print'
    );
    
    insert into output_table
    SELECT s, e, v FROM input_table, lateral table(GENERATE_SERIES(s, e))
    as t(v);
  • Test result

    s(BIGINT)

    e(BIGINT)

    v(BIGINT)

    1

    3

    1

    1

    3

    2

    1

    3

    3

    -2

    1

    -2

    -2

    1

    -1

    -2

    1

    0

    -2

    1

    1