== Physical Plan ==
* Sort (13)
+- Exchange (12)
   +- * HashAggregate (11)
      +- Exchange (10)
         +- * HashAggregate (9)
            +- * Project (8)
               +- * BroadcastHashJoin LeftAnti BuildRight (7)
                  :- * Filter (3)
                  :  +- * ColumnarToRow (2)
                  :     +- Scan parquet spark_catalog.default.customer (1)
                  +- BroadcastExchange (6)
                     +- * ColumnarToRow (5)
                        +- Scan parquet spark_catalog.default.orders (4)


(1) Scan parquet spark_catalog.default.customer
Output [3]: [c_custkey#1, c_phone#2, c_acctbal#3]
Batched: true
Location [not included in comparison]/{warehouse_dir}/customer]
PushedFilters: [IsNotNull(c_acctbal)]
ReadSchema: struct<c_custkey:bigint,c_phone:string,c_acctbal:decimal(10,0)>

(2) ColumnarToRow [codegen id : 2]
Input [3]: [c_custkey#1, c_phone#2, c_acctbal#3]

(3) Filter [codegen id : 2]
Input [3]: [c_custkey#1, c_phone#2, c_acctbal#3]
Condition : ((isnotnull(c_acctbal#3) AND substring(c_phone#2, 1, 2) IN (13,31,23,29,30,18,17)) AND (cast(c_acctbal#3 as decimal(14,4)) > ReusedSubquery Subquery scalar-subquery#4, [id=#1]))

(4) Scan parquet spark_catalog.default.orders
Output [1]: [o_custkey#5]
Batched: true
Location [not included in comparison]/{warehouse_dir}/orders]
ReadSchema: struct<o_custkey:bigint>

(5) ColumnarToRow [codegen id : 1]
Input [1]: [o_custkey#5]

(6) BroadcastExchange
Input [1]: [o_custkey#5]
Arguments: HashedRelationBroadcastMode(List(input[0, bigint, true]),false), [plan_id=2]

(7) BroadcastHashJoin [codegen id : 2]
Left keys [1]: [c_custkey#1]
Right keys [1]: [o_custkey#5]
Join type: LeftAnti
Join condition: None

(8) Project [codegen id : 2]
Output [2]: [substring(c_phone#2, 1, 2) AS cntrycode#6, c_acctbal#3]
Input [3]: [c_custkey#1, c_phone#2, c_acctbal#3]

(9) HashAggregate [codegen id : 2]
Input [2]: [cntrycode#6, c_acctbal#3]
Keys [1]: [cntrycode#6]
Functions [2]: [partial_count(1), partial_sum(c_acctbal#3)]
Aggregate Attributes [3]: [count#7, sum#8, isEmpty#9]
Results [4]: [cntrycode#6, count#10, sum#11, isEmpty#12]

(10) Exchange
Input [4]: [cntrycode#6, count#10, sum#11, isEmpty#12]
Arguments: hashpartitioning(cntrycode#6, 5), ENSURE_REQUIREMENTS, [plan_id=3]

(11) HashAggregate [codegen id : 3]
Input [4]: [cntrycode#6, count#10, sum#11, isEmpty#12]
Keys [1]: [cntrycode#6]
Functions [2]: [count(1), sum(c_acctbal#3)]
Aggregate Attributes [2]: [count(1)#13, sum(c_acctbal#3)#14]
Results [3]: [cntrycode#6, count(1)#13 AS numcust#15, sum(c_acctbal#3)#14 AS totacctbal#16]

(12) Exchange
Input [3]: [cntrycode#6, numcust#15, totacctbal#16]
Arguments: rangepartitioning(cntrycode#6 ASC NULLS FIRST, 5), ENSURE_REQUIREMENTS, [plan_id=4]

(13) Sort [codegen id : 4]
Input [3]: [cntrycode#6, numcust#15, totacctbal#16]
Arguments: [cntrycode#6 ASC NULLS FIRST], true, 0

===== Subqueries =====

Subquery:1 Hosting operator id = 3 Hosting Expression = ReusedSubquery Subquery scalar-subquery#4, [id=#1]

Subquery:2 Hosting operator id = 1 Hosting Expression = Subquery scalar-subquery#4, [id=#1]
* HashAggregate (20)
+- Exchange (19)
   +- * HashAggregate (18)
      +- * Project (17)
         +- * Filter (16)
            +- * ColumnarToRow (15)
               +- Scan parquet spark_catalog.default.customer (14)


(14) Scan parquet spark_catalog.default.customer
Output [2]: [c_phone#17, c_acctbal#18]
Batched: true
Location [not included in comparison]/{warehouse_dir}/customer]
PushedFilters: [IsNotNull(c_acctbal), GreaterThan(c_acctbal,0)]
ReadSchema: struct<c_phone:string,c_acctbal:decimal(10,0)>

(15) ColumnarToRow [codegen id : 1]
Input [2]: [c_phone#17, c_acctbal#18]

(16) Filter [codegen id : 1]
Input [2]: [c_phone#17, c_acctbal#18]
Condition : ((isnotnull(c_acctbal#18) AND (c_acctbal#18 > 0)) AND substring(c_phone#17, 1, 2) IN (13,31,23,29,30,18,17))

(17) Project [codegen id : 1]
Output [1]: [c_acctbal#18]
Input [2]: [c_phone#17, c_acctbal#18]

(18) HashAggregate [codegen id : 1]
Input [1]: [c_acctbal#18]
Keys: []
Functions [1]: [partial_avg(UnscaledValue(c_acctbal#18))]
Aggregate Attributes [2]: [sum#19, count#20]
Results [2]: [sum#21, count#22]

(19) Exchange
Input [2]: [sum#21, count#22]
Arguments: SinglePartition, ENSURE_REQUIREMENTS, [plan_id=5]

(20) HashAggregate [codegen id : 2]
Input [2]: [sum#21, count#22]
Keys: []
Functions [1]: [avg(UnscaledValue(c_acctbal#18))]
Aggregate Attributes [1]: [avg(UnscaledValue(c_acctbal#18))#23]
Results [1]: [cast((avg(UnscaledValue(c_acctbal#18))#23 / 1.0) as decimal(14,4)) AS avg(c_acctbal)#24]


