== Physical Plan ==
TakeOrderedAndProject (47)
+- * Project (46)
   +- * SortMergeJoin Inner (45)
      :- * Sort (14)
      :  +- Exchange (13)
      :     +- * Project (12)
      :        +- * SortMergeJoin Inner (11)
      :           :- * Sort (5)
      :           :  +- Exchange (4)
      :           :     +- * Filter (3)
      :           :        +- * ColumnarToRow (2)
      :           :           +- Scan parquet spark_catalog.default.customer (1)
      :           +- * Sort (10)
      :              +- Exchange (9)
      :                 +- * Filter (8)
      :                    +- * ColumnarToRow (7)
      :                       +- Scan parquet spark_catalog.default.customer_address (6)
      +- * Sort (44)
         +- Exchange (43)
            +- * HashAggregate (42)
               +- * HashAggregate (41)
                  +- * Project (40)
                     +- * SortMergeJoin Inner (39)
                        :- * Sort (36)
                        :  +- Exchange (35)
                        :     +- * Project (34)
                        :        +- * BroadcastHashJoin Inner BuildRight (33)
                        :           :- * Project (27)
                        :           :  +- * BroadcastHashJoin Inner BuildRight (26)
                        :           :     :- * Project (20)
                        :           :     :  +- * BroadcastHashJoin Inner BuildRight (19)
                        :           :     :     :- * Filter (17)
                        :           :     :     :  +- * ColumnarToRow (16)
                        :           :     :     :     +- Scan parquet spark_catalog.default.store_sales (15)
                        :           :     :     +- ReusedExchange (18)
                        :           :     +- BroadcastExchange (25)
                        :           :        +- * Project (24)
                        :           :           +- * Filter (23)
                        :           :              +- * ColumnarToRow (22)
                        :           :                 +- Scan parquet spark_catalog.default.store (21)
                        :           +- BroadcastExchange (32)
                        :              +- * Project (31)
                        :                 +- * Filter (30)
                        :                    +- * ColumnarToRow (29)
                        :                       +- Scan parquet spark_catalog.default.household_demographics (28)
                        +- * Sort (38)
                           +- ReusedExchange (37)


(1) Scan parquet spark_catalog.default.customer
Output [4]: [c_customer_sk#1, c_current_addr_sk#2, c_first_name#3, c_last_name#4]
Batched: true
Location [not included in comparison]/{warehouse_dir}/customer]
PushedFilters: [IsNotNull(c_customer_sk), IsNotNull(c_current_addr_sk)]
ReadSchema: struct<c_customer_sk:int,c_current_addr_sk:int,c_first_name:string,c_last_name:string>

(2) ColumnarToRow [codegen id : 1]
Input [4]: [c_customer_sk#1, c_current_addr_sk#2, c_first_name#3, c_last_name#4]

(3) Filter [codegen id : 1]
Input [4]: [c_customer_sk#1, c_current_addr_sk#2, c_first_name#3, c_last_name#4]
Condition : (isnotnull(c_customer_sk#1) AND isnotnull(c_current_addr_sk#2))

(4) Exchange
Input [4]: [c_customer_sk#1, c_current_addr_sk#2, c_first_name#3, c_last_name#4]
Arguments: hashpartitioning(c_current_addr_sk#2, 5), ENSURE_REQUIREMENTS, [plan_id=1]

(5) Sort [codegen id : 2]
Input [4]: [c_customer_sk#1, c_current_addr_sk#2, c_first_name#3, c_last_name#4]
Arguments: [c_current_addr_sk#2 ASC NULLS FIRST], false, 0

(6) Scan parquet spark_catalog.default.customer_address
Output [2]: [ca_address_sk#5, ca_city#6]
Batched: true
Location [not included in comparison]/{warehouse_dir}/customer_address]
PushedFilters: [IsNotNull(ca_address_sk), IsNotNull(ca_city)]
ReadSchema: struct<ca_address_sk:int,ca_city:string>

(7) ColumnarToRow [codegen id : 3]
Input [2]: [ca_address_sk#5, ca_city#6]

(8) Filter [codegen id : 3]
Input [2]: [ca_address_sk#5, ca_city#6]
Condition : (isnotnull(ca_address_sk#5) AND isnotnull(ca_city#6))

(9) Exchange
Input [2]: [ca_address_sk#5, ca_city#6]
Arguments: hashpartitioning(ca_address_sk#5, 5), ENSURE_REQUIREMENTS, [plan_id=2]

(10) Sort [codegen id : 4]
Input [2]: [ca_address_sk#5, ca_city#6]
Arguments: [ca_address_sk#5 ASC NULLS FIRST], false, 0

(11) SortMergeJoin [codegen id : 5]
Left keys [1]: [c_current_addr_sk#2]
Right keys [1]: [ca_address_sk#5]
Join type: Inner
Join condition: None

(12) Project [codegen id : 5]
Output [4]: [c_customer_sk#1, c_first_name#3, c_last_name#4, ca_city#6]
Input [6]: [c_customer_sk#1, c_current_addr_sk#2, c_first_name#3, c_last_name#4, ca_address_sk#5, ca_city#6]

(13) Exchange
Input [4]: [c_customer_sk#1, c_first_name#3, c_last_name#4, ca_city#6]
Arguments: hashpartitioning(c_customer_sk#1, 5), ENSURE_REQUIREMENTS, [plan_id=3]

(14) Sort [codegen id : 6]
Input [4]: [c_customer_sk#1, c_first_name#3, c_last_name#4, ca_city#6]
Arguments: [c_customer_sk#1 ASC NULLS FIRST], false, 0

(15) Scan parquet spark_catalog.default.store_sales
Output [8]: [ss_customer_sk#7, ss_hdemo_sk#8, ss_addr_sk#9, ss_store_sk#10, ss_ticket_number#11, ss_coupon_amt#12, ss_net_profit#13, ss_sold_date_sk#14]
Batched: true
Location: InMemoryFileIndex []
PartitionFilters: [isnotnull(ss_sold_date_sk#14), dynamicpruningexpression(ss_sold_date_sk#14 IN dynamicpruning#15)]
PushedFilters: [IsNotNull(ss_store_sk), IsNotNull(ss_hdemo_sk), IsNotNull(ss_addr_sk), IsNotNull(ss_customer_sk)]
ReadSchema: struct<ss_customer_sk:int,ss_hdemo_sk:int,ss_addr_sk:int,ss_store_sk:int,ss_ticket_number:int,ss_coupon_amt:decimal(7,2),ss_net_profit:decimal(7,2)>

(16) ColumnarToRow [codegen id : 10]
Input [8]: [ss_customer_sk#7, ss_hdemo_sk#8, ss_addr_sk#9, ss_store_sk#10, ss_ticket_number#11, ss_coupon_amt#12, ss_net_profit#13, ss_sold_date_sk#14]

(17) Filter [codegen id : 10]
Input [8]: [ss_customer_sk#7, ss_hdemo_sk#8, ss_addr_sk#9, ss_store_sk#10, ss_ticket_number#11, ss_coupon_amt#12, ss_net_profit#13, ss_sold_date_sk#14]
Condition : (((isnotnull(ss_store_sk#10) AND isnotnull(ss_hdemo_sk#8)) AND isnotnull(ss_addr_sk#9)) AND isnotnull(ss_customer_sk#7))

(18) ReusedExchange [Reuses operator id: 52]
Output [1]: [d_date_sk#16]

(19) BroadcastHashJoin [codegen id : 10]
Left keys [1]: [ss_sold_date_sk#14]
Right keys [1]: [d_date_sk#16]
Join type: Inner
Join condition: None

(20) Project [codegen id : 10]
Output [7]: [ss_customer_sk#7, ss_hdemo_sk#8, ss_addr_sk#9, ss_store_sk#10, ss_ticket_number#11, ss_coupon_amt#12, ss_net_profit#13]
Input [9]: [ss_customer_sk#7, ss_hdemo_sk#8, ss_addr_sk#9, ss_store_sk#10, ss_ticket_number#11, ss_coupon_amt#12, ss_net_profit#13, ss_sold_date_sk#14, d_date_sk#16]

(21) Scan parquet spark_catalog.default.store
Output [2]: [s_store_sk#17, s_city#18]
Batched: true
Location [not included in comparison]/{warehouse_dir}/store]
PushedFilters: [In(s_city, [Fairview,Midway]), IsNotNull(s_store_sk)]
ReadSchema: struct<s_store_sk:int,s_city:string>

(22) ColumnarToRow [codegen id : 8]
Input [2]: [s_store_sk#17, s_city#18]

(23) Filter [codegen id : 8]
Input [2]: [s_store_sk#17, s_city#18]
Condition : (s_city#18 IN (Fairview,Midway) AND isnotnull(s_store_sk#17))

(24) Project [codegen id : 8]
Output [1]: [s_store_sk#17]
Input [2]: [s_store_sk#17, s_city#18]

(25) BroadcastExchange
Input [1]: [s_store_sk#17]
Arguments: HashedRelationBroadcastMode(List(cast(input[0, int, true] as bigint)),false), [plan_id=4]

(26) BroadcastHashJoin [codegen id : 10]
Left keys [1]: [ss_store_sk#10]
Right keys [1]: [s_store_sk#17]
Join type: Inner
Join condition: None

(27) Project [codegen id : 10]
Output [6]: [ss_customer_sk#7, ss_hdemo_sk#8, ss_addr_sk#9, ss_ticket_number#11, ss_coupon_amt#12, ss_net_profit#13]
Input [8]: [ss_customer_sk#7, ss_hdemo_sk#8, ss_addr_sk#9, ss_store_sk#10, ss_ticket_number#11, ss_coupon_amt#12, ss_net_profit#13, s_store_sk#17]

(28) Scan parquet spark_catalog.default.household_demographics
Output [3]: [hd_demo_sk#19, hd_dep_count#20, hd_vehicle_count#21]
Batched: true
Location [not included in comparison]/{warehouse_dir}/household_demographics]
PushedFilters: [Or(EqualTo(hd_dep_count,4),EqualTo(hd_vehicle_count,3)), IsNotNull(hd_demo_sk)]
ReadSchema: struct<hd_demo_sk:int,hd_dep_count:int,hd_vehicle_count:int>

(29) ColumnarToRow [codegen id : 9]
Input [3]: [hd_demo_sk#19, hd_dep_count#20, hd_vehicle_count#21]

(30) Filter [codegen id : 9]
Input [3]: [hd_demo_sk#19, hd_dep_count#20, hd_vehicle_count#21]
Condition : (((hd_dep_count#20 = 4) OR (hd_vehicle_count#21 = 3)) AND isnotnull(hd_demo_sk#19))

(31) Project [codegen id : 9]
Output [1]: [hd_demo_sk#19]
Input [3]: [hd_demo_sk#19, hd_dep_count#20, hd_vehicle_count#21]

(32) BroadcastExchange
Input [1]: [hd_demo_sk#19]
Arguments: HashedRelationBroadcastMode(List(cast(input[0, int, true] as bigint)),false), [plan_id=5]

(33) BroadcastHashJoin [codegen id : 10]
Left keys [1]: [ss_hdemo_sk#8]
Right keys [1]: [hd_demo_sk#19]
Join type: Inner
Join condition: None

(34) Project [codegen id : 10]
Output [5]: [ss_customer_sk#7, ss_addr_sk#9, ss_ticket_number#11, ss_coupon_amt#12, ss_net_profit#13]
Input [7]: [ss_customer_sk#7, ss_hdemo_sk#8, ss_addr_sk#9, ss_ticket_number#11, ss_coupon_amt#12, ss_net_profit#13, hd_demo_sk#19]

(35) Exchange
Input [5]: [ss_customer_sk#7, ss_addr_sk#9, ss_ticket_number#11, ss_coupon_amt#12, ss_net_profit#13]
Arguments: hashpartitioning(ss_addr_sk#9, 5), ENSURE_REQUIREMENTS, [plan_id=6]

(36) Sort [codegen id : 11]
Input [5]: [ss_customer_sk#7, ss_addr_sk#9, ss_ticket_number#11, ss_coupon_amt#12, ss_net_profit#13]
Arguments: [ss_addr_sk#9 ASC NULLS FIRST], false, 0

(37) ReusedExchange [Reuses operator id: 9]
Output [2]: [ca_address_sk#22, ca_city#23]

(38) Sort [codegen id : 13]
Input [2]: [ca_address_sk#22, ca_city#23]
Arguments: [ca_address_sk#22 ASC NULLS FIRST], false, 0

(39) SortMergeJoin [codegen id : 14]
Left keys [1]: [ss_addr_sk#9]
Right keys [1]: [ca_address_sk#22]
Join type: Inner
Join condition: None

(40) Project [codegen id : 14]
Output [6]: [ss_customer_sk#7, ss_addr_sk#9, ss_ticket_number#11, ss_coupon_amt#12, ss_net_profit#13, ca_city#23]
Input [7]: [ss_customer_sk#7, ss_addr_sk#9, ss_ticket_number#11, ss_coupon_amt#12, ss_net_profit#13, ca_address_sk#22, ca_city#23]

(41) HashAggregate [codegen id : 14]
Input [6]: [ss_customer_sk#7, ss_addr_sk#9, ss_ticket_number#11, ss_coupon_amt#12, ss_net_profit#13, ca_city#23]
Keys [4]: [ss_ticket_number#11, ss_customer_sk#7, ss_addr_sk#9, ca_city#23]
Functions [2]: [partial_sum(UnscaledValue(ss_coupon_amt#12)), partial_sum(UnscaledValue(ss_net_profit#13))]
Aggregate Attributes [2]: [sum#24, sum#25]
Results [6]: [ss_ticket_number#11, ss_customer_sk#7, ss_addr_sk#9, ca_city#23, sum#26, sum#27]

(42) HashAggregate [codegen id : 14]
Input [6]: [ss_ticket_number#11, ss_customer_sk#7, ss_addr_sk#9, ca_city#23, sum#26, sum#27]
Keys [4]: [ss_ticket_number#11, ss_customer_sk#7, ss_addr_sk#9, ca_city#23]
Functions [2]: [sum(UnscaledValue(ss_coupon_amt#12)), sum(UnscaledValue(ss_net_profit#13))]
Aggregate Attributes [2]: [sum(UnscaledValue(ss_coupon_amt#12))#28, sum(UnscaledValue(ss_net_profit#13))#29]
Results [5]: [ss_ticket_number#11, ss_customer_sk#7, ca_city#23 AS bought_city#30, MakeDecimal(sum(UnscaledValue(ss_coupon_amt#12))#28,17,2) AS amt#31, MakeDecimal(sum(UnscaledValue(ss_net_profit#13))#29,17,2) AS profit#32]

(43) Exchange
Input [5]: [ss_ticket_number#11, ss_customer_sk#7, bought_city#30, amt#31, profit#32]
Arguments: hashpartitioning(ss_customer_sk#7, 5), ENSURE_REQUIREMENTS, [plan_id=7]

(44) Sort [codegen id : 15]
Input [5]: [ss_ticket_number#11, ss_customer_sk#7, bought_city#30, amt#31, profit#32]
Arguments: [ss_customer_sk#7 ASC NULLS FIRST], false, 0

(45) SortMergeJoin [codegen id : 16]
Left keys [1]: [c_customer_sk#1]
Right keys [1]: [ss_customer_sk#7]
Join type: Inner
Join condition: NOT (ca_city#6 = bought_city#30)

(46) Project [codegen id : 16]
Output [7]: [c_last_name#4, c_first_name#3, ca_city#6, bought_city#30, ss_ticket_number#11, amt#31, profit#32]
Input [9]: [c_customer_sk#1, c_first_name#3, c_last_name#4, ca_city#6, ss_ticket_number#11, ss_customer_sk#7, bought_city#30, amt#31, profit#32]

(47) TakeOrderedAndProject
Input [7]: [c_last_name#4, c_first_name#3, ca_city#6, bought_city#30, ss_ticket_number#11, amt#31, profit#32]
Arguments: 100, [c_last_name#4 ASC NULLS FIRST, c_first_name#3 ASC NULLS FIRST, ca_city#6 ASC NULLS FIRST, bought_city#30 ASC NULLS FIRST, ss_ticket_number#11 ASC NULLS FIRST], [c_last_name#4, c_first_name#3, ca_city#6, bought_city#30, ss_ticket_number#11, amt#31, profit#32]

===== Subqueries =====

Subquery:1 Hosting operator id = 15 Hosting Expression = ss_sold_date_sk#14 IN dynamicpruning#15
BroadcastExchange (52)
+- * Project (51)
   +- * Filter (50)
      +- * ColumnarToRow (49)
         +- Scan parquet spark_catalog.default.date_dim (48)


(48) Scan parquet spark_catalog.default.date_dim
Output [3]: [d_date_sk#16, d_year#33, d_dow#34]
Batched: true
Location [not included in comparison]/{warehouse_dir}/date_dim]
PushedFilters: [In(d_dow, [0,6]), In(d_year, [1999,2000,2001]), IsNotNull(d_date_sk)]
ReadSchema: struct<d_date_sk:int,d_year:int,d_dow:int>

(49) ColumnarToRow [codegen id : 1]
Input [3]: [d_date_sk#16, d_year#33, d_dow#34]

(50) Filter [codegen id : 1]
Input [3]: [d_date_sk#16, d_year#33, d_dow#34]
Condition : ((d_dow#34 IN (6,0) AND d_year#33 IN (1999,2000,2001)) AND isnotnull(d_date_sk#16))

(51) Project [codegen id : 1]
Output [1]: [d_date_sk#16]
Input [3]: [d_date_sk#16, d_year#33, d_dow#34]

(52) BroadcastExchange
Input [1]: [d_date_sk#16]
Arguments: HashedRelationBroadcastMode(List(cast(input[0, int, true] as bigint)),false), [plan_id=8]


