全部產品
Search
文件中心

Realtime Compute for Apache Flink:Top-N

更新時間:Jul 13, 2024

本文為您介紹Top-N變更的可相容性和不可相容性詳情。

可相容的變更

  • 修改partition key的順序,屬於完全相容變更。

    --原始
    select a, b, c from (
      select *,
       row_number() over (partition by a, b order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 修改partition key順序,屬於完全相容變更。
    select a, b, c from (
      select *,
       row_number() over (partition by b, a order by c) as rk
       from MyTable)
    where rk < 3;
  • 是否輸出rank number的值,不影響相容性,屬於完全相容。

    -- 原始SQL。
    select a, b, c from (
      select *,
       row_number() over (partition by a order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 輸出rank number欄位:rk,屬於完全相容。
    select a, b, c, rk from (
      select *,
       row_number() over (partition by a order by c) as rk
       from MyTable)
    where rk < 3;

不相容的變更

  • 如果rank是UpdateFastRank演算法,且上遊的Upsert Key發生了變化,屬於不相容變更。

  • 新增、刪除、修改partition by key或者partition by key涉及欄位的計算邏輯發生變化,屬於不相容變更。

    -- 原始SQL。
    select a, b, c from (
      select *,
       row_number() over (partition by a order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 新增partition by欄位:d,屬於不相容變更。
    select a, b, c from (
      select *,
       row_number() over (partition by a, d order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 刪除partition by欄位:a,屬於不相容變更。
    select a, b, c from (
      select *,
       row_number() over (order by c) as rk
       from MyTable)
    where rk < 3;
    
    -- 修改partition by欄位: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;
    
    -- 修改order key:c -> b,屬於不相容變更。
    select a, b, c from (
      select *,
       row_number() over (partition by a order by b) as rk
       from MyTable)
    where rk < 3;
    
    -- 修改order key: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;
    
    -- 修改order:asc -> desc,屬於不相容變更。
    select a, b, c from (
      select *,
       row_number() over (partition by a order by c desc) as rk
       from MyTable)
    where rk < 3;
  • 修改rank range的值(Top-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;
    
    -- 修改rank range:3 -> 5,屬於不相容變更。
    select a, b, c from (
      select *,
       row_number() over (partition by a order by c) as rk
       from MyTable)
    where rk < 5;
  • 修改了輸入欄位,屬於不相容變更。

    -- 原始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;