== 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)
      :     :     :                          +- * ColumnarToRow (5)
      :     :     :                             +- CometHashAggregate (4)
      :     :     :                                +- CometProject (3)
      :     :     :                                   +- CometFilter (2)
      :     :     :                                      +- CometScan parquet spark_catalog.default.store_sales (1)
      :     :     +- * Sort (20)
      :     :        +- * Project (19)
      :     :           +- * Filter (18)
      :     :              +- Window (17)
      :     :                 +- * Sort (16)
      :     :                    +- ReusedExchange (15)
      :     +- BroadcastExchange (26)
      :        +- * ColumnarToRow (25)
      :           +- CometFilter (24)
      :              +- CometScan parquet spark_catalog.default.item (23)
      +- ReusedExchange (29)


(1) Scan parquet spark_catalog.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) CometFilter
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))

(3) CometProject
Input [4]: [ss_item_sk#1, ss_store_sk#2, ss_net_profit#3, ss_sold_date_sk#4]
Arguments: [ss_item_sk#1, ss_net_profit#3], [ss_item_sk#1, ss_net_profit#3]

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

(5) ColumnarToRow [codegen id : 1]
Input [3]: [ss_item_sk#1, sum#5, count#6]

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

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

(8) Filter [codegen id : 2]
Input [2]: [item_sk#8, rank_col#9]
Condition : (isnotnull(rank_col#9) AND (cast(rank_col#9 as decimal(13,7)) > (0.9 * Subquery scalar-subquery#10, [id=#11])))

(9) Exchange
Input [2]: [item_sk#8, rank_col#9]
Arguments: SinglePartition, ENSURE_REQUIREMENTS, [plan_id=2]

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

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

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

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

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

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

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

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

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

(19) Project [codegen id : 8]
Output [2]: [item_sk#13, rnk#15]
Input [3]: [item_sk#13, rank_col#14, rnk#15]

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

(21) SortMergeJoin [codegen id : 11]
Left keys [1]: [rnk#12]
Right keys [1]: [rnk#15]
Join type: Inner
Join condition: None

(22) Project [codegen id : 11]
Output [3]: [item_sk#8, rnk#12, item_sk#13]
Input [4]: [item_sk#8, rnk#12, item_sk#13, rnk#15]

(23) Scan parquet spark_catalog.default.item
Output [2]: [i_item_sk#16, i_product_name#17]
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) CometFilter
Input [2]: [i_item_sk#16, i_product_name#17]
Condition : isnotnull(i_item_sk#16)

(25) ColumnarToRow [codegen id : 9]
Input [2]: [i_item_sk#16, i_product_name#17]

(26) BroadcastExchange
Input [2]: [i_item_sk#16, i_product_name#17]
Arguments: HashedRelationBroadcastMode(List(cast(input[0, int, false] as bigint)),false), [plan_id=3]

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

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

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

(30) BroadcastHashJoin [codegen id : 11]
Left keys [1]: [item_sk#13]
Right keys [1]: [i_item_sk#18]
Join type: Inner
Join condition: None

(31) Project [codegen id : 11]
Output [3]: [rnk#12, i_product_name#17 AS best_performing#20, i_product_name#19 AS worst_performing#21]
Input [5]: [rnk#12, item_sk#13, i_product_name#17, i_item_sk#18, i_product_name#19]

(32) TakeOrderedAndProject
Input [3]: [rnk#12, best_performing#20, worst_performing#21]
Arguments: 100, [rnk#12 ASC NULLS FIRST], [rnk#12, best_performing#20, worst_performing#21]

===== Subqueries =====

Subquery:1 Hosting operator id = 8 Hosting Expression = Subquery scalar-subquery#10, [id=#11]
* HashAggregate (39)
+- Exchange (38)
   +- * ColumnarToRow (37)
      +- CometHashAggregate (36)
         +- CometProject (35)
            +- CometFilter (34)
               +- CometScan parquet spark_catalog.default.store_sales (33)


(33) Scan parquet spark_catalog.default.store_sales
Output [4]: [ss_addr_sk#22, ss_store_sk#23, ss_net_profit#24, ss_sold_date_sk#25]
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) CometFilter
Input [4]: [ss_addr_sk#22, ss_store_sk#23, ss_net_profit#24, ss_sold_date_sk#25]
Condition : ((isnotnull(ss_store_sk#23) AND (ss_store_sk#23 = 4)) AND isnull(ss_addr_sk#22))

(35) CometProject
Input [4]: [ss_addr_sk#22, ss_store_sk#23, ss_net_profit#24, ss_sold_date_sk#25]
Arguments: [ss_store_sk#23, ss_net_profit#24], [ss_store_sk#23, ss_net_profit#24]

(36) CometHashAggregate
Input [2]: [ss_store_sk#23, ss_net_profit#24]
Keys [1]: [ss_store_sk#23]
Functions [1]: [partial_avg(UnscaledValue(ss_net_profit#24))]

(37) ColumnarToRow [codegen id : 1]
Input [3]: [ss_store_sk#23, sum#26, count#27]

(38) Exchange
Input [3]: [ss_store_sk#23, sum#26, count#27]
Arguments: hashpartitioning(ss_store_sk#23, 5), ENSURE_REQUIREMENTS, [plan_id=4]

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


