== Physical Plan ==
TakeOrderedAndProject (56)
+- * Project (55)
   +- Window (54)
      +- * Sort (53)
         +- Exchange (52)
            +- * HashAggregate (51)
               +- Exchange (50)
                  +- * HashAggregate (49)
                     +- Union (48)
                        :- * HashAggregate (37)
                        :  +- Exchange (36)
                        :     +- * HashAggregate (35)
                        :        +- * Project (34)
                        :           +- * BroadcastHashJoin Inner BuildRight (33)
                        :              :- * Project (6)
                        :              :  +- * BroadcastHashJoin Inner BuildRight (5)
                        :              :     :- * Filter (3)
                        :              :     :  +- * ColumnarToRow (2)
                        :              :     :     +- Scan parquet default.store_sales (1)
                        :              :     +- ReusedExchange (4)
                        :              +- BroadcastExchange (32)
                        :                 +- * BroadcastHashJoin LeftSemi BuildRight (31)
                        :                    :- * Filter (9)
                        :                    :  +- * ColumnarToRow (8)
                        :                    :     +- Scan parquet default.store (7)
                        :                    +- BroadcastExchange (30)
                        :                       +- * Project (29)
                        :                          +- * Filter (28)
                        :                             +- Window (27)
                        :                                +- * Sort (26)
                        :                                   +- Exchange (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 (42)
                        :  +- Exchange (41)
                        :     +- * HashAggregate (40)
                        :        +- * HashAggregate (39)
                        :           +- ReusedExchange (38)
                        +- * HashAggregate (47)
                           +- Exchange (46)
                              +- * HashAggregate (45)
                                 +- * HashAggregate (44)
                                    +- ReusedExchange (43)


(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 : 9]
Input [3]: [ss_store_sk#1, ss_net_profit#2, ss_sold_date_sk#3]

(3) Filter [codegen id : 9]
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: 61]
Output [1]: [d_date_sk#5]

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

(6) Project [codegen id : 9]
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 : 8]
Input [3]: [s_store_sk#6, s_county#7, s_state#8]

(9) Filter [codegen id : 8]
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: 61]
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), [id=#15]

(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#16]
Results [2]: [s_state#14, sum#17]

(23) Exchange
Input [2]: [s_state#14, sum#17]
Arguments: hashpartitioning(s_state#14, 5), ENSURE_REQUIREMENTS, [id=#18]

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

(25) Exchange
Input [3]: [s_state#20, s_state#14, _w2#21]
Arguments: hashpartitioning(s_state#14, 5), ENSURE_REQUIREMENTS, [id=#22]

(26) Sort [codegen id : 6]
Input [3]: [s_state#20, s_state#14, _w2#21]
Arguments: [s_state#14 ASC NULLS FIRST, _w2#21 DESC NULLS LAST], false, 0

(27) Window
Input [3]: [s_state#20, s_state#14, _w2#21]
Arguments: [rank(_w2#21) windowspecdefinition(s_state#14, _w2#21 DESC NULLS LAST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS ranking#23], [s_state#14], [_w2#21 DESC NULLS LAST]

(28) Filter [codegen id : 7]
Input [4]: [s_state#20, s_state#14, _w2#21, ranking#23]
Condition : (ranking#23 <= 5)

(29) Project [codegen id : 7]
Output [1]: [s_state#20]
Input [4]: [s_state#20, s_state#14, _w2#21, ranking#23]

(30) BroadcastExchange
Input [1]: [s_state#20]
Arguments: HashedRelationBroadcastMode(List(input[0, string, true]),false), [id=#24]

(31) BroadcastHashJoin [codegen id : 8]
Left keys [1]: [s_state#8]
Right keys [1]: [s_state#20]
Join condition: None

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

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

(34) Project [codegen id : 9]
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]

(35) HashAggregate [codegen id : 9]
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#26]
Results [3]: [s_state#8, s_county#7, sum#27]

(36) Exchange
Input [3]: [s_state#8, s_county#7, sum#27]
Arguments: hashpartitioning(s_state#8, s_county#7, 5), ENSURE_REQUIREMENTS, [id=#28]

(37) HashAggregate [codegen id : 10]
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))#29]
Results [6]: [cast(MakeDecimal(sum(UnscaledValue(ss_net_profit#2))#29,17,2) as decimal(27,2)) AS total_sum#30, s_state#8, s_county#7, 0 AS g_state#31, 0 AS g_county#32, 0 AS lochierarchy#33]

(38) ReusedExchange [Reuses operator id: 36]
Output [3]: [s_state#8, s_county#7, sum#34]

(39) HashAggregate [codegen id : 20]
Input [3]: [s_state#8, s_county#7, sum#34]
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))#29]
Results [2]: [MakeDecimal(sum(UnscaledValue(ss_net_profit#2))#29,17,2) AS total_sum#35, s_state#8]

(40) HashAggregate [codegen id : 20]
Input [2]: [total_sum#35, s_state#8]
Keys [1]: [s_state#8]
Functions [1]: [partial_sum(total_sum#35)]
Aggregate Attributes [2]: [sum#36, isEmpty#37]
Results [3]: [s_state#8, sum#38, isEmpty#39]

(41) Exchange
Input [3]: [s_state#8, sum#38, isEmpty#39]
Arguments: hashpartitioning(s_state#8, 5), ENSURE_REQUIREMENTS, [id=#40]

(42) HashAggregate [codegen id : 21]
Input [3]: [s_state#8, sum#38, isEmpty#39]
Keys [1]: [s_state#8]
Functions [1]: [sum(total_sum#35)]
Aggregate Attributes [1]: [sum(total_sum#35)#41]
Results [6]: [sum(total_sum#35)#41 AS total_sum#42, s_state#8, null AS s_county#43, 0 AS g_state#44, 1 AS g_county#45, 1 AS lochierarchy#46]

(43) ReusedExchange [Reuses operator id: 36]
Output [3]: [s_state#8, s_county#7, sum#47]

(44) HashAggregate [codegen id : 31]
Input [3]: [s_state#8, s_county#7, sum#47]
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))#29]
Results [1]: [MakeDecimal(sum(UnscaledValue(ss_net_profit#2))#29,17,2) AS total_sum#35]

(45) HashAggregate [codegen id : 31]
Input [1]: [total_sum#35]
Keys: []
Functions [1]: [partial_sum(total_sum#35)]
Aggregate Attributes [2]: [sum#48, isEmpty#49]
Results [2]: [sum#50, isEmpty#51]

(46) Exchange
Input [2]: [sum#50, isEmpty#51]
Arguments: SinglePartition, ENSURE_REQUIREMENTS, [id=#52]

(47) HashAggregate [codegen id : 32]
Input [2]: [sum#50, isEmpty#51]
Keys: []
Functions [1]: [sum(total_sum#35)]
Aggregate Attributes [1]: [sum(total_sum#35)#53]
Results [6]: [sum(total_sum#35)#53 AS total_sum#54, null AS s_state#55, null AS s_county#56, 1 AS g_state#57, 1 AS g_county#58, 2 AS lochierarchy#59]

(48) Union

(49) HashAggregate [codegen id : 33]
Input [6]: [total_sum#30, s_state#8, s_county#7, g_state#31, g_county#32, lochierarchy#33]
Keys [6]: [total_sum#30, s_state#8, s_county#7, g_state#31, g_county#32, lochierarchy#33]
Functions: []
Aggregate Attributes: []
Results [6]: [total_sum#30, s_state#8, s_county#7, g_state#31, g_county#32, lochierarchy#33]

(50) Exchange
Input [6]: [total_sum#30, s_state#8, s_county#7, g_state#31, g_county#32, lochierarchy#33]
Arguments: hashpartitioning(total_sum#30, s_state#8, s_county#7, g_state#31, g_county#32, lochierarchy#33, 5), ENSURE_REQUIREMENTS, [id=#60]

(51) HashAggregate [codegen id : 34]
Input [6]: [total_sum#30, s_state#8, s_county#7, g_state#31, g_county#32, lochierarchy#33]
Keys [6]: [total_sum#30, s_state#8, s_county#7, g_state#31, g_county#32, lochierarchy#33]
Functions: []
Aggregate Attributes: []
Results [5]: [total_sum#30, s_state#8, s_county#7, lochierarchy#33, CASE WHEN (g_county#32 = 0) THEN s_state#8 END AS _w0#61]

(52) Exchange
Input [5]: [total_sum#30, s_state#8, s_county#7, lochierarchy#33, _w0#61]
Arguments: hashpartitioning(lochierarchy#33, _w0#61, 5), ENSURE_REQUIREMENTS, [id=#62]

(53) Sort [codegen id : 35]
Input [5]: [total_sum#30, s_state#8, s_county#7, lochierarchy#33, _w0#61]
Arguments: [lochierarchy#33 ASC NULLS FIRST, _w0#61 ASC NULLS FIRST, total_sum#30 DESC NULLS LAST], false, 0

(54) Window
Input [5]: [total_sum#30, s_state#8, s_county#7, lochierarchy#33, _w0#61]
Arguments: [rank(total_sum#30) windowspecdefinition(lochierarchy#33, _w0#61, total_sum#30 DESC NULLS LAST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS rank_within_parent#63], [lochierarchy#33, _w0#61], [total_sum#30 DESC NULLS LAST]

(55) Project [codegen id : 36]
Output [5]: [total_sum#30, s_state#8, s_county#7, lochierarchy#33, rank_within_parent#63]
Input [6]: [total_sum#30, s_state#8, s_county#7, lochierarchy#33, _w0#61, rank_within_parent#63]

(56) TakeOrderedAndProject
Input [5]: [total_sum#30, s_state#8, s_county#7, lochierarchy#33, rank_within_parent#63]
Arguments: 100, [lochierarchy#33 DESC NULLS LAST, CASE WHEN (lochierarchy#33 = 0) THEN s_state#8 END ASC NULLS FIRST, rank_within_parent#63 ASC NULLS FIRST], [total_sum#30, s_state#8, s_county#7, lochierarchy#33, rank_within_parent#63]

===== Subqueries =====

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


(57) Scan parquet default.date_dim
Output [2]: [d_date_sk#5, d_month_seq#64]
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>

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

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

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

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

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


