== Physical Plan ==
TakeOrderedAndProject (46)
+- * Project (45)
   +- Window (44)
      +- * Sort (43)
         +- Exchange (42)
            +- * HashAggregate (41)
               +- Exchange (40)
                  +- * HashAggregate (39)
                     +- * Expand (38)
                        +- * Project (37)
                           +- * BroadcastHashJoin Inner BuildRight (36)
                              :- * Project (10)
                              :  +- * BroadcastHashJoin Inner BuildRight (9)
                              :     :- * Filter (3)
                              :     :  +- * ColumnarToRow (2)
                              :     :     +- Scan parquet spark_catalog.default.store_sales (1)
                              :     +- BroadcastExchange (8)
                              :        +- * Project (7)
                              :           +- * Filter (6)
                              :              +- * ColumnarToRow (5)
                              :                 +- Scan parquet spark_catalog.default.date_dim (4)
                              +- BroadcastExchange (35)
                                 +- * BroadcastHashJoin LeftSemi BuildRight (34)
                                    :- * Filter (13)
                                    :  +- * ColumnarToRow (12)
                                    :     +- Scan parquet spark_catalog.default.store (11)
                                    +- BroadcastExchange (33)
                                       +- * Project (32)
                                          +- * Filter (31)
                                             +- Window (30)
                                                +- * Sort (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 spark_catalog.default.store_sales (14)
                                                                  :     +- BroadcastExchange (20)
                                                                  :        +- * Filter (19)
                                                                  :           +- * ColumnarToRow (18)
                                                                  :              +- Scan parquet spark_catalog.default.store (17)
                                                                  +- ReusedExchange (23)


(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)]
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) Scan parquet spark_catalog.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,1200), LessThanOrEqual(d_month_seq,1211), 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 >= 1200)) AND (d_month_seq#5 <= 1211)) 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), [plan_id=1]

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

(10) 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#4]

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

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

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

(14) 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)]
PushedFilters: [IsNotNull(ss_store_sk)]
ReadSchema: struct<ss_store_sk:int,ss_net_profit:decimal(7,2)>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

(34) BroadcastHashJoin [codegen id : 7]
Left keys [1]: [s_state#8]
Right keys [1]: [s_state#13]
Join type: LeftSemi
Join condition: None

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

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

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

(38) Expand [codegen id : 8]
Input [3]: [ss_net_profit#2, s_state#8, s_county#7]
Arguments: [[ss_net_profit#2, s_state#8, s_county#7, 0], [ss_net_profit#2, s_state#8, null, 1], [ss_net_profit#2, null, null, 3]], [ss_net_profit#2, s_state#20, s_county#21, spark_grouping_id#22]

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

(40) Exchange
Input [4]: [s_state#20, s_county#21, spark_grouping_id#22, sum#24]
Arguments: hashpartitioning(s_state#20, s_county#21, spark_grouping_id#22, 5), ENSURE_REQUIREMENTS, [plan_id=6]

(41) HashAggregate [codegen id : 9]
Input [4]: [s_state#20, s_county#21, spark_grouping_id#22, sum#24]
Keys [3]: [s_state#20, s_county#21, spark_grouping_id#22]
Functions [1]: [sum(UnscaledValue(ss_net_profit#2))]
Aggregate Attributes [1]: [sum(UnscaledValue(ss_net_profit#2))#25]
Results [7]: [MakeDecimal(sum(UnscaledValue(ss_net_profit#2))#25,17,2) AS total_sum#26, s_state#20, s_county#21, (cast((shiftright(spark_grouping_id#22, 1) & 1) as tinyint) + cast((shiftright(spark_grouping_id#22, 0) & 1) as tinyint)) AS lochierarchy#27, MakeDecimal(sum(UnscaledValue(ss_net_profit#2))#25,17,2) AS _w0#28, (cast((shiftright(spark_grouping_id#22, 1) & 1) as tinyint) + cast((shiftright(spark_grouping_id#22, 0) & 1) as tinyint)) AS _w1#29, CASE WHEN (cast((shiftright(spark_grouping_id#22, 0) & 1) as tinyint) = 0) THEN s_state#20 END AS _w2#30]

(42) Exchange
Input [7]: [total_sum#26, s_state#20, s_county#21, lochierarchy#27, _w0#28, _w1#29, _w2#30]
Arguments: hashpartitioning(_w1#29, _w2#30, 5), ENSURE_REQUIREMENTS, [plan_id=7]

(43) Sort [codegen id : 10]
Input [7]: [total_sum#26, s_state#20, s_county#21, lochierarchy#27, _w0#28, _w1#29, _w2#30]
Arguments: [_w1#29 ASC NULLS FIRST, _w2#30 ASC NULLS FIRST, _w0#28 DESC NULLS LAST], false, 0

(44) Window
Input [7]: [total_sum#26, s_state#20, s_county#21, lochierarchy#27, _w0#28, _w1#29, _w2#30]
Arguments: [rank(_w0#28) windowspecdefinition(_w1#29, _w2#30, _w0#28 DESC NULLS LAST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS rank_within_parent#31], [_w1#29, _w2#30], [_w0#28 DESC NULLS LAST]

(45) Project [codegen id : 11]
Output [5]: [total_sum#26, s_state#20, s_county#21, lochierarchy#27, rank_within_parent#31]
Input [8]: [total_sum#26, s_state#20, s_county#21, lochierarchy#27, _w0#28, _w1#29, _w2#30, rank_within_parent#31]

(46) TakeOrderedAndProject
Input [5]: [total_sum#26, s_state#20, s_county#21, lochierarchy#27, rank_within_parent#31]
Arguments: 100, [lochierarchy#27 DESC NULLS LAST, CASE WHEN (lochierarchy#27 = 0) THEN s_state#20 END ASC NULLS FIRST, rank_within_parent#31 ASC NULLS FIRST], [total_sum#26, s_state#20, s_county#21, lochierarchy#27, rank_within_parent#31]

