== Physical Plan ==
TakeOrderedAndProject (41)
+- * Project (40)
   +- Window (39)
      +- * Sort (38)
         +- Exchange (37)
            +- * HashAggregate (36)
               +- Exchange (35)
                  +- * HashAggregate (34)
                     +- Union (33)
                        :- * HashAggregate (22)
                        :  +- Exchange (21)
                        :     +- * HashAggregate (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 default.store_sales (1)
                        :              :     :     +- ReusedExchange (4)
                        :              :     +- BroadcastExchange (10)
                        :              :        +- * Filter (9)
                        :              :           +- * ColumnarToRow (8)
                        :              :              +- Scan parquet default.item (7)
                        :              +- BroadcastExchange (17)
                        :                 +- * Project (16)
                        :                    +- * Filter (15)
                        :                       +- * ColumnarToRow (14)
                        :                          +- Scan parquet default.store (13)
                        :- * HashAggregate (27)
                        :  +- Exchange (26)
                        :     +- * HashAggregate (25)
                        :        +- * HashAggregate (24)
                        :           +- ReusedExchange (23)
                        +- * HashAggregate (32)
                           +- Exchange (31)
                              +- * HashAggregate (30)
                                 +- * HashAggregate (29)
                                    +- ReusedExchange (28)


(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: 46]
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.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), [id=#11]

(11) BroadcastHashJoin [codegen id : 4]
Left keys [1]: [ss_item_sk#1]
Right keys [1]: [i_item_sk#8]
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 default.store
Output [2]: [s_store_sk#12, s_state#13]
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#12, s_state#13]

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

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

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

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

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

(20) 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#15, sum#16]
Results [4]: [i_category#10, i_class#9, sum#17, sum#18]

(21) Exchange
Input [4]: [i_category#10, i_class#9, sum#17, sum#18]
Arguments: hashpartitioning(i_category#10, i_class#9, 5), ENSURE_REQUIREMENTS, [id=#19]

(22) HashAggregate [codegen id : 5]
Input [4]: [i_category#10, i_class#9, sum#17, sum#18]
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))#20, sum(UnscaledValue(ss_ext_sales_price#3))#21]
Results [6]: [cast(CheckOverflow((promote_precision(MakeDecimal(sum(UnscaledValue(ss_net_profit#4))#20,17,2)) / promote_precision(MakeDecimal(sum(UnscaledValue(ss_ext_sales_price#3))#21,17,2))), DecimalType(37,20), true) as decimal(38,20)) AS gross_margin#22, i_category#10, i_class#9, 0 AS t_category#23, 0 AS t_class#24, 0 AS lochierarchy#25]

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

(24) HashAggregate [codegen id : 10]
Input [4]: [i_category#10, i_class#9, sum#26, sum#27]
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))#28, sum(UnscaledValue(ss_ext_sales_price#3))#29]
Results [3]: [MakeDecimal(sum(UnscaledValue(ss_net_profit#4))#28,17,2) AS ss_net_profit#30, MakeDecimal(sum(UnscaledValue(ss_ext_sales_price#3))#29,17,2) AS ss_ext_sales_price#31, i_category#10]

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

(26) Exchange
Input [5]: [i_category#10, sum#36, isEmpty#37, sum#38, isEmpty#39]
Arguments: hashpartitioning(i_category#10, 5), ENSURE_REQUIREMENTS, [id=#40]

(27) HashAggregate [codegen id : 11]
Input [5]: [i_category#10, sum#36, isEmpty#37, sum#38, isEmpty#39]
Keys [1]: [i_category#10]
Functions [2]: [sum(ss_net_profit#30), sum(ss_ext_sales_price#31)]
Aggregate Attributes [2]: [sum(ss_net_profit#30)#41, sum(ss_ext_sales_price#31)#42]
Results [6]: [cast(CheckOverflow((promote_precision(sum(ss_net_profit#30)#41) / promote_precision(sum(ss_ext_sales_price#31)#42)), DecimalType(38,11), true) as decimal(38,20)) AS gross_margin#43, i_category#10, null AS i_class#44, 0 AS t_category#45, 1 AS t_class#46, 1 AS lochierarchy#47]

(28) ReusedExchange [Reuses operator id: 21]
Output [4]: [i_category#10, i_class#9, sum#48, sum#49]

(29) HashAggregate [codegen id : 16]
Input [4]: [i_category#10, i_class#9, sum#48, sum#49]
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))#28, sum(UnscaledValue(ss_ext_sales_price#3))#29]
Results [2]: [MakeDecimal(sum(UnscaledValue(ss_net_profit#4))#28,17,2) AS ss_net_profit#30, MakeDecimal(sum(UnscaledValue(ss_ext_sales_price#3))#29,17,2) AS ss_ext_sales_price#31]

(30) HashAggregate [codegen id : 16]
Input [2]: [ss_net_profit#30, ss_ext_sales_price#31]
Keys: []
Functions [2]: [partial_sum(ss_net_profit#30), partial_sum(ss_ext_sales_price#31)]
Aggregate Attributes [4]: [sum#50, isEmpty#51, sum#52, isEmpty#53]
Results [4]: [sum#54, isEmpty#55, sum#56, isEmpty#57]

(31) Exchange
Input [4]: [sum#54, isEmpty#55, sum#56, isEmpty#57]
Arguments: SinglePartition, ENSURE_REQUIREMENTS, [id=#58]

(32) HashAggregate [codegen id : 17]
Input [4]: [sum#54, isEmpty#55, sum#56, isEmpty#57]
Keys: []
Functions [2]: [sum(ss_net_profit#30), sum(ss_ext_sales_price#31)]
Aggregate Attributes [2]: [sum(ss_net_profit#30)#59, sum(ss_ext_sales_price#31)#60]
Results [6]: [cast(CheckOverflow((promote_precision(sum(ss_net_profit#30)#59) / promote_precision(sum(ss_ext_sales_price#31)#60)), DecimalType(38,11), true) as decimal(38,20)) AS gross_margin#61, null AS i_category#62, null AS i_class#63, 1 AS t_category#64, 1 AS t_class#65, 2 AS lochierarchy#66]

(33) Union

(34) HashAggregate [codegen id : 18]
Input [6]: [gross_margin#22, i_category#10, i_class#9, t_category#23, t_class#24, lochierarchy#25]
Keys [6]: [gross_margin#22, i_category#10, i_class#9, t_category#23, t_class#24, lochierarchy#25]
Functions: []
Aggregate Attributes: []
Results [6]: [gross_margin#22, i_category#10, i_class#9, t_category#23, t_class#24, lochierarchy#25]

(35) Exchange
Input [6]: [gross_margin#22, i_category#10, i_class#9, t_category#23, t_class#24, lochierarchy#25]
Arguments: hashpartitioning(gross_margin#22, i_category#10, i_class#9, t_category#23, t_class#24, lochierarchy#25, 5), ENSURE_REQUIREMENTS, [id=#67]

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

(37) Exchange
Input [5]: [gross_margin#22, i_category#10, i_class#9, lochierarchy#25, _w0#68]
Arguments: hashpartitioning(lochierarchy#25, _w0#68, 5), ENSURE_REQUIREMENTS, [id=#69]

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

(39) Window
Input [5]: [gross_margin#22, i_category#10, i_class#9, lochierarchy#25, _w0#68]
Arguments: [rank(gross_margin#22) windowspecdefinition(lochierarchy#25, _w0#68, gross_margin#22 ASC NULLS FIRST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS rank_within_parent#70], [lochierarchy#25, _w0#68], [gross_margin#22 ASC NULLS FIRST]

(40) Project [codegen id : 21]
Output [5]: [gross_margin#22, i_category#10, i_class#9, lochierarchy#25, rank_within_parent#70]
Input [6]: [gross_margin#22, i_category#10, i_class#9, lochierarchy#25, _w0#68, rank_within_parent#70]

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

===== Subqueries =====

Subquery:1 Hosting operator id = 1 Hosting Expression = ss_sold_date_sk#5 IN dynamicpruning#6
BroadcastExchange (46)
+- * Project (45)
   +- * Filter (44)
      +- * ColumnarToRow (43)
         +- Scan parquet default.date_dim (42)


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

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

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

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

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


