全部產品
Search
文件中心

Realtime Compute for Apache Flink:GENERATE_SERIES

更新時間:Jul 13, 2024

本文為您介紹如何使用GENERATE_SERIES函數,按from、from+1、from+2 … to-1的規則,產生一系列填充資料。

使用限制

僅Realtime Compute引擎VVR 3.0.0及以上版本支援GENERATE_SERIES函數。

文法

GENERATE_SERIES(BIGINT from, BIGINT to)

入參

參數

資料類型

from

BIGINT類型,指定下界,包含下界值。

to

BIGINT類型,指定上界,不包含上界值。

樣本

  • 測試資料

    表 1. T1

    s(BIGINT NOT NULL)

    e(BIGINT NOT NULL)

    1

    3

    -2

    1

  • 測試語句

    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);
  • 測試結果

    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