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


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

(2) ColumnarToRow [codegen id : 8]
Input [3]: [ss_store_sk#1, ss_net_profit#2, ss_sold_date_sk#3]

(3) Filter [codegen id : 8]
Input [3]: [ss_store_sk#1, ss_net_profit#2, ss_sold_date_sk#3]
Condition : isnotnull(ss_store_sk#1)

(4) ReusedExchange [Reuses operator id: 60]
Output [1]: [d_date_sk#5]

(5) BroadcastHashJoin [codegen id : 8]
Left keys [1]: [ss_sold_date_sk#3]
Right keys [1]: [d_date_sk#5]
Join condition: None

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

(7) Scan parquet default.store
Output [3]: [s_store_sk#6, s_county#7, s_state#8]
Batched: true
Location [not included in comparison]/{warehouse_dir}/store]
PushedFilters: [IsNotNull(s_store_sk)]
ReadSchema: struct<s_store_sk:int,s_county:string,s_state:string>

(8) ColumnarToRow [codegen id : 7]
Input [3]: [s_store_sk#6, s_county#7, s_state#8]

(9) Filter [codegen id : 7]
Input [3]: [s_store_sk#6, s_county#7, s_state#8]
Condition : isnotnull(s_store_sk#6)

(10) Scan parquet default.store_sales
Output [3]: [ss_store_sk#9, ss_net_profit#10, ss_sold_date_sk#11]
Batched: true
Location: InMemoryFileIndex []
PartitionFilters: [isnotnull(ss_sold_date_sk#11), dynamicpruningexpression(ss_sold_date_sk#11 IN dynamicpruning#4)]
PushedFilters: [IsNotNull(ss_store_sk)]
ReadSchema: struct<ss_store_sk:int,ss_net_profit:decimal(7,2)>

(11) ColumnarToRow [codegen id : 4]
Input [3]: [ss_store_sk#9, ss_net_profit#10, ss_sold_date_sk#11]

(12) Filter [codegen id : 4]
Input [3]: [ss_store_sk#9, ss_net_profit#10, ss_sold_date_sk#11]
Condition : isnotnull(ss_store_sk#9)

(13) ReusedExchange [Reuses operator id: 60]
Output [1]: [d_date_sk#12]

(14) BroadcastHashJoin [codegen id : 4]
Left keys [1]: [ss_sold_date_sk#11]
Right keys [1]: [d_date_sk#12]
Join condition: None

(15) Project [codegen id : 4]
Output [2]: [ss_store_sk#9, ss_net_profit#10]
Input [4]: [ss_store_sk#9, ss_net_profit#10, ss_sold_date_sk#11, d_date_sk#12]

(16) Scan parquet default.store
Output [2]: [s_store_sk#13, s_state#14]
Batched: true
Location [not included in comparison]/{warehouse_dir}/store]
PushedFilters: [IsNotNull(s_store_sk)]
ReadSchema: struct<s_store_sk:int,s_state:string>

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

(18) Filter [codegen id : 3]
Input [2]: [s_store_sk#13, s_state#14]
Condition : isnotnull(s_store_sk#13)

(19) BroadcastExchange
Input [2]: [s_store_sk#13, s_state#14]
Arguments: HashedRelationBroadcastMode(List(cast(input[0, int, false] as bigint)),false), [plan_id=1]

(20) BroadcastHashJoin [codegen id : 4]
Left keys [1]: [ss_store_sk#9]
Right keys [1]: [s_store_sk#13]
Join condition: None

(21) Project [codegen id : 4]
Output [2]: [ss_net_profit#10, s_state#14]
Input [4]: [ss_store_sk#9, ss_net_profit#10, s_store_sk#13, s_state#14]

(22) HashAggregate [codegen id : 4]
Input [2]: [ss_net_profit#10, s_state#14]
Keys [1]: [s_state#14]
Functions [1]: [partial_sum(UnscaledValue(ss_net_profit#10))]
Aggregate Attributes [1]: [sum#15]
Results [2]: [s_state#14, sum#16]

(23) Exchange
Input [2]: [s_state#14, sum#16]
Arguments: hashpartitioning(s_state#14, 5), ENSURE_REQUIREMENTS, [plan_id=2]

(24) HashAggregate [codegen id : 5]
Input [2]: [s_state#14, sum#16]
Keys [1]: [s_state#14]
Functions [1]: [sum(UnscaledValue(ss_net_profit#10))]
Aggregate Attributes [1]: [sum(UnscaledValue(ss_net_profit#10))#17]
Results [3]: [s_state#14, s_state#14, MakeDecimal(sum(UnscaledValue(ss_net_profit#10))#17,17,2) AS _w2#18]

(25) Sort [codegen id : 5]
Input [3]: [s_state#14, s_state#14, _w2#18]
Arguments: [s_state#14 ASC NULLS FIRST, _w2#18 DESC NULLS LAST], false, 0

(26) Window
Input [3]: [s_state#14, s_state#14, _w2#18]
Arguments: [rank(_w2#18) windowspecdefinition(s_state#14, _w2#18 DESC NULLS LAST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS ranking#19], [s_state#14], [_w2#18 DESC NULLS LAST]

(27) Filter [codegen id : 6]
Input [4]: [s_state#14, s_state#14, _w2#18, ranking#19]
Condition : (ranking#19 <= 5)

(28) Project [codegen id : 6]
Output [1]: [s_state#14]
Input [4]: [s_state#14, s_state#14, _w2#18, ranking#19]

(29) BroadcastExchange
Input [1]: [s_state#14]
Arguments: HashedRelationBroadcastMode(List(input[0, string, true]),false), [plan_id=3]

(30) BroadcastHashJoin [codegen id : 7]
Left keys [1]: [s_state#8]
Right keys [1]: [s_state#14]
Join condition: None

(31) BroadcastExchange
Input [3]: [s_store_sk#6, s_county#7, s_state#8]
Arguments: HashedRelationBroadcastMode(List(cast(input[0, int, false] as bigint)),false), [plan_id=4]

(32) BroadcastHashJoin [codegen id : 8]
Left keys [1]: [ss_store_sk#1]
Right keys [1]: [s_store_sk#6]
Join condition: None

(33) Project [codegen id : 8]
Output [3]: [ss_net_profit#2, s_county#7, s_state#8]
Input [5]: [ss_store_sk#1, ss_net_profit#2, s_store_sk#6, s_county#7, s_state#8]

(34) HashAggregate [codegen id : 8]
Input [3]: [ss_net_profit#2, s_county#7, s_state#8]
Keys [2]: [s_state#8, s_county#7]
Functions [1]: [partial_sum(UnscaledValue(ss_net_profit#2))]
Aggregate Attributes [1]: [sum#20]
Results [3]: [s_state#8, s_county#7, sum#21]

(35) Exchange
Input [3]: [s_state#8, s_county#7, sum#21]
Arguments: hashpartitioning(s_state#8, s_county#7, 5), ENSURE_REQUIREMENTS, [plan_id=5]

(36) HashAggregate [codegen id : 9]
Input [3]: [s_state#8, s_county#7, sum#21]
Keys [2]: [s_state#8, s_county#7]
Functions [1]: [sum(UnscaledValue(ss_net_profit#2))]
Aggregate Attributes [1]: [sum(UnscaledValue(ss_net_profit#2))#22]
Results [6]: [cast(MakeDecimal(sum(UnscaledValue(ss_net_profit#2))#22,17,2) as decimal(27,2)) AS total_sum#23, s_state#8, s_county#7, 0 AS g_state#24, 0 AS g_county#25, 0 AS lochierarchy#26]

(37) ReusedExchange [Reuses operator id: 35]
Output [3]: [s_state#8, s_county#7, sum#27]

(38) HashAggregate [codegen id : 18]
Input [3]: [s_state#8, s_county#7, sum#27]
Keys [2]: [s_state#8, s_county#7]
Functions [1]: [sum(UnscaledValue(ss_net_profit#2))]
Aggregate Attributes [1]: [sum(UnscaledValue(ss_net_profit#2))#22]
Results [2]: [MakeDecimal(sum(UnscaledValue(ss_net_profit#2))#22,17,2) AS total_sum#28, s_state#8]

(39) HashAggregate [codegen id : 18]
Input [2]: [total_sum#28, s_state#8]
Keys [1]: [s_state#8]
Functions [1]: [partial_sum(total_sum#28)]
Aggregate Attributes [2]: [sum#29, isEmpty#30]
Results [3]: [s_state#8, sum#31, isEmpty#32]

(40) Exchange
Input [3]: [s_state#8, sum#31, isEmpty#32]
Arguments: hashpartitioning(s_state#8, 5), ENSURE_REQUIREMENTS, [plan_id=6]

(41) HashAggregate [codegen id : 19]
Input [3]: [s_state#8, sum#31, isEmpty#32]
Keys [1]: [s_state#8]
Functions [1]: [sum(total_sum#28)]
Aggregate Attributes [1]: [sum(total_sum#28)#33]
Results [6]: [sum(total_sum#28)#33 AS total_sum#34, s_state#8, null AS s_county#35, 0 AS g_state#36, 1 AS g_county#37, 1 AS lochierarchy#38]

(42) ReusedExchange [Reuses operator id: 35]
Output [3]: [s_state#8, s_county#7, sum#39]

(43) HashAggregate [codegen id : 28]
Input [3]: [s_state#8, s_county#7, sum#39]
Keys [2]: [s_state#8, s_county#7]
Functions [1]: [sum(UnscaledValue(ss_net_profit#2))]
Aggregate Attributes [1]: [sum(UnscaledValue(ss_net_profit#2))#22]
Results [1]: [MakeDecimal(sum(UnscaledValue(ss_net_profit#2))#22,17,2) AS total_sum#28]

(44) HashAggregate [codegen id : 28]
Input [1]: [total_sum#28]
Keys: []
Functions [1]: [partial_sum(total_sum#28)]
Aggregate Attributes [2]: [sum#40, isEmpty#41]
Results [2]: [sum#42, isEmpty#43]

(45) Exchange
Input [2]: [sum#42, isEmpty#43]
Arguments: SinglePartition, ENSURE_REQUIREMENTS, [plan_id=7]

(46) HashAggregate [codegen id : 29]
Input [2]: [sum#42, isEmpty#43]
Keys: []
Functions [1]: [sum(total_sum#28)]
Aggregate Attributes [1]: [sum(total_sum#28)#44]
Results [6]: [sum(total_sum#28)#44 AS total_sum#45, null AS s_state#46, null AS s_county#47, 1 AS g_state#48, 1 AS g_county#49, 2 AS lochierarchy#50]

(47) Union

(48) HashAggregate [codegen id : 30]
Input [6]: [total_sum#23, s_state#8, s_county#7, g_state#24, g_county#25, lochierarchy#26]
Keys [6]: [total_sum#23, s_state#8, s_county#7, g_state#24, g_county#25, lochierarchy#26]
Functions: []
Aggregate Attributes: []
Results [6]: [total_sum#23, s_state#8, s_county#7, g_state#24, g_county#25, lochierarchy#26]

(49) Exchange
Input [6]: [total_sum#23, s_state#8, s_county#7, g_state#24, g_county#25, lochierarchy#26]
Arguments: hashpartitioning(total_sum#23, s_state#8, s_county#7, g_state#24, g_county#25, lochierarchy#26, 5), ENSURE_REQUIREMENTS, [plan_id=8]

(50) HashAggregate [codegen id : 31]
Input [6]: [total_sum#23, s_state#8, s_county#7, g_state#24, g_county#25, lochierarchy#26]
Keys [6]: [total_sum#23, s_state#8, s_county#7, g_state#24, g_county#25, lochierarchy#26]
Functions: []
Aggregate Attributes: []
Results [5]: [total_sum#23, s_state#8, s_county#7, lochierarchy#26, CASE WHEN (g_county#25 = 0) THEN s_state#8 END AS _w0#51]

(51) Exchange
Input [5]: [total_sum#23, s_state#8, s_county#7, lochierarchy#26, _w0#51]
Arguments: hashpartitioning(lochierarchy#26, _w0#51, 5), ENSURE_REQUIREMENTS, [plan_id=9]

(52) Sort [codegen id : 32]
Input [5]: [total_sum#23, s_state#8, s_county#7, lochierarchy#26, _w0#51]
Arguments: [lochierarchy#26 ASC NULLS FIRST, _w0#51 ASC NULLS FIRST, total_sum#23 DESC NULLS LAST], false, 0

(53) Window
Input [5]: [total_sum#23, s_state#8, s_county#7, lochierarchy#26, _w0#51]
Arguments: [rank(total_sum#23) windowspecdefinition(lochierarchy#26, _w0#51, total_sum#23 DESC NULLS LAST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS rank_within_parent#52], [lochierarchy#26, _w0#51], [total_sum#23 DESC NULLS LAST]

(54) Project [codegen id : 33]
Output [5]: [total_sum#23, s_state#8, s_county#7, lochierarchy#26, rank_within_parent#52]
Input [6]: [total_sum#23, s_state#8, s_county#7, lochierarchy#26, _w0#51, rank_within_parent#52]

(55) TakeOrderedAndProject
Input [5]: [total_sum#23, s_state#8, s_county#7, lochierarchy#26, rank_within_parent#52]
Arguments: 100, [lochierarchy#26 DESC NULLS LAST, CASE WHEN (lochierarchy#26 = 0) THEN s_state#8 END ASC NULLS FIRST, rank_within_parent#52 ASC NULLS FIRST], [total_sum#23, s_state#8, s_county#7, lochierarchy#26, rank_within_parent#52]

===== Subqueries =====

Subquery:1 Hosting operator id = 1 Hosting Expression = ss_sold_date_sk#3 IN dynamicpruning#4
BroadcastExchange (60)
+- * Project (59)
   +- * Filter (58)
      +- * ColumnarToRow (57)
         +- Scan parquet default.date_dim (56)


(56) Scan parquet default.date_dim
Output [2]: [d_date_sk#5, d_month_seq#53]
Batched: true
Location [not included in comparison]/{warehouse_dir}/date_dim]
PushedFilters: [IsNotNull(d_month_seq), GreaterThanOrEqual(d_month_seq,1212), LessThanOrEqual(d_month_seq,1223), IsNotNull(d_date_sk)]
ReadSchema: struct<d_date_sk:int,d_month_seq:int>

(57) ColumnarToRow [codegen id : 1]
Input [2]: [d_date_sk#5, d_month_seq#53]

(58) Filter [codegen id : 1]
Input [2]: [d_date_sk#5, d_month_seq#53]
Condition : (((isnotnull(d_month_seq#53) AND (d_month_seq#53 >= 1212)) AND (d_month_seq#53 <= 1223)) AND isnotnull(d_date_sk#5))

(59) Project [codegen id : 1]
Output [1]: [d_date_sk#5]
Input [2]: [d_date_sk#5, d_month_seq#53]

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

Subquery:2 Hosting operator id = 10 Hosting Expression = ss_sold_date_sk#11 IN dynamicpruning#4


