== 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 spark_catalog.default.store_sales (1)
                        :              :     +- ReusedExchange (4)
                        :              +- BroadcastExchange (32)
                        :                 +- * BroadcastHashJoin LeftSemi BuildRight (31)
                        :                    :- * Filter (9)
                        :                    :  +- * ColumnarToRow (8)
                        :                    :     +- Scan parquet spark_catalog.default.store (7)
                        :                    +- BroadcastExchange (30)
                        :                       +- * Project (29)
                        :                          +- * Filter (28)
                        :                             +- Window (27)
                        :                                +- WindowGroupLimit (26)
                        :                                   +- * Sort (25)
                        :                                      +- * HashAggregate (24)
                        :                                         +- Exchange (23)
                        :                                            +- * HashAggregate (22)
                        :                                               +- * Project (21)
                        :                                                  +- * BroadcastHashJoin Inner BuildRight (20)
                        :                                                     :- * Project (18)
                        :                                                     :  +- * BroadcastHashJoin Inner BuildRight (17)
                        :                                                     :     :- * Filter (12)
                        :                                                     :     :  +- * ColumnarToRow (11)
                        :                                                     :     :     +- Scan parquet spark_catalog.default.store_sales (10)
                        :                                                     :     +- BroadcastExchange (16)
                        :                                                     :        +- * Filter (15)
                        :                                                     :           +- * ColumnarToRow (14)
                        :                                                     :              +- Scan parquet spark_catalog.default.store (13)
                        :                                                     +- ReusedExchange (19)
                        :- * HashAggregate (42)
                        :  +- Exchange (41)
                        :     +- * HashAggregate (40)
                        :        +- * HashAggregate (39)
                        :           +- ReusedExchange (38)
                        +- * HashAggregate (47)
                           +- Exchange (46)
                              +- * HashAggregate (45)
                                 +- * HashAggregate (44)
                                    +- ReusedExchange (43)


(1) Scan parquet spark_catalog.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: 61]
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 type: Inner
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 spark_catalog.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 spark_catalog.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) Scan parquet spark_catalog.default.store
Output [2]: [s_store_sk#12, s_state#13]
Batched: true
Location [not included in comparison]/{warehouse_dir}/store]
PushedFilters: [IsNotNull(s_store_sk)]
ReadSchema: struct<s_store_sk:int,s_state:string>

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

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

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

(17) BroadcastHashJoin [codegen id : 4]
Left keys [1]: [ss_store_sk#9]
Right keys [1]: [s_store_sk#12]
Join type: Inner
Join condition: None

(18) Project [codegen id : 4]
Output [3]: [ss_net_profit#10, ss_sold_date_sk#11, s_state#13]
Input [5]: [ss_store_sk#9, ss_net_profit#10, ss_sold_date_sk#11, s_store_sk#12, s_state#13]

(19) ReusedExchange [Reuses operator id: 61]
Output [1]: [d_date_sk#14]

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

(21) Project [codegen id : 4]
Output [2]: [ss_net_profit#10, s_state#13]
Input [4]: [ss_net_profit#10, ss_sold_date_sk#11, s_state#13, d_date_sk#14]

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

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

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

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

(26) WindowGroupLimit
Input [3]: [s_state#13, _w0#18, s_state#13]
Arguments: [s_state#13], [_w0#18 DESC NULLS LAST], rank(_w0#18), 5, Final

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

(28) Filter [codegen id : 6]
Input [4]: [s_state#13, _w0#18, s_state#13, ranking#19]
Condition : (ranking#19 <= 5)

(29) Project [codegen id : 6]
Output [1]: [s_state#13]
Input [4]: [s_state#13, _w0#18, s_state#13, ranking#19]

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

(31) BroadcastHashJoin [codegen id : 7]
Left keys [1]: [s_state#8]
Right keys [1]: [s_state#13]
Join type: LeftSemi
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), [plan_id=4]

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

(34) 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]

(35) 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]

(36) 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]

(37) 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]

(38) ReusedExchange [Reuses operator id: 36]
Output [3]: [s_state#27, s_county#28, sum#29]

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

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

(41) Exchange
Input [3]: [s_state#27, sum#34, isEmpty#35]
Arguments: hashpartitioning(s_state#27, 5), ENSURE_REQUIREMENTS, [plan_id=6]

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

(43) ReusedExchange [Reuses operator id: 36]
Output [3]: [s_state#42, s_county#43, sum#44]

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

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

(46) Exchange
Input [2]: [sum#49, isEmpty#50]
Arguments: SinglePartition, ENSURE_REQUIREMENTS, [plan_id=7]

(47) HashAggregate [codegen id : 29]
Input [2]: [sum#49, isEmpty#50]
Keys: []
Functions [1]: [sum(total_sum#46)]
Aggregate Attributes [1]: [sum(total_sum#46)#51]
Results [6]: [sum(total_sum#46)#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]

(48) Union

(49) 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]

(50) 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]

(51) 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#58]

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

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

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

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

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

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


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

(59) Filter [codegen id : 1]
Input [2]: [d_date_sk#5, d_month_seq#60]
Condition : (((isnotnull(d_month_seq#60) AND (d_month_seq#60 >= 1212)) AND (d_month_seq#60 <= 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#60]

(61) 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


