All Products
Search
Document Center

Realtime Compute for Apache Flink:GENERATE_SERIES

Last Updated:Nov 20, 2024

This topic describes how to use the GENERATE_SERIES function to generate a series of consecutive integers between two numbers.

Syntax

GENERATE_SERIES(BIGINT from, BIGINT to)

Input parameters

Parameter

Remarks

from

The inclusive lower bound of the series of values. Data type: BIGINT

to

The inclusive upper bound of the series of values. Data type: BIGINT

Example

  • Test data

    s(BIGINT NOT NULL)

    e(BIGINT NOT NULL)

    1

    3

    -2

    1

  • Test code

    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