on 03-04-2015 1:27 PM
Hi folks,
I'm new to SAP HANA and need your help with understanding how GROUPING SETS on HANA works.
By executing of this statement
SELECT COUNTRY, LANGU, "SHORT TEXT",
GROUPING(COUNTRY), GROUPING(LANGU), GROUPING("SHORT TEXT"),
GROUPING_ID(COUNTRY, LANGU, "SHORT TEXT")
FROM COUNTRIES
GROUP BY GROUPING SETS ((COUNTRY, LANGU), (LANGU, "SHORT TEXT"))
on this raw table
COUNTRY | LANGU | SHORT TEXT |
---|---|---|
DE | D | Deutschland |
DE | E | Germany |
US | D | USA |
US | E | USA |
I'm getting these results:
COUNTRY | LANGU | SHORT TEXT | GROUPING(COUNTRY) | GROUPING(LANGU) | GROUPING(SHORT TEXT) | GROUPING_ID |
---|---|---|---|---|---|---|
DE | D | ? | 0 | 0 | 1 | 1 |
US | D | ? | 0 | 0 | 1 | 1 |
DE | E | ? | 0 | 0 | 1 | 1 |
US | E | ? | 0 | 0 | 1 | 1 |
? | D | Deutschland | 1 | 0 | 0 | 4 |
? | E | Germany | 1 | 0 | 0 | 4 |
? | D | USA | 1 | 0 | 0 | 4 |
? | E | USA | 1 | 0 | 0 | 4 |
Two questions raised here:
Regards,
Oleg
See GROUPING_ID - SAP HANA SQL and System Views Reference - SAP Library
and GROUPING - SAP HANA SQL and System Views Reference - SAP Library
Indeed the output of GROUPING seems to be exactly inverted to what the documentation tells us.
In this example GROUPING returns 0 for columns used in the current grouping.
GROUPING_ID seems to be calculated correctly though:
first group : ((COUNTRY, LANGU, "SHORT TEXT"))
bit vector: 0 0 1 -> 001 -> 1
second group: ((COUNTRY, LANGU , "SHORT TEXT"))
bit vector: 1 0 0 -> 100 -> 4
- Lars
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
FYI I found a couple of bugs with GROUPING about a month ago and raised an internal bug.
The 2 issues are...
1. GROUPING( <column name> ) returns 1 when should be 0 and 0 when should be 1
2. GROUPING can return values > 1.
Good news - the issue has been fixed internally so is just waiting to be merged into internal releases/testing etc.
regards,
Alan
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.