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 all_sales AS (
SELECT d_year
,i_brand_id
,i_class_id
,i_category_id
,i_manufact_id
,SUM(sales_cnt) AS sales_cnt
,SUM(sales_amt) AS sales_amt
FROM (SELECT d_year
,i_brand_id
,i_class_id
,i_category_id
,i_manufact_id
,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt
,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt
FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk
JOIN date_dim ON d_date_sk=cs_sold_date_sk
LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number
AND cs_item_sk=cr_item_sk)
WHERE i_category='Sports'
UNION
SELECT d_year
,i_brand_id
,i_class_id
,i_category_id
,i_manufact_id
,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt
,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt
FROM store_sales JOIN item ON i_item_sk=ss_item_sk
JOIN date_dim ON d_date_sk=ss_sold_date_sk
LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number
AND ss_item_sk=sr_item_sk)
WHERE i_category='Sports'
UNION
SELECT d_year
,i_brand_id
,i_class_id
,i_category_id
,i_manufact_id
,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt
,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt
FROM web_sales JOIN item ON i_item_sk=ws_item_sk
JOIN date_dim ON d_date_sk=ws_sold_date_sk
LEFT JOIN web_returns ON (ws_order_number=wr_order_number
AND ws_item_sk=wr_item_sk)
WHERE i_category='Sports') sales_detail
GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id)
SELECT prev_yr.d_year AS prev_year
,curr_yr.d_year AS year
,curr_yr.i_brand_id
,curr_yr.i_class_id
,curr_yr.i_category_id
,curr_yr.i_manufact_id
,prev_yr.sales_cnt AS prev_yr_cnt
,curr_yr.sales_cnt AS curr_yr_cnt
,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff
,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff
FROM all_sales curr_yr, all_sales prev_yr
WHERE curr_yr.i_brand_id=prev_yr.i_brand_id
AND curr_yr.i_class_id=prev_yr.i_class_id
AND curr_yr.i_category_id=prev_yr.i_category_id
AND curr_yr.i_manufact_id=prev_yr.i_manufact_id
AND curr_yr.d_year=2002
AND prev_yr.d_year=2002-1
AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9
ORDER BY sales_cnt_diff
limit 100
-- !query schema
struct<prev_year:bigint,year:bigint,i_brand_id:bigint,i_class_id:bigint,i_category_id:bigint,i_manufact_id:bigint,prev_yr_cnt:bigint,curr_yr_cnt:bigint,sales_cnt_diff:bigint,sales_amt_diff:decimal(19,2)>
-- !query output
2001 2002 1001001 1 8 146 36 9 -27 -517.15
2001 2002 1002001 6 8 308 142 7 -135 -882.53
2001 2002 1004001 3 8 279 153 31 -122 -9961.07
2001 2002 3002001 2 8 350 62 40 -22 499.10
2001 2002 3004001 14 8 186 103 63 -40 -2471.97
2001 2002 4001001 1 8 417 163 99 -64 -16099.28
2001 2002 4001001 13 8 110 157 89 -68 1080.24
2001 2002 4002001 2 8 534 147 74 -73 -18167.77
2001 2002 4004001 4 8 278 142 19 -123 -1688.76
2001 2002 5004001 11 8 340 47 7 -40 -3417.97
2001 2002 5004001 4 8 380 66 21 -45 -231.15
2001 2002 6003005 3 8 9 81 31 -50 -2347.97
2001 2002 7005005 5 8 781 87 32 -55 -4724.10
2001 2002 8001002 1 8 113 91 42 -49 709.52
2001 2002 8001006 1 8 805 45 14 -31 739.71
2001 2002 8001008 1 8 11 63 12 -51 -2281.57
2001 2002 8001008 1 8 321 40 15 -25 198.48
2001 2002 8001010 1 8 20 113 48 -65 -1689.07
2001 2002 8002004 2 8 50 96 66 -30 -26.76
2001 2002 8002004 2 8 896 150 66 -84 -6551.76
2001 2002 8002008 2 8 272 162 80 -82 -334.20
2001 2002 8002008 2 8 279 73 43 -30 168.26
2001 2002 8002008 2 8 649 73 46 -27 1656.23
2001 2002 8002008 4 8 91 156 36 -120 -4662.88
2001 2002 8003004 3 8 168 80 38 -42 -4024.86
2001 2002 8003004 3 8 264 43 14 -29 -519.15
2001 2002 8003010 3 8 606 44 18 -26 84.38
2001 2002 8004006 1 8 207 97 19 -78 -710.34
2001 2002 8004010 4 8 173 117 30 -87 -2818.20
2001 2002 8005008 5 8 864 100 72 -28 -7763.06
2001 2002 8005010 5 8 225 95 16 -79 -7616.85
2001 2002 8006008 6 8 263 199 45 -154 -12389.88
2001 2002 8006010 6 8 490 81 14 -67 174.40
2001 2002 8007002 7 8 256 41 29 -12 3245.54
2001 2002 8007004 7 8 233 87 44 -43 -2137.62
2001 2002 8007004 7 8 469 75 15 -60 -767.40
2001 2002 8007004 7 8 621 72 56 -16 -154.37
2001 2002 8007006 7 8 973 120 63 -57 -2859.48
2001 2002 8007007 11 8 290 73 48 -25 -172.77
2001 2002 8007008 7 8 69 236 194 -42 -2099.21
2001 2002 8007010 10 8 142 172 77 -95 -12135.86
2001 2002 8007010 7 8 774 8 2 -6 101.04
2001 2002 8008002 8 8 500 199 60 -139 -3942.11
2001 2002 8008004 8 8 208 79 55 -24 -687.19
2001 2002 8008008 8 8 246 47 12 -35 -3373.95
2001 2002 8008010 3 8 495 131 24 -107 -8525.60
2001 2002 8008010 8 8 120 99 77 -22 -443.74
2001 2002 8009004 9 8 258 99 29 -70 174.32
2001 2002 8009004 9 8 582 121 4 -117 -4514.94
2001 2002 8009008 9 8 273 69 16 -53 -2601.78
2001 2002 8010002 10 8 874 100 79 -21 996.10
2001 2002 8010002 2 8 456 79 9 -70 -1440.61
2001 2002 8010004 10 8 343 61 49 -12 -2469.25
2001 2002 8010005 2 8 19 95 56 -39 -1125.90
2001 2002 8010006 10 8 383 162 56 -106 -437.07
2001 2002 8010006 10 8 68 71 53 -18 -14004.88
2001 2002 8010010 10 8 402 66 21 -45 -2182.26
2001 2002 8010010 2 8 390 49 44 -5 -3661.10
2001 2002 8011002 11 8 415 104 36 -68 -3571.08
2001 2002 8011006 11 8 357 124 5 -119 -2958.79
2001 2002 8011010 11 8 365 139 62 -77 -2642.33
2001 2002 8012002 12 8 122 44 33 -11 2387.22
2001 2002 8012006 12 8 821 215 52 -163 -13895.24
2001 2002 8012008 12 8 64 69 7 -62 -2941.73
2001 2002 8012008 12 8 82 168 72 -96 -6743.93
2001 2002 8013002 3 8 290 53 12 -41 -832.89
2001 2002 8013004 13 8 27 152 22 -130 251.68
2001 2002 8013004 13 8 44 193 2 -191 -6883.92
2001 2002 8014002 14 8 487 137 51 -86 352.05
2001 2002 8014004 14 8 659 89 78 -11 2696.21
2001 2002 8015004 15 8 283 128 36 -92 -5550.49
2001 2002 8015008 15 8 964 80 16 -64 -2833.28
2001 2002 8015008 2 8 253 95 36 -59 -396.46
2001 2002 8016001 10 8 585 77 5 -72 -5623.63
2001 2002 8016002 16 8 496 140 50 -90 -8472.05
2001 2002 8016002 16 8 556 42 28 -14 414.21
2001 2002 8016004 16 8 11 43 30 -13 NULL
2001 2002 8016009 16 8 33 24 21 -3 -1626.63
2001 2002 8016010 1 8 365 78 18 -60 -3433.26
2001 2002 8016010 16 8 433 61 14 -47 -5990.11
2001 2002 9005009 16 8 375 141 88 -53 -5242.16