== Physical Plan ==
TakeOrderedAndProject (49)
+- * Project (48)
   +- * SortMergeJoin Inner (47)
      :- * Project (28)
      :  +- * SortMergeJoin Inner (27)
      :     :- * Sort (22)
      :     :  +- * HashAggregate (21)
      :     :     +- Exchange (20)
      :     :        +- * HashAggregate (19)
      :     :           +- * ColumnarToRow (18)
      :     :              +- CometProject (17)
      :     :                 +- CometBroadcastHashJoin (16)
      :     :                    :- CometProject (12)
      :     :                    :  +- CometFilter (11)
      :     :                    :     +- CometSortMergeJoin (10)
      :     :                    :        :- CometSort (4)
      :     :                    :        :  +- CometExchange (3)
      :     :                    :        :     +- CometFilter (2)
      :     :                    :        :        +- CometNativeScan: `spark_catalog`.`default`.`store_sales` (1)
      :     :                    :        +- CometSort (9)
      :     :                    :           +- CometExchange (8)
      :     :                    :              +- CometProject (7)
      :     :                    :                 +- CometFilter (6)
      :     :                    :                    +- CometNativeScan: `spark_catalog`.`default`.`store_returns` (5)
      :     :                    +- CometBroadcastExchange (15)
      :     :                       +- CometFilter (14)
      :     :                          +- CometNativeScan: `spark_catalog`.`default`.`date_dim` (13)
      :     +- * Sort (26)
      :        +- * Filter (25)
      :           +- * HashAggregate (24)
      :              +- ReusedExchange (23)
      +- * Sort (46)
         +- * Filter (45)
            +- * HashAggregate (44)
               +- Exchange (43)
                  +- * HashAggregate (42)
                     +- * ColumnarToRow (41)
                        +- CometProject (40)
                           +- CometBroadcastHashJoin (39)
                              :- CometProject (37)
                              :  +- CometFilter (36)
                              :     +- CometSortMergeJoin (35)
                              :        :- CometSort (32)
                              :        :  +- CometExchange (31)
                              :        :     +- CometFilter (30)
                              :        :        +- CometNativeScan: `spark_catalog`.`default`.`catalog_sales` (29)
                              :        +- CometSort (34)
                              :           +- ReusedExchange (33)
                              +- ReusedExchange (38)


(1) CometNativeScan: `spark_catalog`.`default`.`store_sales`
Output [7]: [ss_item_sk#1, ss_customer_sk#2, ss_ticket_number#3, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, ss_sold_date_sk#7]
Arguments: [ss_item_sk#1, ss_customer_sk#2, ss_ticket_number#3, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, ss_sold_date_sk#7]

(2) CometFilter
Input [7]: [ss_item_sk#1, ss_customer_sk#2, ss_ticket_number#3, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, ss_sold_date_sk#7]
Condition : (isnotnull(ss_item_sk#1) AND isnotnull(ss_customer_sk#2))

(3) CometExchange
Input [7]: [ss_item_sk#1, ss_customer_sk#2, ss_ticket_number#3, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, ss_sold_date_sk#7]
Arguments: hashpartitioning(ss_ticket_number#3, ss_item_sk#1, 5), ENSURE_REQUIREMENTS, CometNativeShuffle, [plan_id=1]

(4) CometSort
Input [7]: [ss_item_sk#1, ss_customer_sk#2, ss_ticket_number#3, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, ss_sold_date_sk#7]
Arguments: [ss_item_sk#1, ss_customer_sk#2, ss_ticket_number#3, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, ss_sold_date_sk#7], [ss_ticket_number#3 ASC NULLS FIRST, ss_item_sk#1 ASC NULLS FIRST]

(5) CometNativeScan: `spark_catalog`.`default`.`store_returns`
Output [3]: [sr_item_sk#8, sr_ticket_number#9, sr_returned_date_sk#10]
Arguments: [sr_item_sk#8, sr_ticket_number#9, sr_returned_date_sk#10]

(6) CometFilter
Input [3]: [sr_item_sk#8, sr_ticket_number#9, sr_returned_date_sk#10]
Condition : (isnotnull(sr_ticket_number#9) AND isnotnull(sr_item_sk#8))

(7) CometProject
Input [3]: [sr_item_sk#8, sr_ticket_number#9, sr_returned_date_sk#10]
Arguments: [sr_item_sk#8, sr_ticket_number#9], [sr_item_sk#8, sr_ticket_number#9]

(8) CometExchange
Input [2]: [sr_item_sk#8, sr_ticket_number#9]
Arguments: hashpartitioning(sr_ticket_number#9, sr_item_sk#8, 5), ENSURE_REQUIREMENTS, CometNativeShuffle, [plan_id=2]

(9) CometSort
Input [2]: [sr_item_sk#8, sr_ticket_number#9]
Arguments: [sr_item_sk#8, sr_ticket_number#9], [sr_ticket_number#9 ASC NULLS FIRST, sr_item_sk#8 ASC NULLS FIRST]

(10) CometSortMergeJoin
Left output [7]: [ss_item_sk#1, ss_customer_sk#2, ss_ticket_number#3, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, ss_sold_date_sk#7]
Right output [2]: [sr_item_sk#8, sr_ticket_number#9]
Arguments: [ss_ticket_number#3, ss_item_sk#1], [sr_ticket_number#9, sr_item_sk#8], LeftOuter

(11) CometFilter
Input [9]: [ss_item_sk#1, ss_customer_sk#2, ss_ticket_number#3, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, ss_sold_date_sk#7, sr_item_sk#8, sr_ticket_number#9]
Condition : isnull(sr_ticket_number#9)

(12) CometProject
Input [9]: [ss_item_sk#1, ss_customer_sk#2, ss_ticket_number#3, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, ss_sold_date_sk#7, sr_item_sk#8, sr_ticket_number#9]
Arguments: [ss_item_sk#1, ss_customer_sk#2, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, ss_sold_date_sk#7], [ss_item_sk#1, ss_customer_sk#2, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, ss_sold_date_sk#7]

(13) CometNativeScan: `spark_catalog`.`default`.`date_dim`
Output [2]: [d_date_sk#11, d_year#12]
Arguments: [d_date_sk#11, d_year#12]

(14) CometFilter
Input [2]: [d_date_sk#11, d_year#12]
Condition : ((isnotnull(d_year#12) AND (d_year#12 = 2000)) AND isnotnull(d_date_sk#11))

(15) CometBroadcastExchange
Input [2]: [d_date_sk#11, d_year#12]
Arguments: [d_date_sk#11, d_year#12]

(16) CometBroadcastHashJoin
Left output [6]: [ss_item_sk#1, ss_customer_sk#2, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, ss_sold_date_sk#7]
Right output [2]: [d_date_sk#11, d_year#12]
Arguments: [ss_sold_date_sk#7], [d_date_sk#11], Inner, BuildRight

(17) CometProject
Input [8]: [ss_item_sk#1, ss_customer_sk#2, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, ss_sold_date_sk#7, d_date_sk#11, d_year#12]
Arguments: [ss_item_sk#1, ss_customer_sk#2, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, d_year#12], [ss_item_sk#1, ss_customer_sk#2, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, d_year#12]

(18) ColumnarToRow [codegen id : 1]
Input [6]: [ss_item_sk#1, ss_customer_sk#2, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, d_year#12]

(19) HashAggregate [codegen id : 1]
Input [6]: [ss_item_sk#1, ss_customer_sk#2, ss_quantity#4, ss_wholesale_cost#5, ss_sales_price#6, d_year#12]
Keys [3]: [d_year#12, ss_item_sk#1, ss_customer_sk#2]
Functions [3]: [partial_sum(ss_quantity#4), partial_sum(UnscaledValue(ss_wholesale_cost#5)), partial_sum(UnscaledValue(ss_sales_price#6))]
Aggregate Attributes [3]: [sum#13, sum#14, sum#15]
Results [6]: [d_year#12, ss_item_sk#1, ss_customer_sk#2, sum#16, sum#17, sum#18]

(20) Exchange
Input [6]: [d_year#12, ss_item_sk#1, ss_customer_sk#2, sum#16, sum#17, sum#18]
Arguments: hashpartitioning(d_year#12, ss_item_sk#1, ss_customer_sk#2, 5), ENSURE_REQUIREMENTS, [plan_id=3]

(21) HashAggregate [codegen id : 2]
Input [6]: [d_year#12, ss_item_sk#1, ss_customer_sk#2, sum#16, sum#17, sum#18]
Keys [3]: [d_year#12, ss_item_sk#1, ss_customer_sk#2]
Functions [3]: [sum(ss_quantity#4), sum(UnscaledValue(ss_wholesale_cost#5)), sum(UnscaledValue(ss_sales_price#6))]
Aggregate Attributes [3]: [sum(ss_quantity#4)#19, sum(UnscaledValue(ss_wholesale_cost#5))#20, sum(UnscaledValue(ss_sales_price#6))#21]
Results [6]: [d_year#12 AS ss_sold_year#22, ss_item_sk#1, ss_customer_sk#2, sum(ss_quantity#4)#19 AS ss_qty#23, MakeDecimal(sum(UnscaledValue(ss_wholesale_cost#5))#20,17,2) AS ss_wc#24, MakeDecimal(sum(UnscaledValue(ss_sales_price#6))#21,17,2) AS ss_sp#25]

(22) Sort [codegen id : 2]
Input [6]: [ss_sold_year#22, ss_item_sk#1, ss_customer_sk#2, ss_qty#23, ss_wc#24, ss_sp#25]
Arguments: [ss_sold_year#22 ASC NULLS FIRST, ss_item_sk#1 ASC NULLS FIRST, ss_customer_sk#2 ASC NULLS FIRST], false, 0

(23) ReusedExchange [Reuses operator id: 20]
Output [6]: [d_year#26, ws_item_sk#27, ws_bill_customer_sk#28, sum#29, sum#30, sum#31]

(24) HashAggregate [codegen id : 4]
Input [6]: [d_year#26, ws_item_sk#27, ws_bill_customer_sk#28, sum#29, sum#30, sum#31]
Keys [3]: [d_year#26, ws_item_sk#27, ws_bill_customer_sk#28]
Functions [3]: [sum(ws_quantity#32), sum(UnscaledValue(ws_wholesale_cost#33)), sum(UnscaledValue(ws_sales_price#34))]
Aggregate Attributes [3]: [sum(ws_quantity#32)#35, sum(UnscaledValue(ws_wholesale_cost#33))#36, sum(UnscaledValue(ws_sales_price#34))#37]
Results [6]: [d_year#26 AS ws_sold_year#38, ws_item_sk#27, ws_bill_customer_sk#28 AS ws_customer_sk#39, sum(ws_quantity#32)#35 AS ws_qty#40, MakeDecimal(sum(UnscaledValue(ws_wholesale_cost#33))#36,17,2) AS ws_wc#41, MakeDecimal(sum(UnscaledValue(ws_sales_price#34))#37,17,2) AS ws_sp#42]

(25) Filter [codegen id : 4]
Input [6]: [ws_sold_year#38, ws_item_sk#27, ws_customer_sk#39, ws_qty#40, ws_wc#41, ws_sp#42]
Condition : (coalesce(ws_qty#40, 0) > 0)

(26) Sort [codegen id : 4]
Input [6]: [ws_sold_year#38, ws_item_sk#27, ws_customer_sk#39, ws_qty#40, ws_wc#41, ws_sp#42]
Arguments: [ws_sold_year#38 ASC NULLS FIRST, ws_item_sk#27 ASC NULLS FIRST, ws_customer_sk#39 ASC NULLS FIRST], false, 0

(27) SortMergeJoin [codegen id : 5]
Left keys [3]: [ss_sold_year#22, ss_item_sk#1, ss_customer_sk#2]
Right keys [3]: [ws_sold_year#38, ws_item_sk#27, ws_customer_sk#39]
Join type: Inner
Join condition: None

(28) Project [codegen id : 5]
Output [9]: [ss_sold_year#22, ss_item_sk#1, ss_customer_sk#2, ss_qty#23, ss_wc#24, ss_sp#25, ws_qty#40, ws_wc#41, ws_sp#42]
Input [12]: [ss_sold_year#22, ss_item_sk#1, ss_customer_sk#2, ss_qty#23, ss_wc#24, ss_sp#25, ws_sold_year#38, ws_item_sk#27, ws_customer_sk#39, ws_qty#40, ws_wc#41, ws_sp#42]

(29) CometNativeScan: `spark_catalog`.`default`.`catalog_sales`
Output [7]: [cs_bill_customer_sk#43, cs_item_sk#44, cs_order_number#45, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, cs_sold_date_sk#49]
Arguments: [cs_bill_customer_sk#43, cs_item_sk#44, cs_order_number#45, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, cs_sold_date_sk#49]

(30) CometFilter
Input [7]: [cs_bill_customer_sk#43, cs_item_sk#44, cs_order_number#45, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, cs_sold_date_sk#49]
Condition : (isnotnull(cs_item_sk#44) AND isnotnull(cs_bill_customer_sk#43))

(31) CometExchange
Input [7]: [cs_bill_customer_sk#43, cs_item_sk#44, cs_order_number#45, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, cs_sold_date_sk#49]
Arguments: hashpartitioning(cs_order_number#45, cs_item_sk#44, 5), ENSURE_REQUIREMENTS, CometNativeShuffle, [plan_id=4]

(32) CometSort
Input [7]: [cs_bill_customer_sk#43, cs_item_sk#44, cs_order_number#45, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, cs_sold_date_sk#49]
Arguments: [cs_bill_customer_sk#43, cs_item_sk#44, cs_order_number#45, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, cs_sold_date_sk#49], [cs_order_number#45 ASC NULLS FIRST, cs_item_sk#44 ASC NULLS FIRST]

(33) ReusedExchange [Reuses operator id: 8]
Output [2]: [cr_item_sk#50, cr_order_number#51]

(34) CometSort
Input [2]: [cr_item_sk#50, cr_order_number#51]
Arguments: [cr_item_sk#50, cr_order_number#51], [cr_order_number#51 ASC NULLS FIRST, cr_item_sk#50 ASC NULLS FIRST]

(35) CometSortMergeJoin
Left output [7]: [cs_bill_customer_sk#43, cs_item_sk#44, cs_order_number#45, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, cs_sold_date_sk#49]
Right output [2]: [cr_item_sk#50, cr_order_number#51]
Arguments: [cs_order_number#45, cs_item_sk#44], [cr_order_number#51, cr_item_sk#50], LeftOuter

(36) CometFilter
Input [9]: [cs_bill_customer_sk#43, cs_item_sk#44, cs_order_number#45, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, cs_sold_date_sk#49, cr_item_sk#50, cr_order_number#51]
Condition : isnull(cr_order_number#51)

(37) CometProject
Input [9]: [cs_bill_customer_sk#43, cs_item_sk#44, cs_order_number#45, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, cs_sold_date_sk#49, cr_item_sk#50, cr_order_number#51]
Arguments: [cs_bill_customer_sk#43, cs_item_sk#44, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, cs_sold_date_sk#49], [cs_bill_customer_sk#43, cs_item_sk#44, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, cs_sold_date_sk#49]

(38) ReusedExchange [Reuses operator id: 15]
Output [2]: [d_date_sk#52, d_year#53]

(39) CometBroadcastHashJoin
Left output [6]: [cs_bill_customer_sk#43, cs_item_sk#44, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, cs_sold_date_sk#49]
Right output [2]: [d_date_sk#52, d_year#53]
Arguments: [cs_sold_date_sk#49], [d_date_sk#52], Inner, BuildRight

(40) CometProject
Input [8]: [cs_bill_customer_sk#43, cs_item_sk#44, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, cs_sold_date_sk#49, d_date_sk#52, d_year#53]
Arguments: [cs_bill_customer_sk#43, cs_item_sk#44, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, d_year#53], [cs_bill_customer_sk#43, cs_item_sk#44, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, d_year#53]

(41) ColumnarToRow [codegen id : 6]
Input [6]: [cs_bill_customer_sk#43, cs_item_sk#44, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, d_year#53]

(42) HashAggregate [codegen id : 6]
Input [6]: [cs_bill_customer_sk#43, cs_item_sk#44, cs_quantity#46, cs_wholesale_cost#47, cs_sales_price#48, d_year#53]
Keys [3]: [d_year#53, cs_item_sk#44, cs_bill_customer_sk#43]
Functions [3]: [partial_sum(cs_quantity#46), partial_sum(UnscaledValue(cs_wholesale_cost#47)), partial_sum(UnscaledValue(cs_sales_price#48))]
Aggregate Attributes [3]: [sum#54, sum#55, sum#56]
Results [6]: [d_year#53, cs_item_sk#44, cs_bill_customer_sk#43, sum#57, sum#58, sum#59]

(43) Exchange
Input [6]: [d_year#53, cs_item_sk#44, cs_bill_customer_sk#43, sum#57, sum#58, sum#59]
Arguments: hashpartitioning(d_year#53, cs_item_sk#44, cs_bill_customer_sk#43, 5), ENSURE_REQUIREMENTS, [plan_id=5]

(44) HashAggregate [codegen id : 7]
Input [6]: [d_year#53, cs_item_sk#44, cs_bill_customer_sk#43, sum#57, sum#58, sum#59]
Keys [3]: [d_year#53, cs_item_sk#44, cs_bill_customer_sk#43]
Functions [3]: [sum(cs_quantity#46), sum(UnscaledValue(cs_wholesale_cost#47)), sum(UnscaledValue(cs_sales_price#48))]
Aggregate Attributes [3]: [sum(cs_quantity#46)#60, sum(UnscaledValue(cs_wholesale_cost#47))#61, sum(UnscaledValue(cs_sales_price#48))#62]
Results [6]: [d_year#53 AS cs_sold_year#63, cs_item_sk#44, cs_bill_customer_sk#43 AS cs_customer_sk#64, sum(cs_quantity#46)#60 AS cs_qty#65, MakeDecimal(sum(UnscaledValue(cs_wholesale_cost#47))#61,17,2) AS cs_wc#66, MakeDecimal(sum(UnscaledValue(cs_sales_price#48))#62,17,2) AS cs_sp#67]

(45) Filter [codegen id : 7]
Input [6]: [cs_sold_year#63, cs_item_sk#44, cs_customer_sk#64, cs_qty#65, cs_wc#66, cs_sp#67]
Condition : (coalesce(cs_qty#65, 0) > 0)

(46) Sort [codegen id : 7]
Input [6]: [cs_sold_year#63, cs_item_sk#44, cs_customer_sk#64, cs_qty#65, cs_wc#66, cs_sp#67]
Arguments: [cs_sold_year#63 ASC NULLS FIRST, cs_item_sk#44 ASC NULLS FIRST, cs_customer_sk#64 ASC NULLS FIRST], false, 0

(47) SortMergeJoin [codegen id : 8]
Left keys [3]: [ss_sold_year#22, ss_item_sk#1, ss_customer_sk#2]
Right keys [3]: [cs_sold_year#63, cs_item_sk#44, cs_customer_sk#64]
Join type: Inner
Join condition: None

(48) Project [codegen id : 8]
Output [12]: [round((cast(ss_qty#23 as double) / knownfloatingpointnormalized(normalizenanandzero(cast(coalesce((ws_qty#40 + cs_qty#65), 1) as double)))), 2) AS ratio#68, ss_qty#23 AS store_qty#69, ss_wc#24 AS store_wholesale_cost#70, ss_sp#25 AS store_sales_price#71, (coalesce(ws_qty#40, 0) + coalesce(cs_qty#65, 0)) AS other_chan_qty#72, (coalesce(ws_wc#41, 0.00) + coalesce(cs_wc#66, 0.00)) AS other_chan_wholesale_cost#73, (coalesce(ws_sp#42, 0.00) + coalesce(cs_sp#67, 0.00)) AS other_chan_sales_price#74, ss_qty#23, ss_wc#24, ss_sp#25, ws_qty#40, cs_qty#65]
Input [15]: [ss_sold_year#22, ss_item_sk#1, ss_customer_sk#2, ss_qty#23, ss_wc#24, ss_sp#25, ws_qty#40, ws_wc#41, ws_sp#42, cs_sold_year#63, cs_item_sk#44, cs_customer_sk#64, cs_qty#65, cs_wc#66, cs_sp#67]

(49) TakeOrderedAndProject
Input [12]: [ratio#68, store_qty#69, store_wholesale_cost#70, store_sales_price#71, other_chan_qty#72, other_chan_wholesale_cost#73, other_chan_sales_price#74, ss_qty#23, ss_wc#24, ss_sp#25, ws_qty#40, cs_qty#65]
Arguments: 100, [ratio#68 ASC NULLS FIRST, ss_qty#23 DESC NULLS LAST, ss_wc#24 DESC NULLS LAST, ss_sp#25 DESC NULLS LAST, other_chan_qty#72 ASC NULLS FIRST, other_chan_wholesale_cost#73 ASC NULLS FIRST, other_chan_sales_price#74 ASC NULLS FIRST, round((cast(ss_qty#23 as double) / cast(coalesce((ws_qty#40 + cs_qty#65), 1) as double)), 2) ASC NULLS FIRST], [ratio#68, store_qty#69, store_wholesale_cost#70, store_sales_price#71, other_chan_qty#72, other_chan_wholesale_cost#73, other_chan_sales_price#74]

