全部产品
Search
文档中心

Realtime Compute for Apache Flink:GENERATE_SERIES

更新时间:Jun 19, 2025

Topik ini menjelaskan penggunaan fungsi GENERATE_SERIES untuk menghasilkan serangkaian bilangan bulat berturut-turut di antara dua angka.

Sintaksis

GENERATE_SERIES(BIGINT from, BIGINT to)

Parameter input

Parameter

Keterangan

from

Batas bawah inklusif dari rangkaian nilai. Tipe data: BIGINT

to

Batas atas inklusif dari rangkaian nilai. Tipe data: BIGINT

Contoh

  • Data Uji

    s(BIGINT NOT NULL)

    e(BIGINT NOT NULL)

    1

    3

    -2

    1

  • Kode Uji

    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);
  • Hasil Uji

    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