窗口功能的默认窗口框架是什么 [英] What's the default window frame for window functions

查看:89
本文介绍了窗口功能的默认窗口框架是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行以下代码:

val sales = Seq(
  (0, 0, 0, 5),
  (1, 0, 1, 3),
  (2, 0, 2, 1),
  (3, 1, 0, 2),
  (4, 2, 0, 8),
  (5, 2, 2, 8))
  .toDF("id", "orderID", "prodID", "orderQty")

val orderedByID = Window.orderBy('id)

val totalQty = sum('orderQty).over(orderedByID).as('running_total)
val salesTotalQty = sales.select('*, totalQty).orderBy('id)
salesTotalQty.show

结果是:

+---+-------+------+--------+-------------+
| id|orderID|prodID|orderQty|running_total|
+---+-------+------+--------+-------------+
|  0|      0|     0|       5|            5|
|  1|      0|     1|       3|            8|
|  2|      0|     2|       1|            9|
|  3|      1|     0|       2|           11|
|  4|      2|     0|       8|           19|
|  5|      2|     2|       8|           27|
+---+-------+------+--------+-------------+

上面的代码中没有定义窗口框架,它看起来默认的窗口框架是rowsBetween(Window.unboundedPreceding, Window.currentRow)

There is no window frame defined in the above code, it looks the default window frame is rowsBetween(Window.unboundedPreceding, Window.currentRow)

不确定我对默认窗口框架的理解是否正确

Not sure my understanding about default window frame is correct

推荐答案

来自

默认帧规格取决于给定窗口定义的其他方面:

Default frame specification depends on other aspects of a given window defintion:

  • 如果指定了ORDER BY子句并且该函数接受了帧规范,则该帧规范是由RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW定义的,
  • 否则,帧规格由未绑定的前导和未绑定的跟随之间的行定义.

这篇关于窗口功能的默认窗口框架是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆