World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
-- Automatically generated by Gravitino Spark SQL test
-- !query
with ssr as
(select s_store_id,
sum(sales_price) as sales,
sum(profit) as profit,
sum(return_amt) as returns,
sum(net_loss) as profit_loss
from
((select ss_store_sk as store_sk,
ss_sold_date_sk as date_sk,
ss_ext_sales_price as sales_price,
ss_net_profit as profit,
cast(0 as decimal(7,2)) as return_amt,
cast(0 as decimal(7,2)) as net_loss
from store_sales)
union all
(select sr_store_sk as store_sk,
sr_returned_date_sk as date_sk,
cast(0 as decimal(7,2)) as sales_price,
cast(0 as decimal(7,2)) as profit,
sr_return_amt as return_amt,
sr_net_loss as net_loss
from store_returns)
)
salesreturns,
date_dim,
store
where date_sk = d_date_sk
and d_date between cast('1998-08-04' as date)
and (cast('1998-08-04' as date) + interval 14 days)
and store_sk = s_store_sk
group by s_store_id)
,
csr as
(select cp_catalog_page_id,
sum(sales_price) as sales,
sum(profit) as profit,
sum(return_amt) as returns,
sum(net_loss) as profit_loss
from
( (select cs_catalog_page_sk as page_sk,
cs_sold_date_sk as date_sk,
cs_ext_sales_price as sales_price,
cs_net_profit as profit,
cast(0 as decimal(7,2)) as return_amt,
cast(0 as decimal(7,2)) as net_loss
from catalog_sales)
union all
(select cr_catalog_page_sk as page_sk,
cr_returned_date_sk as date_sk,
cast(0 as decimal(7,2)) as sales_price,
cast(0 as decimal(7,2)) as profit,
cr_return_amount as return_amt,
cr_net_loss as net_loss
from catalog_returns)
) salesreturns,
date_dim,
catalog_page
where date_sk = d_date_sk
and d_date between cast('1998-08-04' as date)
and (cast('1998-08-04' as date) + interval 14 days)
and page_sk = cp_catalog_page_sk
group by cp_catalog_page_id)
,
wsr as
(select web_site_id,
sum(sales_price) as sales,
sum(profit) as profit,
sum(return_amt) as returns,
sum(net_loss) as profit_loss
from
( (select ws_web_site_sk as wsr_web_site_sk,
ws_sold_date_sk as date_sk,
ws_ext_sales_price as sales_price,
ws_net_profit as profit,
cast(0 as decimal(7,2)) as return_amt,
cast(0 as decimal(7,2)) as net_loss
from web_sales)
union all
(select ws_web_site_sk as wsr_web_site_sk,
wr_returned_date_sk as date_sk,
cast(0 as decimal(7,2)) as sales_price,
cast(0 as decimal(7,2)) as profit,
wr_return_amt as return_amt,
wr_net_loss as net_loss
from web_returns left outer join web_sales on
( wr_item_sk = ws_item_sk
and wr_order_number = ws_order_number))
) salesreturns,
date_dim,
web_site
where date_sk = d_date_sk
and d_date between cast('1998-08-04' as date)
and (cast('1998-08-04' as date) + interval 14 days)
and wsr_web_site_sk = web_site_sk
group by web_site_id)
select channel
, id
, sum(sales) as sales
, sum(returns) as returns
, sum(profit) as profit
from
((select 'store channel' as channel
, concat('store' , s_store_id) as id
, sales
, returns
, (profit - profit_loss) as profit
from ssr)
union all
(select 'catalog channel' as channel
, concat('catalog_page' , cp_catalog_page_id) as id
, sales
, returns
, (profit - profit_loss) as profit
from csr)
union all
(select 'web channel' as channel
, concat('web_site' , web_site_id) as id
, sales
, returns
, (profit - profit_loss) as profit
from wsr)
) x
group by rollup (channel, id)
order by channel
,id
limit 100
-- !query schema
struct<channel:string,id:string,sales:decimal(27,2),returns:decimal(27,2),profit:decimal(28,2)>
-- !query output
NULL NULL 506679.85 17261.00 -203531.74
catalog channel NULL 0.00 4899.24 NULL
catalog channel catalog_pageAAAAAAAAABAAAAAA 0.00 73.57 NULL
catalog channel catalog_pageAAAAAAAABAAAAAAA 0.00 254.90 NULL
catalog channel catalog_pageAAAAAAAABBAAAAAA 0.00 405.75 NULL
catalog channel catalog_pageAAAAAAAACAAAAAAA 0.00 800.00 NULL
catalog channel catalog_pageAAAAAAAACBAAAAAA 0.00 440.89 NULL
catalog channel catalog_pageAAAAAAAADAAAAAAA 0.00 78.70 NULL
catalog channel catalog_pageAAAAAAAADBAAAAAA 0.00 147.78 NULL
catalog channel catalog_pageAAAAAAAAEAAAAAAA 0.00 17.65 NULL
catalog channel catalog_pageAAAAAAAAEBAAAAAA 0.00 660.05 NULL
catalog channel catalog_pageAAAAAAAAFAAAAAAA 0.00 443.41 NULL
catalog channel catalog_pageAAAAAAAAGAAAAAAA 0.00 217.73 NULL
catalog channel catalog_pageAAAAAAAAHAAAAAAA 0.00 0.07 NULL
catalog channel catalog_pageAAAAAAAAIAAAAAAA 0.00 451.36 NULL
catalog channel catalog_pageAAAAAAAAJAAAAAAA 0.00 89.34 NULL
catalog channel catalog_pageAAAAAAAAKAAAAAAA 0.00 105.34 NULL
catalog channel catalog_pageAAAAAAAALAAAAAAA 0.00 30.43 NULL
catalog channel catalog_pageAAAAAAAAMAAAAAAA 0.00 224.03 NULL
catalog channel catalog_pageAAAAAAAANAAAAAAA 0.00 51.12 NULL
catalog channel catalog_pageAAAAAAAAOAAAAAAA 0.00 257.48 NULL
catalog channel catalog_pageAAAAAAAAPAAAAAAA 0.00 149.64 NULL
store channel NULL 371201.09 11952.47 -178708.59
store channel storeAAAAAAAABAAAAAAA 10712.16 3385.56 -4845.39
store channel storeAAAAAAAACAAAAAAA 82495.65 364.92 -39994.20
store channel storeAAAAAAAAEAAAAAAA 57571.92 3409.81 -41886.17
store channel storeAAAAAAAAHAAAAAAA 80649.95 1279.82 -21820.22
store channel storeAAAAAAAAIAAAAAAA 98532.73 1104.48 -37771.78
store channel storeAAAAAAAAKAAAAAAA 41238.68 2407.88 -32390.83
web channel NULL 135478.76 409.29 -24823.15
web channel web_siteAAAAAAAAABAAAAAA 5131.57 0.00 -1670.96
web channel web_siteAAAAAAAABAAAAAAA 6968.33 25.05 -8935.97
web channel web_siteAAAAAAAACAAAAAAA 1388.50 0.00 -1396.78
web channel web_siteAAAAAAAADBAAAAAA 12384.81 0.00 6480.74
web channel web_siteAAAAAAAAEAAAAAAA 16.70 0.00 2.60
web channel web_siteAAAAAAAAEBAAAAAA 8501.68 0.00 -10879.22
web channel web_siteAAAAAAAAGBAAAAAA 22569.13 0.00 6032.06
web channel web_siteAAAAAAAAHAAAAAAA 14390.23 0.00 -2174.13
web channel web_siteAAAAAAAAIAAAAAAA 11451.48 0.00 -1405.63
web channel web_siteAAAAAAAAJBAAAAAA 8.96 0.00 -107.84
web channel web_siteAAAAAAAAKAAAAAAA 13771.31 0.00 2545.76
web channel web_siteAAAAAAAAKBAAAAAA 16188.14 0.00 -2769.41
web channel web_siteAAAAAAAAMBAAAAAA 15808.72 384.24 -6086.85
web channel web_siteAAAAAAAANAAAAAAA 5063.13 0.00 -5074.70
web channel web_siteAAAAAAAAOAAAAAAA 1836.07 0.00 617.18