== 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 (13)
                              :  +- * BroadcastHashJoin Inner BuildRight (12)
                              :     :- * Project (6)
                              :     :  +- * BroadcastHashJoin Inner BuildRight (5)
                              :     :     :- * Filter (3)
                              :     :     :  +- * ColumnarToRow (2)
                              :     :     :     +- Scan parquet default.store_sales (1)
                              :     :     +- ReusedExchange (4)
                              :     +- BroadcastExchange (11)
                              :        +- * Project (10)
                              :           +- * Filter (9)
                              :              +- * ColumnarToRow (8)
                              :                 +- Scan parquet default.store (7)
                              +- BroadcastExchange (17)
                                 +- * Filter (16)
                                    +- * ColumnarToRow (15)
                                       +- Scan parquet default.item (14)


(1) Scan parquet 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 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 default.store
Output [2]: [s_store_sk#8, s_state#9]
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>

(8) ColumnarToRow [codegen id : 2]
Input [2]: [s_store_sk#8, s_state#9]

(9) Filter [codegen id : 2]
Input [2]: [s_store_sk#8, s_state#9]
Condition : ((isnotnull(s_state#9) AND (s_state#9 = TN)) AND isnotnull(s_store_sk#8))

(10) Project [codegen id : 2]
Output [1]: [s_store_sk#8]
Input [2]: [s_store_sk#8, s_state#9]

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

(12) BroadcastHashJoin [codegen id : 4]
Left keys [1]: [ss_store_sk#2]
Right keys [1]: [s_store_sk#8]
Join condition: None

(13) Project [codegen id : 4]
Output [3]: [ss_item_sk#1, ss_ext_sales_price#3, ss_net_profit#4]
Input [5]: [ss_item_sk#1, ss_store_sk#2, ss_ext_sales_price#3, ss_net_profit#4, s_store_sk#8]

(14) Scan parquet default.item
Output [3]: [i_item_sk#11, i_class#12, i_category#13]
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>

(15) ColumnarToRow [codegen id : 3]
Input [3]: [i_item_sk#11, i_class#12, i_category#13]

(16) Filter [codegen id : 3]
Input [3]: [i_item_sk#11, i_class#12, i_category#13]
Condition : isnotnull(i_item_sk#11)

(17) BroadcastExchange
Input [3]: [i_item_sk#11, i_class#12, i_category#13]
Arguments: HashedRelationBroadcastMode(List(cast(input[0, int, false] as bigint)),false), [id=#14]

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

(19) Project [codegen id : 4]
Output [4]: [ss_ext_sales_price#3, ss_net_profit#4, i_category#13, i_class#12]
Input [6]: [ss_item_sk#1, ss_ext_sales_price#3, ss_net_profit#4, i_item_sk#11, i_class#12, i_category#13]

(20) Expand [codegen id : 4]
Input [4]: [ss_ext_sales_price#3, ss_net_profit#4, i_category#13, i_class#12]
Arguments: [[ss_ext_sales_price#3, ss_net_profit#4, i_category#13, i_class#12, 0], [ss_ext_sales_price#3, ss_net_profit#4, i_category#13, 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#15, i_class#16, spark_grouping_id#17]

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

(22) Exchange
Input [5]: [i_category#15, i_class#16, spark_grouping_id#17, sum#20, sum#21]
Arguments: hashpartitioning(i_category#15, i_class#16, spark_grouping_id#17, 5), ENSURE_REQUIREMENTS, [id=#22]

(23) HashAggregate [codegen id : 5]
Input [5]: [i_category#15, i_class#16, spark_grouping_id#17, sum#20, sum#21]
Keys [3]: [i_category#15, i_class#16, spark_grouping_id#17]
Functions [2]: [sum(UnscaledValue(ss_net_profit#4)), sum(UnscaledValue(ss_ext_sales_price#3))]
Aggregate Attributes [2]: [sum(UnscaledValue(ss_net_profit#4))#23, sum(UnscaledValue(ss_ext_sales_price#3))#24]
Results [7]: [CheckOverflow((promote_precision(MakeDecimal(sum(UnscaledValue(ss_net_profit#4))#23,17,2)) / promote_precision(MakeDecimal(sum(UnscaledValue(ss_ext_sales_price#3))#24,17,2))), DecimalType(37,20), true) AS gross_margin#25, i_category#15, i_class#16, (cast((shiftright(spark_grouping_id#17, 1) & 1) as tinyint) + cast((shiftright(spark_grouping_id#17, 0) & 1) as tinyint)) AS lochierarchy#26, (cast((shiftright(spark_grouping_id#17, 1) & 1) as tinyint) + cast((shiftright(spark_grouping_id#17, 0) & 1) as tinyint)) AS _w1#27, CASE WHEN (cast((shiftright(spark_grouping_id#17, 0) & 1) as tinyint) = 0) THEN i_category#15 END AS _w2#28, CheckOverflow((promote_precision(MakeDecimal(sum(UnscaledValue(ss_net_profit#4))#23,17,2)) / promote_precision(MakeDecimal(sum(UnscaledValue(ss_ext_sales_price#3))#24,17,2))), DecimalType(37,20), true) AS _w3#29]

(24) Exchange
Input [7]: [gross_margin#25, i_category#15, i_class#16, lochierarchy#26, _w1#27, _w2#28, _w3#29]
Arguments: hashpartitioning(_w1#27, _w2#28, 5), ENSURE_REQUIREMENTS, [id=#30]

(25) Sort [codegen id : 6]
Input [7]: [gross_margin#25, i_category#15, i_class#16, lochierarchy#26, _w1#27, _w2#28, _w3#29]
Arguments: [_w1#27 ASC NULLS FIRST, _w2#28 ASC NULLS FIRST, _w3#29 ASC NULLS FIRST], false, 0

(26) Window
Input [7]: [gross_margin#25, i_category#15, i_class#16, lochierarchy#26, _w1#27, _w2#28, _w3#29]
Arguments: [rank(_w3#29) windowspecdefinition(_w1#27, _w2#28, _w3#29 ASC NULLS FIRST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS rank_within_parent#31], [_w1#27, _w2#28], [_w3#29 ASC NULLS FIRST]

(27) Project [codegen id : 7]
Output [5]: [gross_margin#25, i_category#15, i_class#16, lochierarchy#26, rank_within_parent#31]
Input [8]: [gross_margin#25, i_category#15, i_class#16, lochierarchy#26, _w1#27, _w2#28, _w3#29, rank_within_parent#31]

(28) TakeOrderedAndProject
Input [5]: [gross_margin#25, i_category#15, i_class#16, lochierarchy#26, rank_within_parent#31]
Arguments: 100, [lochierarchy#26 DESC NULLS LAST, CASE WHEN (lochierarchy#26 = 0) THEN i_category#15 END ASC NULLS FIRST, rank_within_parent#31 ASC NULLS FIRST], [gross_margin#25, i_category#15, i_class#16, lochierarchy#26, rank_within_parent#31]

===== 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 default.date_dim (29)


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

(31) Filter [codegen id : 1]
Input [2]: [d_date_sk#7, d_year#32]
Condition : ((isnotnull(d_year#32) AND (d_year#32 = 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#32]

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


