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


(1) CometScan [native_iceberg_compat] 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) CometExchange
Input [3]: [ss_item_sk#1, sum#5, count#6]
Arguments: hashpartitioning(ss_item_sk#1, 5), ENSURE_REQUIREMENTS, CometNativeShuffle, [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) CometColumnarToRow [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) CometColumnarExchange
Input [2]: [item_sk#7, rank_col#8]
Arguments: SinglePartition, ENSURE_REQUIREMENTS, CometColumnarShuffle, [plan_id=2]

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

(13) CometColumnarToRow [codegen id : 2]
Input [2]: [item_sk#7, rank_col#8]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

(37) CometProject
Input [2]: [i_item_sk#19, i_product_name#20]
Arguments: [i_item_sk#19, i_product_name#21], [i_item_sk#19, staticinvoke(class org.apache.spark.sql.catalyst.util.CharVarcharCodegenUtils, StringType, readSidePadding, i_product_name#20, 50, true, false, true) AS i_product_name#21]

(38) CometColumnarToRow [codegen id : 7]
Input [2]: [i_item_sk#19, i_product_name#21]

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

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

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

(42) ReusedExchange [Reuses operator id: 39]
Output [2]: [i_item_sk#22, i_product_name#23]

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

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

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

===== Subqueries =====

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


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

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

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

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

(50) CometExchange
Input [3]: [ss_store_sk#27, sum#30, count#31]
Arguments: hashpartitioning(ss_store_sk#27, 5), ENSURE_REQUIREMENTS, CometNativeShuffle, [plan_id=5]

(51) CometHashAggregate
Input [3]: [ss_store_sk#27, sum#30, count#31]
Keys [1]: [ss_store_sk#27]
Functions [1]: [avg(UnscaledValue(ss_net_profit#28))]

(52) CometColumnarToRow [codegen id : 1]
Input [1]: [rank_col#32]

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


