== Physical Plan ==
TakeOrderedAndProject (28)
+- * Project (27)
   +- Window (26)
      +- * Sort (25)
         +- Exchange (24)
            +- * HashAggregate (23)
               +- Exchange (22)
                  +- * HashAggregate (21)
                     +- * Expand (20)
                        +- * Project (19)
                           +- * BroadcastHashJoin Inner BuildRight (18)
                              :- * Project (12)
                              :  +- * BroadcastHashJoin Inner BuildRight (11)
                              :     :- * Project (6)
                              :     :  +- * BroadcastHashJoin Inner BuildRight (5)
                              :     :     :- * Filter (3)
                              :     :     :  +- * ColumnarToRow (2)
                              :     :     :     +- Scan parquet spark_catalog.default.store_sales (1)
                              :     :     +- ReusedExchange (4)
                              :     +- BroadcastExchange (10)
                              :        +- * Filter (9)
                              :           +- * ColumnarToRow (8)
                              :              +- Scan parquet spark_catalog.default.item (7)
                              +- BroadcastExchange (17)
                                 +- * Project (16)
                                    +- * Filter (15)
                                       +- * ColumnarToRow (14)
                                          +- Scan parquet spark_catalog.default.store (13)


(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), dynamicpruningexpression(ss_sold_date_sk#5 IN dynamicpruning#6)]
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) ReusedExchange [Reuses operator id: 33]
Output [1]: [d_date_sk#7]

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

(6) 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#7]

(7) 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>

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

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

(10) 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=1]

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

(12) 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]

(13) 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>

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

(15) 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))

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

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

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

(19) Project [codegen id : 4]
Output [4]: [ss_ext_sales_price#3, ss_net_profit#4, i_category#10, i_class#9]
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]

(20) Expand [codegen id : 4]
Input [4]: [ss_ext_sales_price#3, ss_net_profit#4, i_category#10, i_class#9]
Arguments: [[ss_ext_sales_price#3, ss_net_profit#4, i_category#10, i_class#9, 0], [ss_ext_sales_price#3, ss_net_profit#4, i_category#10, null, 1], [ss_ext_sales_price#3, ss_net_profit#4, null, null, 3]], [ss_ext_sales_price#3, ss_net_profit#4, i_category#13, i_class#14, spark_grouping_id#15]

(21) HashAggregate [codegen id : 4]
Input [5]: [ss_ext_sales_price#3, ss_net_profit#4, i_category#13, i_class#14, spark_grouping_id#15]
Keys [3]: [i_category#13, i_class#14, spark_grouping_id#15]
Functions [2]: [partial_sum(UnscaledValue(ss_net_profit#4)), partial_sum(UnscaledValue(ss_ext_sales_price#3))]
Aggregate Attributes [2]: [sum#16, sum#17]
Results [5]: [i_category#13, i_class#14, spark_grouping_id#15, sum#18, sum#19]

(22) Exchange
Input [5]: [i_category#13, i_class#14, spark_grouping_id#15, sum#18, sum#19]
Arguments: hashpartitioning(i_category#13, i_class#14, spark_grouping_id#15, 5), ENSURE_REQUIREMENTS, [plan_id=3]

(23) HashAggregate [codegen id : 5]
Input [5]: [i_category#13, i_class#14, spark_grouping_id#15, sum#18, sum#19]
Keys [3]: [i_category#13, i_class#14, spark_grouping_id#15]
Functions [2]: [sum(UnscaledValue(ss_net_profit#4)), sum(UnscaledValue(ss_ext_sales_price#3))]
Aggregate Attributes [2]: [sum(UnscaledValue(ss_net_profit#4))#20, sum(UnscaledValue(ss_ext_sales_price#3))#21]
Results [7]: [(MakeDecimal(sum(UnscaledValue(ss_net_profit#4))#20,17,2) / MakeDecimal(sum(UnscaledValue(ss_ext_sales_price#3))#21,17,2)) AS gross_margin#22, i_category#13, i_class#14, (cast((shiftright(spark_grouping_id#15, 1) & 1) as tinyint) + cast((shiftright(spark_grouping_id#15, 0) & 1) as tinyint)) AS lochierarchy#23, (MakeDecimal(sum(UnscaledValue(ss_net_profit#4))#20,17,2) / MakeDecimal(sum(UnscaledValue(ss_ext_sales_price#3))#21,17,2)) AS _w0#24, (cast((shiftright(spark_grouping_id#15, 1) & 1) as tinyint) + cast((shiftright(spark_grouping_id#15, 0) & 1) as tinyint)) AS _w1#25, CASE WHEN (cast((shiftright(spark_grouping_id#15, 0) & 1) as tinyint) = 0) THEN i_category#13 END AS _w2#26]

(24) Exchange
Input [7]: [gross_margin#22, i_category#13, i_class#14, lochierarchy#23, _w0#24, _w1#25, _w2#26]
Arguments: hashpartitioning(_w1#25, _w2#26, 5), ENSURE_REQUIREMENTS, [plan_id=4]

(25) Sort [codegen id : 6]
Input [7]: [gross_margin#22, i_category#13, i_class#14, lochierarchy#23, _w0#24, _w1#25, _w2#26]
Arguments: [_w1#25 ASC NULLS FIRST, _w2#26 ASC NULLS FIRST, _w0#24 ASC NULLS FIRST], false, 0

(26) Window
Input [7]: [gross_margin#22, i_category#13, i_class#14, lochierarchy#23, _w0#24, _w1#25, _w2#26]
Arguments: [rank(_w0#24) windowspecdefinition(_w1#25, _w2#26, _w0#24 ASC NULLS FIRST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS rank_within_parent#27], [_w1#25, _w2#26], [_w0#24 ASC NULLS FIRST]

(27) Project [codegen id : 7]
Output [5]: [gross_margin#22, i_category#13, i_class#14, lochierarchy#23, rank_within_parent#27]
Input [8]: [gross_margin#22, i_category#13, i_class#14, lochierarchy#23, _w0#24, _w1#25, _w2#26, rank_within_parent#27]

(28) TakeOrderedAndProject
Input [5]: [gross_margin#22, i_category#13, i_class#14, lochierarchy#23, rank_within_parent#27]
Arguments: 100, [lochierarchy#23 DESC NULLS LAST, CASE WHEN (lochierarchy#23 = 0) THEN i_category#13 END ASC NULLS FIRST, rank_within_parent#27 ASC NULLS FIRST], [gross_margin#22, i_category#13, i_class#14, lochierarchy#23, rank_within_parent#27]

===== Subqueries =====

Subquery:1 Hosting operator id = 1 Hosting Expression = ss_sold_date_sk#5 IN dynamicpruning#6
BroadcastExchange (33)
+- * Project (32)
   +- * Filter (31)
      +- * ColumnarToRow (30)
         +- Scan parquet spark_catalog.default.date_dim (29)


(29) Scan parquet spark_catalog.default.date_dim
Output [2]: [d_date_sk#7, d_year#28]
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>

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

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

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

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


