【问题标题】:Why compute row_number() order by monotonically_increasing_id() in Spark?为什么在 Spark 中通过 monotonically_increasing_id() 计算 row_number() 顺序?
【发布时间】:2022-10-31 14:42:20
【问题描述】:

建议您可以'generate unique increasing numeric values' by

select row_number() over (order by monotonically_increasing_id()) from /* ... */

但你也可以这样做:

select row_number() over (order by 1) from /* ... */

在这种情况下,使用monotonically_increasing_id() 有什么好处?

【问题讨论】:

    标签: apache-spark apache-spark-sql


    【解决方案1】:

    monotonically_increasing_id() 保证 id 不断增加,但不保证它们是连续的。

    生成的ID保证单调递增且唯一,但是不连续。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-06
      • 1970-01-01
      • 2021-05-06
      • 2017-12-29
      • 1970-01-01
      • 1970-01-01
      • 2021-07-25
      • 1970-01-01
      相关资源
      最近更新 更多