== Physical Plan ==
TakeOrderedAndProject (31)
+- * Project (30)
   +- * BroadcastHashJoin Inner BuildRight (29)
      :- * Project (27)
      :  +- * BroadcastHashJoin Inner BuildRight (26)
      :     :- * Project (21)
      :     :  +- * BroadcastHashJoin Inner BuildRight (20)
      :     :     :- * 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)
      :     :     +- BroadcastExchange (19)
      :     :        +- * Project (18)
      :     :           +- * Filter (17)
      :     :              +- Window (16)
      :     :                 +- * Sort (15)
      :     :                    +- ReusedExchange (14)
      :     +- BroadcastExchange (25)
      :        +- * Filter (24)
      :           +- * ColumnarToRow (23)
      :              +- Scan parquet default.item (22)
      +- ReusedExchange (28)


(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, [plan_id=1]

(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))#9]
Results [2]: [ss_item_sk#1 AS item_sk#10, cast((avg(UnscaledValue(ss_net_profit#3))#9 / 100.0) as decimal(11,6)) AS rank_col#11]

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

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

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

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

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

(13) Project [codegen id : 10]
Output [2]: [item_sk#10, rnk#14]
Input [3]: [item_sk#10, rank_col#11, rnk#14]

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

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

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

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

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

(19) BroadcastExchange
Input [2]: [item_sk#15, rnk#17]
Arguments: HashedRelationBroadcastMode(List(cast(input[1, int, false] as bigint)),false), [plan_id=3]

(20) BroadcastHashJoin [codegen id : 10]
Left keys [1]: [rnk#14]
Right keys [1]: [rnk#17]
Join condition: None

(21) Project [codegen id : 10]
Output [3]: [item_sk#10, rnk#14, item_sk#15]
Input [4]: [item_sk#10, rnk#14, item_sk#15, rnk#17]

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

(23) ColumnarToRow [codegen id : 8]
Input [2]: [i_item_sk#18, i_product_name#19]

(24) Filter [codegen id : 8]
Input [2]: [i_item_sk#18, i_product_name#19]
Condition : isnotnull(i_item_sk#18)

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

(26) BroadcastHashJoin [codegen id : 10]
Left keys [1]: [item_sk#10]
Right keys [1]: [i_item_sk#18]
Join condition: None

(27) Project [codegen id : 10]
Output [3]: [rnk#14, item_sk#15, i_product_name#19]
Input [5]: [item_sk#10, rnk#14, item_sk#15, i_item_sk#18, i_product_name#19]

(28) ReusedExchange [Reuses operator id: 25]
Output [2]: [i_item_sk#20, i_product_name#21]

(29) BroadcastHashJoin [codegen id : 10]
Left keys [1]: [item_sk#15]
Right keys [1]: [i_item_sk#20]
Join condition: None

(30) Project [codegen id : 10]
Output [3]: [rnk#14, i_product_name#19 AS best_performing#22, i_product_name#21 AS worst_performing#23]
Input [5]: [rnk#14, item_sk#15, i_product_name#19, i_item_sk#20, i_product_name#21]

(31) TakeOrderedAndProject
Input [3]: [rnk#14, best_performing#22, worst_performing#23]
Arguments: 100, [rnk#14 ASC NULLS FIRST], [rnk#14, best_performing#22, worst_performing#23]

===== Subqueries =====

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


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

(33) ColumnarToRow [codegen id : 1]
Input [4]: [ss_addr_sk#24, ss_store_sk#25, ss_net_profit#26, ss_sold_date_sk#27]

(34) Filter [codegen id : 1]
Input [4]: [ss_addr_sk#24, ss_store_sk#25, ss_net_profit#26, ss_sold_date_sk#27]
Condition : ((isnotnull(ss_store_sk#25) AND (ss_store_sk#25 = 4)) AND isnull(ss_addr_sk#24))

(35) Project [codegen id : 1]
Output [2]: [ss_store_sk#25, ss_net_profit#26]
Input [4]: [ss_addr_sk#24, ss_store_sk#25, ss_net_profit#26, ss_sold_date_sk#27]

(36) HashAggregate [codegen id : 1]
Input [2]: [ss_store_sk#25, ss_net_profit#26]
Keys [1]: [ss_store_sk#25]
Functions [1]: [partial_avg(UnscaledValue(ss_net_profit#26))]
Aggregate Attributes [2]: [sum#28, count#29]
Results [3]: [ss_store_sk#25, sum#30, count#31]

(37) Exchange
Input [3]: [ss_store_sk#25, sum#30, count#31]
Arguments: hashpartitioning(ss_store_sk#25, 5), ENSURE_REQUIREMENTS, [plan_id=5]

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


