== Physical Plan ==
TakeOrderedAndProject (32)
+- * Project (31)
   +- * BroadcastHashJoin Inner BuildRight (30)
      :- * Project (28)
      :  +- * BroadcastHashJoin Inner BuildRight (27)
      :     :- * Project (22)
      :     :  +- * SortMergeJoin Inner (21)
      :     :     :- * Sort (14)
      :     :     :  +- * Project (13)
      :     :     :     +- * Filter (12)
      :     :     :        +- Window (11)
      :     :     :           +- * Sort (10)
      :     :     :              +- Exchange (9)
      :     :     :                 +- * Filter (8)
      :     :     :                    +- * HashAggregate (7)
      :     :     :                       +- Exchange (6)
      :     :     :                          +- * HashAggregate (5)
      :     :     :                             +- * Project (4)
      :     :     :                                +- * Filter (3)
      :     :     :                                   +- * ColumnarToRow (2)
      :     :     :                                      +- Scan parquet default.store_sales (1)
      :     :     +- * Sort (20)
      :     :        +- * Project (19)
      :     :           +- * Filter (18)
      :     :              +- Window (17)
      :     :                 +- * Sort (16)
      :     :                    +- ReusedExchange (15)
      :     +- BroadcastExchange (26)
      :        +- * Filter (25)
      :           +- * ColumnarToRow (24)
      :              +- Scan parquet default.item (23)
      +- ReusedExchange (29)


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

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

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

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

(5) HashAggregate [codegen id : 1]
Input [2]: [ss_item_sk#1, ss_net_profit#3]
Keys [1]: [ss_item_sk#1]
Functions [1]: [partial_avg(UnscaledValue(ss_net_profit#3))]
Aggregate Attributes [2]: [sum#5, count#6]
Results [3]: [ss_item_sk#1, sum#7, count#8]

(6) Exchange
Input [3]: [ss_item_sk#1, sum#7, count#8]
Arguments: hashpartitioning(ss_item_sk#1, 5), ENSURE_REQUIREMENTS, [id=#9]

(7) HashAggregate [codegen id : 2]
Input [3]: [ss_item_sk#1, sum#7, count#8]
Keys [1]: [ss_item_sk#1]
Functions [1]: [avg(UnscaledValue(ss_net_profit#3))]
Aggregate Attributes [1]: [avg(UnscaledValue(ss_net_profit#3))#10]
Results [2]: [ss_item_sk#1 AS item_sk#11, cast((avg(UnscaledValue(ss_net_profit#3))#10 / 100.0) as decimal(11,6)) AS rank_col#12]

(8) Filter [codegen id : 2]
Input [2]: [item_sk#11, rank_col#12]
Condition : (isnotnull(rank_col#12) AND (cast(rank_col#12 as decimal(13,7)) > CheckOverflow((0.900000 * promote_precision(Subquery scalar-subquery#13, [id=#14])), DecimalType(13,7))))

(9) Exchange
Input [2]: [item_sk#11, rank_col#12]
Arguments: SinglePartition, ENSURE_REQUIREMENTS, [id=#15]

(10) Sort [codegen id : 3]
Input [2]: [item_sk#11, rank_col#12]
Arguments: [rank_col#12 ASC NULLS FIRST], false, 0

(11) Window
Input [2]: [item_sk#11, rank_col#12]
Arguments: [rank(rank_col#12) windowspecdefinition(rank_col#12 ASC NULLS FIRST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS rnk#16], [rank_col#12 ASC NULLS FIRST]

(12) Filter [codegen id : 4]
Input [3]: [item_sk#11, rank_col#12, rnk#16]
Condition : ((rnk#16 < 11) AND isnotnull(item_sk#11))

(13) Project [codegen id : 4]
Output [2]: [item_sk#11, rnk#16]
Input [3]: [item_sk#11, rank_col#12, rnk#16]

(14) Sort [codegen id : 4]
Input [2]: [item_sk#11, rnk#16]
Arguments: [rnk#16 ASC NULLS FIRST], false, 0

(15) ReusedExchange [Reuses operator id: 9]
Output [2]: [item_sk#17, rank_col#18]

(16) Sort [codegen id : 7]
Input [2]: [item_sk#17, rank_col#18]
Arguments: [rank_col#18 DESC NULLS LAST], false, 0

(17) Window
Input [2]: [item_sk#17, rank_col#18]
Arguments: [rank(rank_col#18) windowspecdefinition(rank_col#18 DESC NULLS LAST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS rnk#19], [rank_col#18 DESC NULLS LAST]

(18) Filter [codegen id : 8]
Input [3]: [item_sk#17, rank_col#18, rnk#19]
Condition : ((rnk#19 < 11) AND isnotnull(item_sk#17))

(19) Project [codegen id : 8]
Output [2]: [item_sk#17, rnk#19]
Input [3]: [item_sk#17, rank_col#18, rnk#19]

(20) Sort [codegen id : 8]
Input [2]: [item_sk#17, rnk#19]
Arguments: [rnk#19 ASC NULLS FIRST], false, 0

(21) SortMergeJoin [codegen id : 11]
Left keys [1]: [rnk#16]
Right keys [1]: [rnk#19]
Join condition: None

(22) Project [codegen id : 11]
Output [3]: [item_sk#11, rnk#16, item_sk#17]
Input [4]: [item_sk#11, rnk#16, item_sk#17, rnk#19]

(23) Scan parquet default.item
Output [2]: [i_item_sk#20, i_product_name#21]
Batched: true
Location [not included in comparison]/{warehouse_dir}/item]
PushedFilters: [IsNotNull(i_item_sk)]
ReadSchema: struct<i_item_sk:int,i_product_name:string>

(24) ColumnarToRow [codegen id : 9]
Input [2]: [i_item_sk#20, i_product_name#21]

(25) Filter [codegen id : 9]
Input [2]: [i_item_sk#20, i_product_name#21]
Condition : isnotnull(i_item_sk#20)

(26) BroadcastExchange
Input [2]: [i_item_sk#20, i_product_name#21]
Arguments: HashedRelationBroadcastMode(List(cast(input[0, int, false] as bigint)),false), [id=#22]

(27) BroadcastHashJoin [codegen id : 11]
Left keys [1]: [item_sk#11]
Right keys [1]: [i_item_sk#20]
Join condition: None

(28) Project [codegen id : 11]
Output [3]: [rnk#16, item_sk#17, i_product_name#21]
Input [5]: [item_sk#11, rnk#16, item_sk#17, i_item_sk#20, i_product_name#21]

(29) ReusedExchange [Reuses operator id: 26]
Output [2]: [i_item_sk#23, i_product_name#24]

(30) BroadcastHashJoin [codegen id : 11]
Left keys [1]: [item_sk#17]
Right keys [1]: [i_item_sk#23]
Join condition: None

(31) Project [codegen id : 11]
Output [3]: [rnk#16, i_product_name#21 AS best_performing#25, i_product_name#24 AS worst_performing#26]
Input [5]: [rnk#16, item_sk#17, i_product_name#21, i_item_sk#23, i_product_name#24]

(32) TakeOrderedAndProject
Input [3]: [rnk#16, best_performing#25, worst_performing#26]
Arguments: 100, [rnk#16 ASC NULLS FIRST], [rnk#16, best_performing#25, worst_performing#26]

===== Subqueries =====

Subquery:1 Hosting operator id = 8 Hosting Expression = Subquery scalar-subquery#13, [id=#14]
* HashAggregate (39)
+- Exchange (38)
   +- * HashAggregate (37)
      +- * Project (36)
         +- * Filter (35)
            +- * ColumnarToRow (34)
               +- Scan parquet default.store_sales (33)


(33) Scan parquet default.store_sales
Output [4]: [ss_addr_sk#27, ss_store_sk#28, ss_net_profit#29, ss_sold_date_sk#30]
Batched: true
Location [not included in comparison]/{warehouse_dir}/store_sales]
PushedFilters: [IsNotNull(ss_store_sk), EqualTo(ss_store_sk,4), IsNull(ss_addr_sk)]
ReadSchema: struct<ss_addr_sk:int,ss_store_sk:int,ss_net_profit:decimal(7,2)>

(34) ColumnarToRow [codegen id : 1]
Input [4]: [ss_addr_sk#27, ss_store_sk#28, ss_net_profit#29, ss_sold_date_sk#30]

(35) Filter [codegen id : 1]
Input [4]: [ss_addr_sk#27, ss_store_sk#28, ss_net_profit#29, ss_sold_date_sk#30]
Condition : ((isnotnull(ss_store_sk#28) AND (ss_store_sk#28 = 4)) AND isnull(ss_addr_sk#27))

(36) Project [codegen id : 1]
Output [2]: [ss_store_sk#28, ss_net_profit#29]
Input [4]: [ss_addr_sk#27, ss_store_sk#28, ss_net_profit#29, ss_sold_date_sk#30]

(37) HashAggregate [codegen id : 1]
Input [2]: [ss_store_sk#28, ss_net_profit#29]
Keys [1]: [ss_store_sk#28]
Functions [1]: [partial_avg(UnscaledValue(ss_net_profit#29))]
Aggregate Attributes [2]: [sum#31, count#32]
Results [3]: [ss_store_sk#28, sum#33, count#34]

(38) Exchange
Input [3]: [ss_store_sk#28, sum#33, count#34]
Arguments: hashpartitioning(ss_store_sk#28, 5), ENSURE_REQUIREMENTS, [id=#35]

(39) HashAggregate [codegen id : 2]
Input [3]: [ss_store_sk#28, sum#33, count#34]
Keys [1]: [ss_store_sk#28]
Functions [1]: [avg(UnscaledValue(ss_net_profit#29))]
Aggregate Attributes [1]: [avg(UnscaledValue(ss_net_profit#29))#36]
Results [1]: [cast((avg(UnscaledValue(ss_net_profit#29))#36 / 100.0) as decimal(11,6)) AS rank_col#37]


