Windowing in Hive
Windowing in Hive allows an analyst to create a window of data to operate aggregation and other analytical functions, such as LEAD
and LAG
.
The windowing specification in HiveQL comprises:
Partition
Order by
Window frame
Source name for window definition
Let's look into each of these specifications in detail:
Partition specification: It includes a column reference from the table. It could not be any aggregation or other window specification.
Order specification: It comprises a combination of one or more columns. The ordering could be
ASC
orDESC
, which by default isASC
.Handling NULLs: There is no support for
Nulls
first or last specification. In Hive, Nulls are returned first.Window frame: A frame has a start boundary and an optional end boundary:
Frame type: Window frames could be any of the following types:
ROW
RANGE
Frame boundary: A frame is associated with a direction or an amount. A direction value could be
PRECEDING
orFOLLOWING
and the amount could be an integer value or...