== Physical Plan ==
TakeOrderedAndProject (45)
+- * Project (44)
   +- Window (43)
      +- * Sort (42)
         +- Exchange (41)
            +- * HashAggregate (40)
               +- Exchange (39)
                  +- * HashAggregate (38)
                     +- Union (37)
                        :- * HashAggregate (26)
                        :  +- Exchange (25)
                        :     +- * HashAggregate (24)
                        :        +- * Project (23)
                        :           +- * BroadcastHashJoin Inner BuildRight (22)
                        :              :- * Project (16)
                        :              :  +- * BroadcastHashJoin Inner BuildRight (15)
                        :              :     :- * Project (10)
                        :              :     :  +- * BroadcastHashJoin Inner BuildRight (9)
                        :              :     :     :- * Filter (3)
                        :              :     :     :  +- * ColumnarToRow (2)
                        :              :     :     :     +- Scan parquet spark_catalog.default.store_sales (1)
                        :              :     :     +- BroadcastExchange (8)
                        :              :     :        +- * Project (7)
                        :              :     :           +- * Filter (6)
                        :              :     :              +- * ColumnarToRow (5)
                        :              :     :                 +- Scan parquet spark_catalog.default.date_dim (4)
                        :              :     +- BroadcastExchange (14)
                        :              :        +- * Filter (13)
                        :              :           +- * ColumnarToRow (12)
                        :              :              +- Scan parquet spark_catalog.default.item (11)
                        :              +- BroadcastExchange (21)
                        :                 +- * Project (20)
                        :                    +- * Filter (19)
                        :                       +- * ColumnarToRow (18)
                        :                          +- Scan parquet spark_catalog.default.store (17)
                        :- * HashAggregate (31)
                        :  +- Exchange (30)
                        :     +- * HashAggregate (29)
                        :        +- * HashAggregate (28)
                        :           +- ReusedExchange (27)
                        +- * HashAggregate (36)
                           +- Exchange (35)
                              +- * HashAggregate (34)
                                 +- * HashAggregate (33)
                                    +- ReusedExchange (32)


(1) Scan parquet spark_catalog.default.store_sales
Output [5]: [ss_item_sk#1, ss_store_sk#2, ss_ext_sales_price#3, ss_net_profit#4, ss_sold_date_sk#5]
Batched: true
Location: InMemoryFileIndex []
PartitionFilters: [isnotnull(ss_sold_date_sk#5)]
PushedFilters: [IsNotNull(ss_item_sk), IsNotNull(ss_store_sk)]
ReadSchema: struct<ss_item_sk:int,ss_store_sk:int,ss_ext_sales_price:decimal(7,2),ss_net_profit:decimal(7,2)>

(2) ColumnarToRow [codegen id : 4]
Input [5]: [ss_item_sk#1, ss_store_sk#2, ss_ext_sales_price#3, ss_net_profit#4, ss_sold_date_sk#5]

(3) Filter [codegen id : 4]
Input [5]: [ss_item_sk#1, ss_store_sk#2, ss_ext_sales_price#3, ss_net_profit#4, ss_sold_date_sk#5]
Condition : (isnotnull(ss_item_sk#1) AND isnotnull(ss_store_sk#2))

(4) Scan parquet spark_catalog.default.date_dim
Output [2]: [d_date_sk#6, d_year#7]
Batched: true
Location [not included in comparison]/{warehouse_dir}/date_dim]
PushedFilters: [IsNotNull(d_year), EqualTo(d_year,2001), IsNotNull(d_date_sk)]
ReadSchema: struct<d_date_sk:int,d_year:int>

(5) ColumnarToRow [codegen id : 1]
Input [2]: [d_date_sk#6, d_year#7]

(6) Filter [codegen id : 1]
Input [2]: [d_date_sk#6, d_year#7]
Condition : ((isnotnull(d_year#7) AND (d_year#7 = 2001)) AND isnotnull(d_date_sk#6))

(7) Project [codegen id : 1]
Output [1]: [d_date_sk#6]
Input [2]: [d_date_sk#6, d_year#7]

(8) BroadcastExchange
Input [1]: [d_date_sk#6]
Arguments: HashedRelationBroadcastMode(List(cast(input[0, int, true] as bigint)),false), [plan_id=1]

(9) BroadcastHashJoin [codegen id : 4]
Left keys [1]: [ss_sold_date_sk#5]
Right keys [1]: [d_date_sk#6]
Join type: Inner
Join condition: None

(10) Project [codegen id : 4]
Output [4]: [ss_item_sk#1, ss_store_sk#2, ss_ext_sales_price#3, ss_net_profit#4]
Input [6]: [ss_item_sk#1, ss_store_sk#2, ss_ext_sales_price#3, ss_net_profit#4, ss_sold_date_sk#5, d_date_sk#6]

(11) Scan parquet spark_catalog.default.item
Output [3]: [i_item_sk#8, i_class#9, i_category#10]
Batched: true
Location [not included in comparison]/{warehouse_dir}/item]
PushedFilters: [IsNotNull(i_item_sk)]
ReadSchema: struct<i_item_sk:int,i_class:string,i_category:string>

(12) ColumnarToRow [codegen id : 2]
Input [3]: [i_item_sk#8, i_class#9, i_category#10]

(13) Filter [codegen id : 2]
Input [3]: [i_item_sk#8, i_class#9, i_category#10]
Condition : isnotnull(i_item_sk#8)

(14) BroadcastExchange
Input [3]: [i_item_sk#8, i_class#9, i_category#10]
Arguments: HashedRelationBroadcastMode(List(cast(input[0, int, false] as bigint)),false), [plan_id=2]

(15) BroadcastHashJoin [codegen id : 4]
Left keys [1]: [ss_item_sk#1]
Right keys [1]: [i_item_sk#8]
Join type: Inner
Join condition: None

(16) Project [codegen id : 4]
Output [5]: [ss_store_sk#2, ss_ext_sales_price#3, ss_net_profit#4, i_class#9, i_category#10]
Input [7]: [ss_item_sk#1, ss_store_sk#2, ss_ext_sales_price#3, ss_net_profit#4, i_item_sk#8, i_class#9, i_category#10]

(17) Scan parquet spark_catalog.default.store
Output [2]: [s_store_sk#11, s_state#12]
Batched: true
Location [not included in comparison]/{warehouse_dir}/store]
PushedFilters: [IsNotNull(s_state), EqualTo(s_state,TN), IsNotNull(s_store_sk)]
ReadSchema: struct<s_store_sk:int,s_state:string>

(18) ColumnarToRow [codegen id : 3]
Input [2]: [s_store_sk#11, s_state#12]

(19) Filter [codegen id : 3]
Input [2]: [s_store_sk#11, s_state#12]
Condition : ((isnotnull(s_state#12) AND (s_state#12 = TN)) AND isnotnull(s_store_sk#11))

(20) Project [codegen id : 3]
Output [1]: [s_store_sk#11]
Input [2]: [s_store_sk#11, s_state#12]

(21) BroadcastExchange
Input [1]: [s_store_sk#11]
Arguments: HashedRelationBroadcastMode(List(cast(input[0, int, true] as bigint)),false), [plan_id=3]

(22) BroadcastHashJoin [codegen id : 4]
Left keys [1]: [ss_store_sk#2]
Right keys [1]: [s_store_sk#11]
Join type: Inner
Join condition: None

(23) Project [codegen id : 4]
Output [4]: [ss_ext_sales_price#3, ss_net_profit#4, i_class#9, i_category#10]
Input [6]: [ss_store_sk#2, ss_ext_sales_price#3, ss_net_profit#4, i_class#9, i_category#10, s_store_sk#11]

(24) HashAggregate [codegen id : 4]
Input [4]: [ss_ext_sales_price#3, ss_net_profit#4, i_class#9, i_category#10]
Keys [2]: [i_category#10, i_class#9]
Functions [2]: [partial_sum(UnscaledValue(ss_net_profit#4)), partial_sum(UnscaledValue(ss_ext_sales_price#3))]
Aggregate Attributes [2]: [sum#13, sum#14]
Results [4]: [i_category#10, i_class#9, sum#15, sum#16]

(25) Exchange
Input [4]: [i_category#10, i_class#9, sum#15, sum#16]
Arguments: hashpartitioning(i_category#10, i_class#9, 5), ENSURE_REQUIREMENTS, [plan_id=4]

(26) HashAggregate [codegen id : 5]
Input [4]: [i_category#10, i_class#9, sum#15, sum#16]
Keys [2]: [i_category#10, i_class#9]
Functions [2]: [sum(UnscaledValue(ss_net_profit#4)), sum(UnscaledValue(ss_ext_sales_price#3))]
Aggregate Attributes [2]: [sum(UnscaledValue(ss_net_profit#4))#17, sum(UnscaledValue(ss_ext_sales_price#3))#18]
Results [6]: [cast((MakeDecimal(sum(UnscaledValue(ss_net_profit#4))#17,17,2) / MakeDecimal(sum(UnscaledValue(ss_ext_sales_price#3))#18,17,2)) as decimal(38,20)) AS gross_margin#19, i_category#10, i_class#9, 0 AS t_category#20, 0 AS t_class#21, 0 AS lochierarchy#22]

(27) ReusedExchange [Reuses operator id: 25]
Output [4]: [i_category#10, i_class#9, sum#23, sum#24]

(28) HashAggregate [codegen id : 10]
Input [4]: [i_category#10, i_class#9, sum#23, sum#24]
Keys [2]: [i_category#10, i_class#9]
Functions [2]: [sum(UnscaledValue(ss_net_profit#4)), sum(UnscaledValue(ss_ext_sales_price#3))]
Aggregate Attributes [2]: [sum(UnscaledValue(ss_net_profit#4))#25, sum(UnscaledValue(ss_ext_sales_price#3))#26]
Results [3]: [MakeDecimal(sum(UnscaledValue(ss_net_profit#4))#25,17,2) AS ss_net_profit#27, MakeDecimal(sum(UnscaledValue(ss_ext_sales_price#3))#26,17,2) AS ss_ext_sales_price#28, i_category#10]

(29) HashAggregate [codegen id : 10]
Input [3]: [ss_net_profit#27, ss_ext_sales_price#28, i_category#10]
Keys [1]: [i_category#10]
Functions [2]: [partial_sum(ss_net_profit#27), partial_sum(ss_ext_sales_price#28)]
Aggregate Attributes [4]: [sum#29, isEmpty#30, sum#31, isEmpty#32]
Results [5]: [i_category#10, sum#33, isEmpty#34, sum#35, isEmpty#36]

(30) Exchange
Input [5]: [i_category#10, sum#33, isEmpty#34, sum#35, isEmpty#36]
Arguments: hashpartitioning(i_category#10, 5), ENSURE_REQUIREMENTS, [plan_id=5]

(31) HashAggregate [codegen id : 11]
Input [5]: [i_category#10, sum#33, isEmpty#34, sum#35, isEmpty#36]
Keys [1]: [i_category#10]
Functions [2]: [sum(ss_net_profit#27), sum(ss_ext_sales_price#28)]
Aggregate Attributes [2]: [sum(ss_net_profit#27)#37, sum(ss_ext_sales_price#28)#38]
Results [6]: [cast((sum(ss_net_profit#27)#37 / sum(ss_ext_sales_price#28)#38) as decimal(38,20)) AS gross_margin#39, i_category#10, null AS i_class#40, 0 AS t_category#41, 1 AS t_class#42, 1 AS lochierarchy#43]

(32) ReusedExchange [Reuses operator id: 25]
Output [4]: [i_category#10, i_class#9, sum#44, sum#45]

(33) HashAggregate [codegen id : 16]
Input [4]: [i_category#10, i_class#9, sum#44, sum#45]
Keys [2]: [i_category#10, i_class#9]
Functions [2]: [sum(UnscaledValue(ss_net_profit#4)), sum(UnscaledValue(ss_ext_sales_price#3))]
Aggregate Attributes [2]: [sum(UnscaledValue(ss_net_profit#4))#25, sum(UnscaledValue(ss_ext_sales_price#3))#26]
Results [2]: [MakeDecimal(sum(UnscaledValue(ss_net_profit#4))#25,17,2) AS ss_net_profit#27, MakeDecimal(sum(UnscaledValue(ss_ext_sales_price#3))#26,17,2) AS ss_ext_sales_price#28]

(34) HashAggregate [codegen id : 16]
Input [2]: [ss_net_profit#27, ss_ext_sales_price#28]
Keys: []
Functions [2]: [partial_sum(ss_net_profit#27), partial_sum(ss_ext_sales_price#28)]
Aggregate Attributes [4]: [sum#46, isEmpty#47, sum#48, isEmpty#49]
Results [4]: [sum#50, isEmpty#51, sum#52, isEmpty#53]

(35) Exchange
Input [4]: [sum#50, isEmpty#51, sum#52, isEmpty#53]
Arguments: SinglePartition, ENSURE_REQUIREMENTS, [plan_id=6]

(36) HashAggregate [codegen id : 17]
Input [4]: [sum#50, isEmpty#51, sum#52, isEmpty#53]
Keys: []
Functions [2]: [sum(ss_net_profit#27), sum(ss_ext_sales_price#28)]
Aggregate Attributes [2]: [sum(ss_net_profit#27)#54, sum(ss_ext_sales_price#28)#55]
Results [6]: [cast((sum(ss_net_profit#27)#54 / sum(ss_ext_sales_price#28)#55) as decimal(38,20)) AS gross_margin#56, null AS i_category#57, null AS i_class#58, 1 AS t_category#59, 1 AS t_class#60, 2 AS lochierarchy#61]

(37) Union

(38) HashAggregate [codegen id : 18]
Input [6]: [gross_margin#19, i_category#10, i_class#9, t_category#20, t_class#21, lochierarchy#22]
Keys [6]: [gross_margin#19, i_category#10, i_class#9, t_category#20, t_class#21, lochierarchy#22]
Functions: []
Aggregate Attributes: []
Results [6]: [gross_margin#19, i_category#10, i_class#9, t_category#20, t_class#21, lochierarchy#22]

(39) Exchange
Input [6]: [gross_margin#19, i_category#10, i_class#9, t_category#20, t_class#21, lochierarchy#22]
Arguments: hashpartitioning(gross_margin#19, i_category#10, i_class#9, t_category#20, t_class#21, lochierarchy#22, 5), ENSURE_REQUIREMENTS, [plan_id=7]

(40) HashAggregate [codegen id : 19]
Input [6]: [gross_margin#19, i_category#10, i_class#9, t_category#20, t_class#21, lochierarchy#22]
Keys [6]: [gross_margin#19, i_category#10, i_class#9, t_category#20, t_class#21, lochierarchy#22]
Functions: []
Aggregate Attributes: []
Results [5]: [gross_margin#19, i_category#10, i_class#9, lochierarchy#22, CASE WHEN (t_class#21 = 0) THEN i_category#10 END AS _w0#62]

(41) Exchange
Input [5]: [gross_margin#19, i_category#10, i_class#9, lochierarchy#22, _w0#62]
Arguments: hashpartitioning(lochierarchy#22, _w0#62, 5), ENSURE_REQUIREMENTS, [plan_id=8]

(42) Sort [codegen id : 20]
Input [5]: [gross_margin#19, i_category#10, i_class#9, lochierarchy#22, _w0#62]
Arguments: [lochierarchy#22 ASC NULLS FIRST, _w0#62 ASC NULLS FIRST, gross_margin#19 ASC NULLS FIRST], false, 0

(43) Window
Input [5]: [gross_margin#19, i_category#10, i_class#9, lochierarchy#22, _w0#62]
Arguments: [rank(gross_margin#19) windowspecdefinition(lochierarchy#22, _w0#62, gross_margin#19 ASC NULLS FIRST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS rank_within_parent#63], [lochierarchy#22, _w0#62], [gross_margin#19 ASC NULLS FIRST]

(44) Project [codegen id : 21]
Output [5]: [gross_margin#19, i_category#10, i_class#9, lochierarchy#22, rank_within_parent#63]
Input [6]: [gross_margin#19, i_category#10, i_class#9, lochierarchy#22, _w0#62, rank_within_parent#63]

(45) TakeOrderedAndProject
Input [5]: [gross_margin#19, i_category#10, i_class#9, lochierarchy#22, rank_within_parent#63]
Arguments: 100, [lochierarchy#22 DESC NULLS LAST, CASE WHEN (lochierarchy#22 = 0) THEN i_category#10 END ASC NULLS FIRST, rank_within_parent#63 ASC NULLS FIRST], [gross_margin#19, i_category#10, i_class#9, lochierarchy#22, rank_within_parent#63]

