== Physical Plan ==
TakeOrderedAndProject (46)
+- * Project (45)
   +- * BroadcastHashJoin Inner BuildRight (44)
      :- * Project (42)
      :  +- * BroadcastHashJoin Inner BuildRight (41)
      :     :- * Project (36)
      :     :  +- * SortMergeJoin Inner (35)
      :     :     :- * Sort (19)
      :     :     :  +- * Project (18)
      :     :     :     +- * Filter (17)
      :     :     :        +- Window (16)
      :     :     :           +- WindowGroupLimit (15)
      :     :     :              +- * ColumnarToRow (14)
      :     :     :                 +- CometSort (13)
      :     :     :                    +- CometColumnarExchange (12)
      :     :     :                       +- RowToColumnar (11)
      :     :     :                          +- WindowGroupLimit (10)
      :     :     :                             +- * ColumnarToRow (9)
      :     :     :                                +- CometSort (8)
      :     :     :                                   +- CometFilter (7)
      :     :     :                                      +- CometHashAggregate (6)
      :     :     :                                         +- CometColumnarExchange (5)
      :     :     :                                            +- CometHashAggregate (4)
      :     :     :                                               +- CometProject (3)
      :     :     :                                                  +- CometFilter (2)
      :     :     :                                                     +- CometScan parquet spark_catalog.default.store_sales (1)
      :     :     +- * Sort (34)
      :     :        +- * Project (33)
      :     :           +- * Filter (32)
      :     :              +- Window (31)
      :     :                 +- WindowGroupLimit (30)
      :     :                    +- * ColumnarToRow (29)
      :     :                       +- CometSort (28)
      :     :                          +- CometColumnarExchange (27)
      :     :                             +- RowToColumnar (26)
      :     :                                +- WindowGroupLimit (25)
      :     :                                   +- * ColumnarToRow (24)
      :     :                                      +- CometSort (23)
      :     :                                         +- CometFilter (22)
      :     :                                            +- CometHashAggregate (21)
      :     :                                               +- ReusedExchange (20)
      :     +- BroadcastExchange (40)
      :        +- * ColumnarToRow (39)
      :           +- CometFilter (38)
      :              +- CometScan parquet spark_catalog.default.item (37)
      +- ReusedExchange (43)


(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) CometColumnarExchange
Input [3]: [ss_item_sk#1, sum#5, count#6]
Arguments: hashpartitioning(ss_item_sk#1, 5), ENSURE_REQUIREMENTS, CometColumnarShuffle, [plan_id=1]

(6) CometHashAggregate
Input [3]: [ss_item_sk#1, sum#5, count#6]
Keys [1]: [ss_item_sk#1]
Functions [1]: [avg(UnscaledValue(ss_net_profit#3))]

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

(8) CometSort
Input [2]: [item_sk#7, rank_col#8]
Arguments: [item_sk#7, rank_col#8], [rank_col#8 ASC NULLS FIRST]

(9) ColumnarToRow [codegen id : 1]
Input [2]: [item_sk#7, rank_col#8]

(10) WindowGroupLimit
Input [2]: [item_sk#7, rank_col#8]
Arguments: [rank_col#8 ASC NULLS FIRST], rank(rank_col#8), 10, Partial

(11) RowToColumnar
Input [2]: [item_sk#7, rank_col#8]

(12) CometColumnarExchange
Input [2]: [item_sk#7, rank_col#8]
Arguments: SinglePartition, ENSURE_REQUIREMENTS, CometColumnarShuffle, [plan_id=2]

(13) CometSort
Input [2]: [item_sk#7, rank_col#8]
Arguments: [item_sk#7, rank_col#8], [rank_col#8 ASC NULLS FIRST]

(14) ColumnarToRow [codegen id : 2]
Input [2]: [item_sk#7, rank_col#8]

(15) WindowGroupLimit
Input [2]: [item_sk#7, rank_col#8]
Arguments: [rank_col#8 ASC NULLS FIRST], rank(rank_col#8), 10, Final

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

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

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

(19) Sort [codegen id : 3]
Input [2]: [item_sk#7, rnk#11]
Arguments: [rnk#11 ASC NULLS FIRST], false, 0

(20) ReusedExchange [Reuses operator id: 5]
Output [3]: [ss_item_sk#12, sum#13, count#14]

(21) CometHashAggregate
Input [3]: [ss_item_sk#12, sum#13, count#14]
Keys [1]: [ss_item_sk#12]
Functions [1]: [avg(UnscaledValue(ss_net_profit#15))]

(22) CometFilter
Input [2]: [item_sk#16, rank_col#17]
Condition : (isnotnull(rank_col#17) AND (cast(rank_col#17 as decimal(13,7)) > (0.9 * ReusedSubquery Subquery scalar-subquery#9, [id=#10])))

(23) CometSort
Input [2]: [item_sk#16, rank_col#17]
Arguments: [item_sk#16, rank_col#17], [rank_col#17 DESC NULLS LAST]

(24) ColumnarToRow [codegen id : 4]
Input [2]: [item_sk#16, rank_col#17]

(25) WindowGroupLimit
Input [2]: [item_sk#16, rank_col#17]
Arguments: [rank_col#17 DESC NULLS LAST], rank(rank_col#17), 10, Partial

(26) RowToColumnar
Input [2]: [item_sk#16, rank_col#17]

(27) CometColumnarExchange
Input [2]: [item_sk#16, rank_col#17]
Arguments: SinglePartition, ENSURE_REQUIREMENTS, CometColumnarShuffle, [plan_id=3]

(28) CometSort
Input [2]: [item_sk#16, rank_col#17]
Arguments: [item_sk#16, rank_col#17], [rank_col#17 DESC NULLS LAST]

(29) ColumnarToRow [codegen id : 5]
Input [2]: [item_sk#16, rank_col#17]

(30) WindowGroupLimit
Input [2]: [item_sk#16, rank_col#17]
Arguments: [rank_col#17 DESC NULLS LAST], rank(rank_col#17), 10, Final

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

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

(33) Project [codegen id : 6]
Output [2]: [item_sk#16, rnk#18]
Input [3]: [item_sk#16, rank_col#17, rnk#18]

(34) Sort [codegen id : 6]
Input [2]: [item_sk#16, rnk#18]
Arguments: [rnk#18 ASC NULLS FIRST], false, 0

(35) SortMergeJoin [codegen id : 9]
Left keys [1]: [rnk#11]
Right keys [1]: [rnk#18]
Join type: Inner
Join condition: None

(36) Project [codegen id : 9]
Output [3]: [item_sk#7, rnk#11, item_sk#16]
Input [4]: [item_sk#7, rnk#11, item_sk#16, rnk#18]

(37) Scan parquet spark_catalog.default.item
Output [2]: [i_item_sk#19, i_product_name#20]
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>

(38) CometFilter
Input [2]: [i_item_sk#19, i_product_name#20]
Condition : isnotnull(i_item_sk#19)

(39) ColumnarToRow [codegen id : 7]
Input [2]: [i_item_sk#19, i_product_name#20]

(40) BroadcastExchange
Input [2]: [i_item_sk#19, i_product_name#20]
Arguments: HashedRelationBroadcastMode(List(cast(input[0, int, false] as bigint)),false), [plan_id=4]

(41) BroadcastHashJoin [codegen id : 9]
Left keys [1]: [item_sk#7]
Right keys [1]: [i_item_sk#19]
Join type: Inner
Join condition: None

(42) Project [codegen id : 9]
Output [3]: [rnk#11, item_sk#16, i_product_name#20]
Input [5]: [item_sk#7, rnk#11, item_sk#16, i_item_sk#19, i_product_name#20]

(43) ReusedExchange [Reuses operator id: 40]
Output [2]: [i_item_sk#21, i_product_name#22]

(44) BroadcastHashJoin [codegen id : 9]
Left keys [1]: [item_sk#16]
Right keys [1]: [i_item_sk#21]
Join type: Inner
Join condition: None

(45) Project [codegen id : 9]
Output [3]: [rnk#11, i_product_name#20 AS best_performing#23, i_product_name#22 AS worst_performing#24]
Input [5]: [rnk#11, item_sk#16, i_product_name#20, i_item_sk#21, i_product_name#22]

(46) TakeOrderedAndProject
Input [3]: [rnk#11, best_performing#23, worst_performing#24]
Arguments: 100, [rnk#11 ASC NULLS FIRST], [rnk#11, best_performing#23, worst_performing#24]

===== Subqueries =====

Subquery:1 Hosting operator id = 7 Hosting Expression = Subquery scalar-subquery#9, [id=#10]
* ColumnarToRow (53)
+- CometHashAggregate (52)
   +- CometColumnarExchange (51)
      +- CometHashAggregate (50)
         +- CometProject (49)
            +- CometFilter (48)
               +- CometScan parquet spark_catalog.default.store_sales (47)


(47) Scan parquet spark_catalog.default.store_sales
Output [4]: [ss_addr_sk#25, ss_store_sk#26, ss_net_profit#27, ss_sold_date_sk#28]
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)>

(48) CometFilter
Input [4]: [ss_addr_sk#25, ss_store_sk#26, ss_net_profit#27, ss_sold_date_sk#28]
Condition : ((isnotnull(ss_store_sk#26) AND (ss_store_sk#26 = 4)) AND isnull(ss_addr_sk#25))

(49) CometProject
Input [4]: [ss_addr_sk#25, ss_store_sk#26, ss_net_profit#27, ss_sold_date_sk#28]
Arguments: [ss_store_sk#26, ss_net_profit#27], [ss_store_sk#26, ss_net_profit#27]

(50) CometHashAggregate
Input [2]: [ss_store_sk#26, ss_net_profit#27]
Keys [1]: [ss_store_sk#26]
Functions [1]: [partial_avg(UnscaledValue(ss_net_profit#27))]

(51) CometColumnarExchange
Input [3]: [ss_store_sk#26, sum#29, count#30]
Arguments: hashpartitioning(ss_store_sk#26, 5), ENSURE_REQUIREMENTS, CometColumnarShuffle, [plan_id=5]

(52) CometHashAggregate
Input [3]: [ss_store_sk#26, sum#29, count#30]
Keys [1]: [ss_store_sk#26]
Functions [1]: [avg(UnscaledValue(ss_net_profit#27))]

(53) ColumnarToRow [codegen id : 1]
Input [1]: [rank_col#31]

Subquery:2 Hosting operator id = 22 Hosting Expression = ReusedSubquery Subquery scalar-subquery#9, [id=#10]


