== Physical Plan ==
* HashAggregate (29)
+- Exchange (28)
   +- * HashAggregate (27)
      +- * Project (26)
         +- * BroadcastHashJoin Inner BuildRight (25)
            :- * Project (23)
            :  +- * BroadcastHashJoin Inner BuildRight (22)
            :     :- * Project (10)
            :     :  +- * BroadcastHashJoin Inner BuildRight (9)
            :     :     :- * Filter (3)
            :     :     :  +- * ColumnarToRow (2)
            :     :     :     +- Scan parquet spark_catalog.default.catalog_sales (1)
            :     :     +- BroadcastExchange (8)
            :     :        +- * Project (7)
            :     :           +- * Filter (6)
            :     :              +- * ColumnarToRow (5)
            :     :                 +- Scan parquet spark_catalog.default.item (4)
            :     +- BroadcastExchange (21)
            :        +- * Filter (20)
            :           +- * HashAggregate (19)
            :              +- Exchange (18)
            :                 +- * HashAggregate (17)
            :                    +- * Project (16)
            :                       +- * BroadcastHashJoin Inner BuildRight (15)
            :                          :- * Filter (13)
            :                          :  +- * ColumnarToRow (12)
            :                          :     +- Scan parquet spark_catalog.default.catalog_sales (11)
            :                          +- ReusedExchange (14)
            +- ReusedExchange (24)


(1) Scan parquet spark_catalog.default.catalog_sales
Output [3]: [cs_item_sk#1, cs_ext_discount_amt#2, cs_sold_date_sk#3]
Batched: true
Location: InMemoryFileIndex []
PartitionFilters: [isnotnull(cs_sold_date_sk#3), dynamicpruningexpression(cs_sold_date_sk#3 IN dynamicpruning#4)]
PushedFilters: [IsNotNull(cs_item_sk), IsNotNull(cs_ext_discount_amt)]
ReadSchema: struct<cs_item_sk:int,cs_ext_discount_amt:decimal(7,2)>

(2) ColumnarToRow [codegen id : 6]
Input [3]: [cs_item_sk#1, cs_ext_discount_amt#2, cs_sold_date_sk#3]

(3) Filter [codegen id : 6]
Input [3]: [cs_item_sk#1, cs_ext_discount_amt#2, cs_sold_date_sk#3]
Condition : (isnotnull(cs_item_sk#1) AND isnotnull(cs_ext_discount_amt#2))

(4) Scan parquet spark_catalog.default.item
Output [2]: [i_item_sk#5, i_manufact_id#6]
Batched: true
Location [not included in comparison]/{warehouse_dir}/item]
PushedFilters: [IsNotNull(i_manufact_id), EqualTo(i_manufact_id,977), IsNotNull(i_item_sk)]
ReadSchema: struct<i_item_sk:int,i_manufact_id:int>

(5) ColumnarToRow [codegen id : 1]
Input [2]: [i_item_sk#5, i_manufact_id#6]

(6) Filter [codegen id : 1]
Input [2]: [i_item_sk#5, i_manufact_id#6]
Condition : ((isnotnull(i_manufact_id#6) AND (i_manufact_id#6 = 977)) AND isnotnull(i_item_sk#5))

(7) Project [codegen id : 1]
Output [1]: [i_item_sk#5]
Input [2]: [i_item_sk#5, i_manufact_id#6]

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

(9) BroadcastHashJoin [codegen id : 6]
Left keys [1]: [cs_item_sk#1]
Right keys [1]: [i_item_sk#5]
Join type: Inner
Join condition: None

(10) Project [codegen id : 6]
Output [3]: [cs_ext_discount_amt#2, cs_sold_date_sk#3, i_item_sk#5]
Input [4]: [cs_item_sk#1, cs_ext_discount_amt#2, cs_sold_date_sk#3, i_item_sk#5]

(11) Scan parquet spark_catalog.default.catalog_sales
Output [3]: [cs_item_sk#7, cs_ext_discount_amt#8, cs_sold_date_sk#9]
Batched: true
Location: InMemoryFileIndex []
PartitionFilters: [isnotnull(cs_sold_date_sk#9), dynamicpruningexpression(cs_sold_date_sk#9 IN dynamicpruning#4)]
PushedFilters: [IsNotNull(cs_item_sk)]
ReadSchema: struct<cs_item_sk:int,cs_ext_discount_amt:decimal(7,2)>

(12) ColumnarToRow [codegen id : 3]
Input [3]: [cs_item_sk#7, cs_ext_discount_amt#8, cs_sold_date_sk#9]

(13) Filter [codegen id : 3]
Input [3]: [cs_item_sk#7, cs_ext_discount_amt#8, cs_sold_date_sk#9]
Condition : isnotnull(cs_item_sk#7)

(14) ReusedExchange [Reuses operator id: 34]
Output [1]: [d_date_sk#10]

(15) BroadcastHashJoin [codegen id : 3]
Left keys [1]: [cs_sold_date_sk#9]
Right keys [1]: [d_date_sk#10]
Join type: Inner
Join condition: None

(16) Project [codegen id : 3]
Output [2]: [cs_item_sk#7, cs_ext_discount_amt#8]
Input [4]: [cs_item_sk#7, cs_ext_discount_amt#8, cs_sold_date_sk#9, d_date_sk#10]

(17) HashAggregate [codegen id : 3]
Input [2]: [cs_item_sk#7, cs_ext_discount_amt#8]
Keys [1]: [cs_item_sk#7]
Functions [1]: [partial_avg(UnscaledValue(cs_ext_discount_amt#8))]
Aggregate Attributes [2]: [sum#11, count#12]
Results [3]: [cs_item_sk#7, sum#13, count#14]

(18) Exchange
Input [3]: [cs_item_sk#7, sum#13, count#14]
Arguments: hashpartitioning(cs_item_sk#7, 5), ENSURE_REQUIREMENTS, [plan_id=2]

(19) HashAggregate [codegen id : 4]
Input [3]: [cs_item_sk#7, sum#13, count#14]
Keys [1]: [cs_item_sk#7]
Functions [1]: [avg(UnscaledValue(cs_ext_discount_amt#8))]
Aggregate Attributes [1]: [avg(UnscaledValue(cs_ext_discount_amt#8))#15]
Results [2]: [(1.3 * cast((avg(UnscaledValue(cs_ext_discount_amt#8))#15 / 100.0) as decimal(11,6))) AS (1.3 * avg(cs_ext_discount_amt))#16, cs_item_sk#7]

(20) Filter [codegen id : 4]
Input [2]: [(1.3 * avg(cs_ext_discount_amt))#16, cs_item_sk#7]
Condition : isnotnull((1.3 * avg(cs_ext_discount_amt))#16)

(21) BroadcastExchange
Input [2]: [(1.3 * avg(cs_ext_discount_amt))#16, cs_item_sk#7]
Arguments: HashedRelationBroadcastMode(List(cast(input[1, int, true] as bigint)),false), [plan_id=3]

(22) BroadcastHashJoin [codegen id : 6]
Left keys [1]: [i_item_sk#5]
Right keys [1]: [cs_item_sk#7]
Join type: Inner
Join condition: (cast(cs_ext_discount_amt#2 as decimal(14,7)) > (1.3 * avg(cs_ext_discount_amt))#16)

(23) Project [codegen id : 6]
Output [2]: [cs_ext_discount_amt#2, cs_sold_date_sk#3]
Input [5]: [cs_ext_discount_amt#2, cs_sold_date_sk#3, i_item_sk#5, (1.3 * avg(cs_ext_discount_amt))#16, cs_item_sk#7]

(24) ReusedExchange [Reuses operator id: 34]
Output [1]: [d_date_sk#17]

(25) BroadcastHashJoin [codegen id : 6]
Left keys [1]: [cs_sold_date_sk#3]
Right keys [1]: [d_date_sk#17]
Join type: Inner
Join condition: None

(26) Project [codegen id : 6]
Output [1]: [cs_ext_discount_amt#2]
Input [3]: [cs_ext_discount_amt#2, cs_sold_date_sk#3, d_date_sk#17]

(27) HashAggregate [codegen id : 6]
Input [1]: [cs_ext_discount_amt#2]
Keys: []
Functions [1]: [partial_sum(UnscaledValue(cs_ext_discount_amt#2))]
Aggregate Attributes [1]: [sum#18]
Results [1]: [sum#19]

(28) Exchange
Input [1]: [sum#19]
Arguments: SinglePartition, ENSURE_REQUIREMENTS, [plan_id=4]

(29) HashAggregate [codegen id : 7]
Input [1]: [sum#19]
Keys: []
Functions [1]: [sum(UnscaledValue(cs_ext_discount_amt#2))]
Aggregate Attributes [1]: [sum(UnscaledValue(cs_ext_discount_amt#2))#20]
Results [1]: [MakeDecimal(sum(UnscaledValue(cs_ext_discount_amt#2))#20,17,2) AS excess discount amount#21]

===== Subqueries =====

Subquery:1 Hosting operator id = 1 Hosting Expression = cs_sold_date_sk#3 IN dynamicpruning#4
BroadcastExchange (34)
+- * Project (33)
   +- * Filter (32)
      +- * ColumnarToRow (31)
         +- Scan parquet spark_catalog.default.date_dim (30)


(30) Scan parquet spark_catalog.default.date_dim
Output [2]: [d_date_sk#17, d_date#22]
Batched: true
Location [not included in comparison]/{warehouse_dir}/date_dim]
PushedFilters: [IsNotNull(d_date), GreaterThanOrEqual(d_date,2000-01-27), LessThanOrEqual(d_date,2000-04-26), IsNotNull(d_date_sk)]
ReadSchema: struct<d_date_sk:int,d_date:date>

(31) ColumnarToRow [codegen id : 1]
Input [2]: [d_date_sk#17, d_date#22]

(32) Filter [codegen id : 1]
Input [2]: [d_date_sk#17, d_date#22]
Condition : (((isnotnull(d_date#22) AND (d_date#22 >= 2000-01-27)) AND (d_date#22 <= 2000-04-26)) AND isnotnull(d_date_sk#17))

(33) Project [codegen id : 1]
Output [1]: [d_date_sk#17]
Input [2]: [d_date_sk#17, d_date#22]

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

Subquery:2 Hosting operator id = 11 Hosting Expression = cs_sold_date_sk#9 IN dynamicpruning#4


