== 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, [id=#9]

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

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

(9) Exchange
Input [2]: [item_sk#11, rank_col#12]
Arguments: SinglePartition, ENSURE_REQUIREMENTS, [id=#15]

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

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

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

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

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

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

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

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

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

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

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

(21) Project [codegen id : 10]
Output [3]: [item_sk#11, rnk#16, item_sk#17]
Input [4]: [item_sk#11, rnk#16, item_sk#17, rnk#19]

(22) Scan parquet 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>

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

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

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

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

(27) Project [codegen id : 10]
Output [3]: [rnk#16, item_sk#17, i_product_name#22]
Input [5]: [item_sk#11, rnk#16, item_sk#17, i_item_sk#21, i_product_name#22]

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

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

(30) Project [codegen id : 10]
Output [3]: [rnk#16, i_product_name#22 AS best_performing#26, i_product_name#25 AS worst_performing#27]
Input [5]: [rnk#16, item_sk#17, i_product_name#22, i_item_sk#24, i_product_name#25]

(31) TakeOrderedAndProject
Input [3]: [rnk#16, best_performing#26, worst_performing#27]
Arguments: 100, [rnk#16 ASC NULLS FIRST], [rnk#16, best_performing#26, worst_performing#27]

===== Subqueries =====

Subquery:1 Hosting operator id = 8 Hosting Expression = Subquery scalar-subquery#13, [id=#14]
* 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#28, ss_store_sk#29, ss_net_profit#30, ss_sold_date_sk#31]
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#28, ss_store_sk#29, ss_net_profit#30, ss_sold_date_sk#31]

(34) Filter [codegen id : 1]
Input [4]: [ss_addr_sk#28, ss_store_sk#29, ss_net_profit#30, ss_sold_date_sk#31]
Condition : ((isnotnull(ss_store_sk#29) AND (ss_store_sk#29 = 4)) AND isnull(ss_addr_sk#28))

(35) Project [codegen id : 1]
Output [2]: [ss_store_sk#29, ss_net_profit#30]
Input [4]: [ss_addr_sk#28, ss_store_sk#29, ss_net_profit#30, ss_sold_date_sk#31]

(36) HashAggregate [codegen id : 1]
Input [2]: [ss_store_sk#29, ss_net_profit#30]
Keys [1]: [ss_store_sk#29]
Functions [1]: [partial_avg(UnscaledValue(ss_net_profit#30))]
Aggregate Attributes [2]: [sum#32, count#33]
Results [3]: [ss_store_sk#29, sum#34, count#35]

(37) Exchange
Input [3]: [ss_store_sk#29, sum#34, count#35]
Arguments: hashpartitioning(ss_store_sk#29, 5), ENSURE_REQUIREMENTS, [id=#36]

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


