すべてのプロダクト
Search
ドキュメントセンター

Realtime Compute for Apache Flink:上位 N 件

最終更新日:Jan 08, 2025

このトピックでは、ジョブの上位 N 件のクエリを変更した後に、ジョブと、ジョブの開始に使用される状態データとの間の互換性について説明します。

互換性のある変更

  • 完全な互換性:パーティションキーの順序を変更します。

    -- 元の SQL ステートメント:
    select a, b, c from (
      select *,
       row_number() over (partition by a, b order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 完全な互換性: パーティションキーの順序を変更します。
    select a, b, c from (
      select *,
       row_number() over (partition by b, a order by c) as rk
       from MyTable)
    where rk < 3;
  • 完全な互換性:ランキング位置を指定するフィールドをクエリ結果に含めるか、または除外します。

    -- 元の SQL ステートメント:
    select a, b, c from (
      select *,
       row_number() over (partition by a order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 完全な互換性: クエリ結果に rk フィールドを含めます。
    select a, b, c, rk from (
      select *,
       row_number() over (partition by a order by c) as rk
       from MyTable)
    where rk < 3;

互換性のない変更

  • ランキングに UpdateFastRank アルゴリズムを使用し、アップストリームの upsert キーを変更します。

  • パーティションキーを追加、削除、または変更するか、パーティションキーに含まれるフィールドの計算ロジックを変更します。

    -- 元の SQL ステートメント:
    select a, b, c from (
      select *,
       row_number() over (partition by a order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 非互換: パーティションキーとして d を追加します。
    select a, b, c from (
      select *,
       row_number() over (partition by a, d order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 非互換: パーティションキーから a を削除します。
    select a, b, c from (
      select *,
       row_number() over (order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 非互換: パーティションキーを a から a + 1 に変更します。
    select a, b, c from (
      select *,
       row_number() over (partition by a order by c) as rk
       from (select a + 1 as a, b, c from MyTable))
    where rk < 3;
  • order by 句で指定されたフィールドまたは順序を変更します。

    -- 元の SQL ステートメント:
    select a, b, c from (
      select *,
       row_number() over (partition by a order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 非互換: 並べ替えに使用するフィールドを c から b に変更します。
    select a, b, c from (
      select *,
       row_number() over (partition by a order by b) as rk
       from MyTable)
    where rk < 3;
    
    -- 非互換: 並べ替えに使用するフィールドを c から substring(c, 1, 5) に変更します。
    select a, b, c from (
      select *,
       row_number() over (partition by a order by c) as rk
       from (select a, b, substring(c, 1, 5) as c from MyTable))
    where rk < 3;
    
    -- 非互換: 並べ替え順序を昇順から降順に変更します。
    select a, b, c from (
      select *,
       row_number() over (partition by a order by c desc) as rk
       from MyTable)
    where rk < 3;
  • N の値を変更します。上位 N 件のクエリでは、N は返される上位ランク結果の数を指定します。

    -- 元の SQL ステートメント:
    select a, b, c from (
      select *,
       row_number() over (partition by a order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 非互換: N の値を 3 から 5 に変更します。
    select a, b, c from (
      select *,
       row_number() over (partition by a order by c) as rk
       from MyTable)
    where rk < 5;
  • 上位 N 件のクエリで選択されたフィールドを追加、削除、または変更します。

    -- 元の SQL ステートメント:
    select a, b, c from (
      select *,
       row_number() over (partition by a order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 非互換: 選択されたフィールドに d を追加します。
    select a, b, c, d from (
      select *,
       row_number() over (partition by a order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 非互換: 選択されたフィールドから b を削除します。
    select a, c from (
      select *,
       row_number() over (partition by a order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 非互換: 選択されたフィールドを b から b + 1 に変更します。
    select a, b, c from (
      select *,
       row_number() over (partition by a order by c) as rk
       from (select a, b + 1 as b, c from MyTable))
    where rk < 3;