本文為您介紹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發(fā)生了變化,屬于不兼容變更。
新增、刪除、修改partition by key或者partition by key涉及字段的計算邏輯發(fā)生變化,屬于不兼容變更。
-- 原始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;
文檔內容是否對您有幫助?