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


(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) Sort [codegen id : 2]
Input [2]: [item_sk#8, rank_col#9]
Arguments: [rank_col#9 ASC NULLS FIRST], false, 0

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

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

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

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

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

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

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

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

(18) ReusedExchange [Reuses operator id: 6]
Output [3]: [ss_item_sk#13, sum#14, count#15]

(19) HashAggregate [codegen id : 6]
Input [3]: [ss_item_sk#13, sum#14, count#15]
Keys [1]: [ss_item_sk#13]
Functions [1]: [avg(UnscaledValue(ss_net_profit#16))]
Aggregate Attributes [1]: [avg(UnscaledValue(ss_net_profit#16))#17]
Results [2]: [ss_item_sk#13 AS item_sk#18, cast((avg(UnscaledValue(ss_net_profit#16))#17 / 100.0) as decimal(11,6)) AS rank_col#19]

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

(21) Sort [codegen id : 6]
Input [2]: [item_sk#18, rank_col#19]
Arguments: [rank_col#19 DESC NULLS LAST], false, 0

(22) WindowGroupLimit
Input [2]: [item_sk#18, rank_col#19]
Arguments: [rank_col#19 DESC NULLS LAST], rank(rank_col#19), 10, Partial

(23) Exchange
Input [2]: [item_sk#18, rank_col#19]
Arguments: SinglePartition, ENSURE_REQUIREMENTS, [plan_id=3]

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

(25) WindowGroupLimit
Input [2]: [item_sk#18, rank_col#19]
Arguments: [rank_col#19 DESC NULLS LAST], rank(rank_col#19), 10, Final

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

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

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

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

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

(31) Project [codegen id : 11]
Output [3]: [item_sk#8, rnk#12, item_sk#18]
Input [4]: [item_sk#8, rnk#12, item_sk#18, rnk#20]

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

(33) CometFilter
Input [2]: [i_item_sk#21, i_product_name#22]
Condition : isnotnull(i_item_sk#21)

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

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

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

(37) Project [codegen id : 11]
Output [3]: [rnk#12, item_sk#18, i_product_name#22]
Input [5]: [item_sk#8, rnk#12, item_sk#18, i_item_sk#21, i_product_name#22]

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

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

(40) Project [codegen id : 11]
Output [3]: [rnk#12, i_product_name#22 AS best_performing#25, i_product_name#24 AS worst_performing#26]
Input [5]: [rnk#12, item_sk#18, i_product_name#22, i_item_sk#23, i_product_name#24]

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

===== Subqueries =====

Subquery:1 Hosting operator id = 8 Hosting Expression = Subquery scalar-subquery#10, [id=#11]
* HashAggregate (48)
+- Exchange (47)
   +- * ColumnarToRow (46)
      +- CometHashAggregate (45)
         +- CometProject (44)
            +- CometFilter (43)
               +- CometScan parquet spark_catalog.default.store_sales (42)


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

(43) CometFilter
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))

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

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

(46) ColumnarToRow [codegen id : 1]
Input [3]: [ss_store_sk#28, sum#31, count#32]

(47) Exchange
Input [3]: [ss_store_sk#28, sum#31, count#32]
Arguments: hashpartitioning(ss_store_sk#28, 5), ENSURE_REQUIREMENTS, [plan_id=5]

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

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


