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 ss as
(select s_store_sk,
sum(ss_ext_sales_price) as sales,
sum(ss_net_profit) as profit
from store_sales,
date_dim,
store
where ss_sold_date_sk = d_date_sk
and d_date between cast('1998-08-04' as date)
and (cast('1998-08-04' as date) + interval 30 days)
and ss_store_sk = s_store_sk
group by s_store_sk)
,
sr as
(select s_store_sk,
sum(sr_return_amt) as returns,
sum(sr_net_loss) as profit_loss
from store_returns,
date_dim,
store
where sr_returned_date_sk = d_date_sk
and d_date between cast('1998-08-04' as date)
and (cast('1998-08-04' as date) + interval 30 days)
and sr_store_sk = s_store_sk
group by s_store_sk),
cs as
(select cs_call_center_sk,
sum(cs_ext_sales_price) as sales,
sum(cs_net_profit) as profit
from catalog_sales,
date_dim
where cs_sold_date_sk = d_date_sk
and d_date between cast('1998-08-04' as date)
and (cast('1998-08-04' as date) + interval 30 days)
group by cs_call_center_sk
),
cr as
(select cr_call_center_sk,
sum(cr_return_amount) as returns,
sum(cr_net_loss) as profit_loss
from catalog_returns,
date_dim
where cr_returned_date_sk = d_date_sk
and d_date between cast('1998-08-04' as date)
and (cast('1998-08-04' as date) + interval 30 days)
group by cr_call_center_sk
),
ws as
( select wp_web_page_sk,
sum(ws_ext_sales_price) as sales,
sum(ws_net_profit) as profit
from web_sales,
date_dim,
web_page
where ws_sold_date_sk = d_date_sk
and d_date between cast('1998-08-04' as date)
and (cast('1998-08-04' as date) + interval 30 days)
and ws_web_page_sk = wp_web_page_sk
group by wp_web_page_sk),
wr as
(select wp_web_page_sk,
sum(wr_return_amt) as returns,
sum(wr_net_loss) as profit_loss
from web_returns,
date_dim,
web_page
where wr_returned_date_sk = d_date_sk
and d_date between cast('1998-08-04' as date)
and (cast('1998-08-04' as date) + interval 30 days)
and wr_web_page_sk = wp_web_page_sk
group by wp_web_page_sk)
select channel
, id
, sum(sales) as sales
, sum(returns) as returns
, sum(profit) as profit
from
(select 'store channel' as channel
, ss.s_store_sk as id
, sales
, coalesce(returns, 0) as returns
, (profit - coalesce(profit_loss,0)) as profit
from ss left join sr
on ss.s_store_sk = sr.s_store_sk
union all
select 'catalog channel' as channel
, cs_call_center_sk as id
, sales
, returns
, (profit - profit_loss) as profit
from cs
, cr
union all
select 'web channel' as channel
, ws.wp_web_page_sk as id
, sales
, coalesce(returns, 0) returns
, (profit - coalesce(profit_loss,0)) as profit
from ws left join wr
on ws.wp_web_page_sk = wr.wp_web_page_sk
) x
group by rollup (channel, id)
order by channel
,id
limit 100
-- !query schema
struct<channel:string,id:bigint,sales:decimal(27,2),returns:decimal(27,2),profit:decimal(28,2)>
-- !query output
NULL NULL 1073038.40 107655.02 -423054.27
store channel 1 72083.73 8104.15 -46175.32
store channel 10 114736.79 3082.76 -71042.45
store channel 2 82495.65 2323.02 -42419.17
store channel 4 137775.87 4355.14 -62412.45
store channel 7 92283.44 2857.84 -37776.34
store channel 8 215863.27 1415.13 -73034.57
store channel NULL 715238.75 22138.04 -332860.30
web channel 1 10562.51 77.64 -2673.30
web channel 10 10801.35 1297.48 2824.82
web channel 13 34815.44 9473.25 1614.60
web channel 14 5431.79 1812.37 186.81
web channel 16 21371.89 11.52 5424.48
web channel 19 10439.66 2864.25 -4739.74
web channel 2 5530.88 0.00 -1408.72
web channel 20 6437.96 4339.50 -12766.91
web channel 22 11333.57 2604.70 2192.87
web channel 25 19351.49 0.00 -7804.65
web channel 26 3658.06 5023.68 -3504.07
web channel 28 5611.14 62.40 -688.04
web channel 31 2645.58 4987.36 -765.72
web channel 32 11956.20 2463.81 -6361.51
web channel 34 6109.59 2283.70 -328.83
web channel 37 25890.99 995.32 4090.06
web channel 38 18795.16 303.80 -1620.01
web channel 4 661.57 0.00 -361.27
web channel 40 13069.37 3627.48 -3153.28
web channel 43 6329.56 27.04 -8828.26
web channel 44 30668.64 2694.87 -71.37
web channel 46 3331.97 1582.02 -120.51
web channel 49 1006.26 0.00 -10204.29
web channel 50 13469.80 9843.69 -16661.70
web channel 52 17368.43 9031.65 -13343.03
web channel 55 2280.72 10922.91 -5933.85
web channel 56 4761.93 0.00 143.21
web channel 58 9182.32 8392.30 -3532.39
web channel 7 31393.85 0.00 3862.05
web channel 8 13531.97 794.24 -5661.42
web channel NULL 357799.65 85516.98 -90193.97