Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

11.3 KB
Raw Blame
-- Automatically generated by Gravitino Spark SQL test
-- !query
with  cross_items as
 (select i_item_sk ss_item_sk
 from item,
 (select iss.i_brand_id brand_id
     ,iss.i_class_id class_id
     ,iss.i_category_id category_id
 from store_sales
     ,item iss
     ,date_dim d1
 where ss_item_sk = iss.i_item_sk
   and ss_sold_date_sk = d1.d_date_sk
   and d1.d_year between 1998 AND 1998 + 2
 intersect 
 select ics.i_brand_id
     ,ics.i_class_id
     ,ics.i_category_id
 from catalog_sales
     ,item ics
     ,date_dim d2
 where cs_item_sk = ics.i_item_sk
   and cs_sold_date_sk = d2.d_date_sk
   and d2.d_year between 1998 AND 1998 + 2
 intersect
 select iws.i_brand_id
     ,iws.i_class_id
     ,iws.i_category_id
 from web_sales
     ,item iws
     ,date_dim d3
 where ws_item_sk = iws.i_item_sk
   and ws_sold_date_sk = d3.d_date_sk
   and d3.d_year between 1998 AND 1998 + 2)
 where i_brand_id = brand_id
      and i_class_id = class_id
      and i_category_id = category_id
),
 avg_sales as
 (select avg(quantity*list_price) average_sales
  from (select ss_quantity quantity
             ,ss_list_price list_price
       from store_sales
           ,date_dim
       where ss_sold_date_sk = d_date_sk
         and d_year between 1998 and 1998 + 2
       union all 
       select cs_quantity quantity 
             ,cs_list_price list_price
       from catalog_sales
           ,date_dim
       where cs_sold_date_sk = d_date_sk
         and d_year between 1998 and 1998 + 2 
       union all
       select ws_quantity quantity
             ,ws_list_price list_price
       from web_sales
           ,date_dim
       where ws_sold_date_sk = d_date_sk
         and d_year between 1998 and 1998 + 2) x)
  select  channel, i_brand_id,i_class_id,i_category_id,sum(sales), sum(number_sales)
 from(
       select 'store' channel, i_brand_id,i_class_id
             ,i_category_id,sum(ss_quantity*ss_list_price) sales
             , count(*) number_sales
       from store_sales
           ,item
           ,date_dim
       where ss_item_sk in (select ss_item_sk from cross_items)
         and ss_item_sk = i_item_sk
         and ss_sold_date_sk = d_date_sk
         and d_year = 1998+2 
         and d_moy = 11
       group by i_brand_id,i_class_id,i_category_id
       having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)
       union all
       select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales
       from catalog_sales
           ,item
           ,date_dim
       where cs_item_sk in (select ss_item_sk from cross_items)
         and cs_item_sk = i_item_sk
         and cs_sold_date_sk = d_date_sk
         and d_year = 1998+2 
         and d_moy = 11
       group by i_brand_id,i_class_id,i_category_id
       having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales)
       union all
       select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales
       from web_sales
           ,item
           ,date_dim
       where ws_item_sk in (select ss_item_sk from cross_items)
         and ws_item_sk = i_item_sk
         and ws_sold_date_sk = d_date_sk
         and d_year = 1998+2
         and d_moy = 11
       group by i_brand_id,i_class_id,i_category_id
       having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales)
 ) y
 group by rollup (channel, i_brand_id,i_class_id,i_category_id)
 order by channel,i_brand_id,i_class_id,i_category_id
 limit 100
-- !query schema
struct<channel:string,i_brand_id:bigint,i_class_id:bigint,i_category_id:bigint,sum(sales):decimal(38,2),sum(number_sales):bigint>
-- !query output
NULL	NULL	NULL	NULL	3049499.94	651
store	1001001	1	1	31885.81	9
store	1001001	1	NULL	31885.81	9
store	1001001	NULL	NULL	31885.81	9
store	1001002	1	1	61750.09	11
store	1001002	1	NULL	61750.09	11
store	1001002	NULL	NULL	61750.09	11
store	1002001	2	1	61869.73	12
store	1002001	2	NULL	61869.73	12
store	1002001	NULL	NULL	61869.73	12
store	1002002	2	1	31670.46	10
store	1002002	2	NULL	31670.46	10
store	1002002	NULL	NULL	31670.46	10
store	1003001	3	1	15865.08	5
store	1003001	3	NULL	15865.08	5
store	1003001	NULL	NULL	15865.08	5
store	1003002	3	1	11884.96	6
store	1003002	3	NULL	11884.96	6
store	1003002	NULL	NULL	11884.96	6
store	1004001	4	1	27032.32	8
store	1004001	4	NULL	27032.32	8
store	1004001	NULL	NULL	27032.32	8
store	1004002	4	1	46872.89	11
store	1004002	4	NULL	46872.89	11
store	1004002	NULL	NULL	46872.89	11
store	2001001	1	2	23132.36	11
store	2001001	1	NULL	23132.36	11
store	2001001	NULL	NULL	23132.36	11
store	2001002	1	2	28347.00	9
store	2001002	1	NULL	28347.00	9
store	2001002	NULL	NULL	28347.00	9
store	2002001	2	2	32545.94	8
store	2002001	2	NULL	32545.94	8
store	2002001	NULL	NULL	32545.94	8
store	2002002	2	2	42168.51	10
store	2002002	2	NULL	42168.51	10
store	2002002	NULL	NULL	42168.51	10
store	2003001	3	2	20829.36	7
store	2003001	3	NULL	20829.36	7
store	2003001	NULL	NULL	20829.36	7
store	2003002	3	2	48988.72	9
store	2003002	3	NULL	48988.72	9
store	2003002	NULL	NULL	48988.72	9
store	2004001	4	2	20678.69	7
store	2004001	4	NULL	20678.69	7
store	2004001	NULL	NULL	20678.69	7
store	2004002	4	2	63959.64	18
store	2004002	4	NULL	63959.64	18
store	2004002	NULL	NULL	63959.64	18
store	3001001	1	3	36344.04	9
store	3001001	1	NULL	36344.04	9
store	3001001	NULL	NULL	36344.04	9
store	3001002	1	3	29346.66	4
store	3001002	1	NULL	29346.66	4
store	3001002	NULL	NULL	29346.66	4
store	3002001	2	3	28054.56	10
store	3002001	2	NULL	28054.56	10
store	3002001	NULL	NULL	28054.56	10
store	3002002	2	3	56050.29	12
store	3002002	2	NULL	56050.29	12
store	3002002	NULL	NULL	56050.29	12
store	3003001	3	3	82327.31	20
store	3003001	3	NULL	82327.31	20
store	3003001	NULL	NULL	82327.31	20
store	3003002	3	3	37370.63	8
store	3003002	3	NULL	37370.63	8
store	3003002	NULL	NULL	37370.63	8
store	3004001	4	3	32091.61	6
store	3004001	4	NULL	32091.61	6
store	3004001	NULL	NULL	32091.61	6
store	3004002	4	3	34101.88	10
store	3004002	4	NULL	34101.88	10
store	3004002	NULL	NULL	34101.88	10
store	4001001	1	4	59345.06	12
store	4001001	1	NULL	59345.06	12
store	4001001	NULL	NULL	59345.06	12
store	4001002	1	4	35633.96	12
store	4001002	1	NULL	35633.96	12
store	4001002	NULL	NULL	35633.96	12
store	4002001	2	4	30512.88	9
store	4002001	2	NULL	30512.88	9
store	4002001	NULL	NULL	30512.88	9
store	4002002	2	4	54833.60	14
store	4002002	2	NULL	54833.60	14
store	4002002	NULL	NULL	54833.60	14
store	4003001	3	4	10725.35	2
store	4003001	3	NULL	10725.35	2
store	4003001	NULL	NULL	10725.35	2
store	4003002	3	4	29130.98	11
store	4003002	3	NULL	29130.98	11
store	4003002	NULL	NULL	29130.98	11
store	4004001	4	4	47820.24	11
store	4004001	4	NULL	47820.24	11
store	4004001	NULL	NULL	47820.24	11
store	4004002	4	4	75503.48	14
store	4004002	4	NULL	75503.48	14
store	4004002	NULL	NULL	75503.48	14
store	5001001	1	NULL	34458.91	10
store	5001001	NULL	NULL	34458.91	10
store	NULL	NULL	NULL	2414735.62	556


-- !query
with  cross_items as
 (select i_item_sk ss_item_sk
 from item,
 (select iss.i_brand_id brand_id
     ,iss.i_class_id class_id
     ,iss.i_category_id category_id
 from store_sales
     ,item iss
     ,date_dim d1
 where ss_item_sk = iss.i_item_sk
   and ss_sold_date_sk = d1.d_date_sk
   and d1.d_year between 1998 AND 1998 + 2
 intersect
 select ics.i_brand_id
     ,ics.i_class_id
     ,ics.i_category_id
 from catalog_sales
     ,item ics
     ,date_dim d2
 where cs_item_sk = ics.i_item_sk
   and cs_sold_date_sk = d2.d_date_sk
   and d2.d_year between 1998 AND 1998 + 2
 intersect
 select iws.i_brand_id
     ,iws.i_class_id
     ,iws.i_category_id
 from web_sales
     ,item iws
     ,date_dim d3
 where ws_item_sk = iws.i_item_sk
   and ws_sold_date_sk = d3.d_date_sk
   and d3.d_year between 1998 AND 1998 + 2) x
 where i_brand_id = brand_id
      and i_class_id = class_id
      and i_category_id = category_id
),
 avg_sales as
(select avg(quantity*list_price) average_sales
  from (select ss_quantity quantity
             ,ss_list_price list_price
       from store_sales
           ,date_dim
       where ss_sold_date_sk = d_date_sk
         and d_year between 1998 and 1998 + 2
       union all
       select cs_quantity quantity
             ,cs_list_price list_price
       from catalog_sales
           ,date_dim
       where cs_sold_date_sk = d_date_sk
         and d_year between 1998 and 1998 + 2
       union all
       select ws_quantity quantity
             ,ws_list_price list_price
       from web_sales
           ,date_dim
       where ws_sold_date_sk = d_date_sk
         and d_year between 1998 and 1998 + 2) x)
  select  * from
 (select 'store' channel, i_brand_id,i_class_id,i_category_id
        ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales
 from store_sales 
     ,item
     ,date_dim
 where ss_item_sk in (select ss_item_sk from cross_items)
   and ss_item_sk = i_item_sk
   and ss_sold_date_sk = d_date_sk
   and d_week_seq = (select d_week_seq
                     from date_dim
                     where d_year = 1998 + 1
                       and d_moy = 12
                       and d_dom = 16)
 group by i_brand_id,i_class_id,i_category_id
 having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year,
 (select 'store' channel, i_brand_id,i_class_id
        ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales
 from store_sales
     ,item
     ,date_dim
 where ss_item_sk in (select ss_item_sk from cross_items)
   and ss_item_sk = i_item_sk
   and ss_sold_date_sk = d_date_sk
   and d_week_seq = (select d_week_seq
                     from date_dim
                     where d_year = 1998
                       and d_moy = 12
                       and d_dom = 16)
 group by i_brand_id,i_class_id,i_category_id
 having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year
 where this_year.i_brand_id= last_year.i_brand_id
   and this_year.i_class_id = last_year.i_class_id
   and this_year.i_category_id = last_year.i_category_id
 order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id
 limit 100
-- !query schema
struct<channel:string,i_brand_id:bigint,i_class_id:bigint,i_category_id:bigint,sales:decimal(28,2),number_sales:bigint,channel:string,i_brand_id:bigint,i_class_id:bigint,i_category_id:bigint,sales:decimal(28,2),number_sales:bigint>
-- !query output
store	10002006	2	10	5926.44	1	store	10002006	2	10	5624.71	1
store	1001001	1	1	9993.34	2	store	1001001	1	1	14170.87	3
store	10016015	16	10	5282.76	1	store	10016015	16	10	7062.30	1
store	1003001	3	1	26879.25	5	store	1003001	3	1	7952.33	3
store	1004001	4	1	25861.72	4	store	1004001	4	1	14708.04	6
store	2003001	3	2	18806.03	5	store	2003001	3	2	6689.28	1
store	3001001	1	3	49580.51	7	store	3001001	1	3	6664.98	3
store	3002001	2	3	17695.75	3	store	3002001	2	3	7547.20	3
store	3003001	3	3	18201.26	6	store	3003001	3	3	13766.04	4
store	3004001	4	3	18160.79	6	store	3004001	4	3	11545.59	3
store	4001001	1	4	28270.43	6	store	4001001	1	4	9902.93	3
store	4002001	2	4	26106.97	4	store	4002001	2	4	14785.36	4
store	4004001	4	4	7754.37	3	store	4004001	4	4	6046.47	1
store	4004002	4	4	13184.04	6	store	4004002	4	4	4688.65	1
store	5001001	1	5	22738.19	8	store	5001001	1	5	24411.20	6
store	5003001	3	5	19355.10	7	store	5003001	3	5	6876.55	3
store	5004002	4	5	6355.47	4	store	5004002	4	5	6297.48	1
store	7005005	5	7	6178.69	1	store	7005005	5	7	8772.80	1
store	9010005	10	9	9596.52	2	store	9010005	10	9	5644.16	1
store	9010009	10	9	4968.34	1	store	9010009	10	9	15515.37	1