The OVER clause
More Example are available here: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+WindowingAndAnalytics
- OVER with standard aggregates:
- COUNT
- SUM
- MIN
- MAX
- AVG
- OVER with a PARTITION BY statement with one or more partitioning columns of any primitive datatype.
- OVER with PARTITION BY and ORDER BY with one or more partitioning and/or ordering columns of any datatype.
- OVER with a window specification. Windows can be defined separately in a WINDOW clause. Window specifications support the following formats:
(ROWS | RANGE) BETWEEN (UNBOUNDED | [num]) PRECEDING AND ([num] PRECEDING | CURRENT ROW | (UNBOUNDED | [num]) FOLLOWING) (ROWS | RANGE) BETWEEN CURRENT ROW AND (CURRENT ROW | (UNBOUNDED | [num]) FOLLOWING) (ROWS | RANGE) BETWEEN [num] FOLLOWING AND (UNBOUNDED | [num]) FOLLOWING
When ORDER BY is specified with missing WINDOW clause, the WINDOW specification defaults toRANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.
When both ORDER BY and WINDOW clauses are missing, the WINDOW specification defaults toROW BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING.
PARTITION BY with one partitioning column, no ORDER BY or window specification
PARTITION BY with two partitioning columns, no ORDER BY or window specification
PARTITION BY with one partitioning column, one ORDER BY column, and no window specification
PARTITION BY with two partitioning columns, two ORDER BY columns, and no window specification
PARTITION BY with partitioning, ORDER BY, and window specification
There can be multiple
OVER
clauses in a single query. A single OVER
clause only applies to the immediately preceding function call. In this example, the first OVER clause applies to COUNT(b) and the second OVER clause applies to SUM(b):
Aliases can be used as well, with or without the keyword AS:
WINDOW clause
Distinct counting for each partition
More Example are available here: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+WindowingAndAnalytics
No comments:
Post a Comment