If your work involves heavy OLAP queries, you need to know about grouping sets and roll ups. Unified Analytics supports
grouping sets with rollups and grouping functions.
You created a Unified Analytics Virtual Warehouse based on a Database Catalog that loads
the sample data to run queries of airline data.
-
Log into the Data Warehouse service as DWUser.
-
Go to the Virtual Warehouses tab, locate the Virtual Warehouse
using which you want to run queries, and click HUE.
The Hue query editor opens in a new browser tab.
-
Select a database.
-
In Hue, select either the Impala or Hive editor.
-
Run a query that determines the number of flights per country and state.
SELECT
a.country,
a.state,
grouping(a.country)
grouping(a.state)
SUM(f.Distance),
COUNT(*)
FROM
flights f,
airports a
WHERE
f.origin = a.iata
GROUP BY
a.country,
a.state
WITH ROLLUP;
-
Run a query that defines custom grouping sets: country and country/state.
SELECT
a.country,
a.state,
grouping(a.country)
grouping(a.state)
SUM(f.Distance),
COUNT(*)
FROM
flights f,
airports a
WHERE
f.origin = a.iata
GROUP BY
a.country,
a.state
GROUPING SETS (
(a.country),
(a.country, a.state)
);