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


(1) Scan parquet default.store_sales
Output [3]: [ss_sold_date_sk#1, ss_store_sk#2, ss_net_profit#3]
Batched: true
Location [not included in comparison]/{warehouse_dir}/store_sales]
PushedFilters: [IsNotNull(ss_sold_date_sk), IsNotNull(ss_store_sk)]
ReadSchema: struct<ss_sold_date_sk:int,ss_store_sk:int,ss_net_profit:decimal(7,2)>

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

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

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

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

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

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

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

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

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

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

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

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

(14) Scan parquet default.store_sales
Output [3]: [ss_sold_date_sk#1, ss_store_sk#2, ss_net_profit#3]
Batched: true
Location [not included in comparison]/{warehouse_dir}/store_sales]
PushedFilters: [IsNotNull(ss_store_sk), IsNotNull(ss_sold_date_sk)]
ReadSchema: struct<ss_sold_date_sk:int,ss_store_sk:int,ss_net_profit:decimal(7,2)>

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

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

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

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

(19) Filter [codegen id : 2]
Input [2]: [s_store_sk#7, s_state#9]
Condition : isnotnull(s_store_sk#7)

(20) BroadcastExchange
Input [2]: [s_store_sk#7, s_state#9]
Arguments: HashedRelationBroadcastMode(List(cast(input[0, int, false] as bigint)),false), [id=#10]

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

(22) Project [codegen id : 4]
Output [3]: [ss_sold_date_sk#1, ss_net_profit#3, s_state#9]
Input [5]: [ss_sold_date_sk#1, ss_store_sk#2, ss_net_profit#3, s_store_sk#7, s_state#9]

(23) ReusedExchange [Reuses operator id: 8]
Output [1]: [d_date_sk#4]

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

(25) Project [codegen id : 4]
Output [2]: [ss_net_profit#3, s_state#9]
Input [4]: [ss_sold_date_sk#1, ss_net_profit#3, s_state#9, d_date_sk#4]

(26) HashAggregate [codegen id : 4]
Input [2]: [ss_net_profit#3, s_state#9]
Keys [1]: [s_state#9]
Functions [1]: [partial_sum(UnscaledValue(ss_net_profit#3))]
Aggregate Attributes [1]: [sum#11]
Results [2]: [s_state#9, sum#12]

(27) Exchange
Input [2]: [s_state#9, sum#12]
Arguments: hashpartitioning(s_state#9, 5), true, [id=#13]

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

(29) Exchange
Input [3]: [s_state#15, s_state#9, _w2#16]
Arguments: hashpartitioning(s_state#9, 5), true, [id=#17]

(30) Sort [codegen id : 6]
Input [3]: [s_state#15, s_state#9, _w2#16]
Arguments: [s_state#9 ASC NULLS FIRST, _w2#16 DESC NULLS LAST], false, 0

(31) Window
Input [3]: [s_state#15, s_state#9, _w2#16]
Arguments: [rank(_w2#16) windowspecdefinition(s_state#9, _w2#16 DESC NULLS LAST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS ranking#18], [s_state#9], [_w2#16 DESC NULLS LAST]

(32) Filter [codegen id : 7]
Input [4]: [s_state#15, s_state#9, _w2#16, ranking#18]
Condition : (isnotnull(ranking#18) AND (ranking#18 <= 5))

(33) Project [codegen id : 7]
Output [1]: [s_state#15]
Input [4]: [s_state#15, s_state#9, _w2#16, ranking#18]

(34) BroadcastExchange
Input [1]: [s_state#15]
Arguments: HashedRelationBroadcastMode(List(input[0, string, true]),false), [id=#19]

(35) BroadcastHashJoin [codegen id : 8]
Left keys [1]: [s_state#9]
Right keys [1]: [s_state#15]
Join condition: None

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

(37) BroadcastHashJoin [codegen id : 9]
Left keys [1]: [ss_store_sk#2]
Right keys [1]: [s_store_sk#7]
Join condition: None

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

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

(40) Exchange
Input [3]: [s_state#9, s_county#8, sum#22]
Arguments: hashpartitioning(s_state#9, s_county#8, 5), true, [id=#23]

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

(42) ReusedExchange [Reuses operator id: 40]
Output [3]: [s_state#9, s_county#8, sum#29]

(43) HashAggregate [codegen id : 20]
Input [3]: [s_state#9, s_county#8, sum#29]
Keys [2]: [s_state#9, s_county#8]
Functions [1]: [sum(UnscaledValue(ss_net_profit#3))]
Aggregate Attributes [1]: [sum(UnscaledValue(ss_net_profit#3))#30]
Results [2]: [MakeDecimal(sum(UnscaledValue(ss_net_profit#3))#30,17,2) AS total_sum#31, s_state#9]

(44) HashAggregate [codegen id : 20]
Input [2]: [total_sum#31, s_state#9]
Keys [1]: [s_state#9]
Functions [1]: [partial_sum(total_sum#31)]
Aggregate Attributes [2]: [sum#32, isEmpty#33]
Results [3]: [s_state#9, sum#34, isEmpty#35]

(45) Exchange
Input [3]: [s_state#9, sum#34, isEmpty#35]
Arguments: hashpartitioning(s_state#9, 5), true, [id=#36]

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

(47) Union

(48) HashAggregate [codegen id : 22]
Input [6]: [total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28]
Keys [6]: [total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28]
Functions: []
Aggregate Attributes: []
Results [6]: [total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28]

(49) Exchange
Input [6]: [total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28]
Arguments: hashpartitioning(total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28, 5), true, [id=#43]

(50) HashAggregate [codegen id : 23]
Input [6]: [total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28]
Keys [6]: [total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28]
Functions: []
Aggregate Attributes: []
Results [6]: [total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28]

(51) ReusedExchange [Reuses operator id: 40]
Output [3]: [s_state#9, s_county#8, sum#44]

(52) HashAggregate [codegen id : 33]
Input [3]: [s_state#9, s_county#8, sum#44]
Keys [2]: [s_state#9, s_county#8]
Functions [1]: [sum(UnscaledValue(ss_net_profit#3))]
Aggregate Attributes [1]: [sum(UnscaledValue(ss_net_profit#3))#45]
Results [1]: [MakeDecimal(sum(UnscaledValue(ss_net_profit#3))#45,17,2) AS total_sum#31]

(53) HashAggregate [codegen id : 33]
Input [1]: [total_sum#31]
Keys: []
Functions [1]: [partial_sum(total_sum#31)]
Aggregate Attributes [2]: [sum#46, isEmpty#47]
Results [2]: [sum#48, isEmpty#49]

(54) Exchange
Input [2]: [sum#48, isEmpty#49]
Arguments: SinglePartition, true, [id=#50]

(55) HashAggregate [codegen id : 34]
Input [2]: [sum#48, isEmpty#49]
Keys: []
Functions [1]: [sum(total_sum#31)]
Aggregate Attributes [1]: [sum(total_sum#31)#51]
Results [6]: [sum(total_sum#31)#51 AS total_sum#52, null AS s_state#53, null AS s_county#54, 1 AS g_state#55, 1 AS g_county#56, 2 AS lochierarchy#57]

(56) Union

(57) HashAggregate [codegen id : 35]
Input [6]: [total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28]
Keys [6]: [total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28]
Functions: []
Aggregate Attributes: []
Results [6]: [total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28]

(58) Exchange
Input [6]: [total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28]
Arguments: hashpartitioning(total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28, 5), true, [id=#58]

(59) HashAggregate [codegen id : 36]
Input [6]: [total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28]
Keys [6]: [total_sum#25, s_state#9, s_county#8, g_state#26, g_county#27, lochierarchy#28]
Functions: []
Aggregate Attributes: []
Results [5]: [total_sum#25, s_state#9, s_county#8, lochierarchy#28, CASE WHEN (g_county#27 = 0) THEN s_state#9 END AS _w0#59]

(60) Exchange
Input [5]: [total_sum#25, s_state#9, s_county#8, lochierarchy#28, _w0#59]
Arguments: hashpartitioning(lochierarchy#28, _w0#59, 5), true, [id=#60]

(61) Sort [codegen id : 37]
Input [5]: [total_sum#25, s_state#9, s_county#8, lochierarchy#28, _w0#59]
Arguments: [lochierarchy#28 ASC NULLS FIRST, _w0#59 ASC NULLS FIRST, total_sum#25 DESC NULLS LAST], false, 0

(62) Window
Input [5]: [total_sum#25, s_state#9, s_county#8, lochierarchy#28, _w0#59]
Arguments: [rank(total_sum#25) windowspecdefinition(lochierarchy#28, _w0#59, total_sum#25 DESC NULLS LAST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS rank_within_parent#61], [lochierarchy#28, _w0#59], [total_sum#25 DESC NULLS LAST]

(63) Project [codegen id : 38]
Output [5]: [total_sum#25, s_state#9, s_county#8, lochierarchy#28, rank_within_parent#61]
Input [6]: [total_sum#25, s_state#9, s_county#8, lochierarchy#28, _w0#59, rank_within_parent#61]

(64) TakeOrderedAndProject
Input [5]: [total_sum#25, s_state#9, s_county#8, lochierarchy#28, rank_within_parent#61]
Arguments: 100, [lochierarchy#28 DESC NULLS LAST, CASE WHEN (lochierarchy#28 = 0) THEN s_state#9 END ASC NULLS FIRST, rank_within_parent#61 ASC NULLS FIRST], [total_sum#25, s_state#9, s_county#8, lochierarchy#28, rank_within_parent#61]

