-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29366][SQL] Subqueries created for DPP are not printed in EXPLAIN FORMATTED #26039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Test build #111829 has finished for PR 26039 at commit
|
|
Just leaving a general comment, as I'm not familiar with this change:
Sounds like contradiction: former says subquery expressions are "not" printed for now, and latter says subqueries are printed without the fix.
Shall we provide example query and actual change of explain string (before applying vs after applying)? It would be helpful to determine the effect of the patch visually. And normally we tend to not describe the title of PR as "problem statement". We tend to describe the title for what this patch will change/fix. |
|
Shall we also print the pushed filters in the scan node? |
|
@cloud-fan Actually i have a PR almost ready that implements verboseString for DataSourceScanExec to fix SPARK-29092. I am currently testing it and will open the pr very soon. Then we can co-relate the subqueries better. |
|
cc @cloud-fan fyi - i have raised the pr here scan-verbose-pr |
| case s: BaseSubqueryExec => | ||
| subqueries += ((p, e, s)) | ||
| getSubqueries(s, subqueries) | ||
| case _ => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this method put its result in the parameter subqueries, I think we don't need to call flatMap and collect, just foreach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cloud-fan We need the collect to traverse the expression tree. I have changed flatMap to foreach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the collect to traverse the expression tree
hmm, can we use foreach to traverse the expression tree? We have TreeNode.foreach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cloud-fan We have it in this form :
p.expressions.foreach(_.collect {
...
...
})
You are suggesting to do :
p.expressions.foreach(_.foreach {
...
...
}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cloud-fan Got it... I will send a small follow-up. Thank you.
|
@gatorsmile @cloud-fan def printExpressionsFlatMap(p: SparkPlan, exprs: Seq[Expression]): Unit = {
if (p.isInstanceOf[FileSourceScanExec]) {
println("flatmap")
exprs.flatMap { e =>
println(s"SQL : ${e.sql} toString= ${e.toString}")
e :: Nil
}
}
return
}
def printExpressionsForEach(p: SparkPlan, exprs: Seq[Expression]): Unit = {
if (p.isInstanceOf[FileSourceScanExec]) {
println("foreach")
exprs.foreach(e => println(s"SQL : ${e.sql} toString= ${e.toString}"))
}
}When i call the above methods for the same input |
|
Test build #111856 has finished for PR 26039 at commit
|
| getSubqueries(s, subqueries) | ||
| case _ => | ||
| } | ||
| case other => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why we remove it is because it is uesless. collect is accepting partial functions.
gatorsmile
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks! Merged to master.
…AIN FORMATTED
### What changes were proposed in this pull request?
The subquery expressions introduced by DPP are not printed in the newer explain command.
This PR fixes the code that computes the list of subqueries in the plan.
**SQL**
df1 and df2 are partitioned on k.
```
SELECT df1.id, df2.k
FROM df1 JOIN df2 ON df1.k = df2.k AND df2.id < 2
```
**Before**
```
|== Physical Plan ==
* Project (9)
+- * BroadcastHashJoin Inner BuildRight (8)
:- * ColumnarToRow (2)
: +- Scan parquet default.df1 (1)
+- BroadcastExchange (7)
+- * Project (6)
+- * Filter (5)
+- * ColumnarToRow (4)
+- Scan parquet default.df2 (3)
(1) Scan parquet default.df1
Output: [id#19L, k#20L]
(2) ColumnarToRow [codegen id : 2]
Input: [id#19L, k#20L]
(3) Scan parquet default.df2
Output: [id#21L, k#22L]
(4) ColumnarToRow [codegen id : 1]
Input: [id#21L, k#22L]
(5) Filter [codegen id : 1]
Input : [id#21L, k#22L]
Condition : (isnotnull(id#21L) AND (id#21L < 2))
(6) Project [codegen id : 1]
Output : [k#22L]
Input : [id#21L, k#22L]
(7) BroadcastExchange
Input: [k#22L]
(8) BroadcastHashJoin [codegen id : 2]
Left keys: List(k#20L)
Right keys: List(k#22L)
Join condition: None
(9) Project [codegen id : 2]
Output : [id#19L, k#22L]
Input : [id#19L, k#20L, k#22L]
```
**After**
```
|== Physical Plan ==
* Project (9)
+- * BroadcastHashJoin Inner BuildRight (8)
:- * ColumnarToRow (2)
: +- Scan parquet default.df1 (1)
+- BroadcastExchange (7)
+- * Project (6)
+- * Filter (5)
+- * ColumnarToRow (4)
+- Scan parquet default.df2 (3)
(1) Scan parquet default.df1
Output: [id#19L, k#20L]
(2) ColumnarToRow [codegen id : 2]
Input: [id#19L, k#20L]
(3) Scan parquet default.df2
Output: [id#21L, k#22L]
(4) ColumnarToRow [codegen id : 1]
Input: [id#21L, k#22L]
(5) Filter [codegen id : 1]
Input : [id#21L, k#22L]
Condition : (isnotnull(id#21L) AND (id#21L < 2))
(6) Project [codegen id : 1]
Output : [k#22L]
Input : [id#21L, k#22L]
(7) BroadcastExchange
Input: [k#22L]
(8) BroadcastHashJoin [codegen id : 2]
Left keys: List(k#20L)
Right keys: List(k#22L)
Join condition: None
(9) Project [codegen id : 2]
Output : [id#19L, k#22L]
Input : [id#19L, k#20L, k#22L]
===== Subqueries =====
Subquery:1 Hosting operator id = 1 Hosting Expression = k#20L IN subquery25
* HashAggregate (16)
+- Exchange (15)
+- * HashAggregate (14)
+- * Project (13)
+- * Filter (12)
+- * ColumnarToRow (11)
+- Scan parquet default.df2 (10)
(10) Scan parquet default.df2
Output: [id#21L, k#22L]
(11) ColumnarToRow [codegen id : 1]
Input: [id#21L, k#22L]
(12) Filter [codegen id : 1]
Input : [id#21L, k#22L]
Condition : (isnotnull(id#21L) AND (id#21L < 2))
(13) Project [codegen id : 1]
Output : [k#22L]
Input : [id#21L, k#22L]
(14) HashAggregate [codegen id : 1]
Input: [k#22L]
(15) Exchange
Input: [k#22L]
(16) HashAggregate [codegen id : 2]
Input: [k#22L]
```
### Why are the changes needed?
Without the fix, the subqueries are not printed in the explain plan.
### Does this PR introduce any user-facing change?
Yes. the explain output will be different.
### How was this patch tested?
Added a test case in ExplainSuite.
Closes apache#26039 from dilipbiswal/explain_subquery_issue.
Authored-by: Dilip Biswal <dkbiswal@gmail.com>
Signed-off-by: Xiao Li <gatorsmile@gmail.com>
What changes were proposed in this pull request?
The subquery expressions introduced by DPP are not printed in the newer explain command.
This PR fixes the code that computes the list of subqueries in the plan.
Before
`== Physical Plan ==
+- * Filter (3)
+- * ColumnarToRow (2)
+- BatchScan (1)
(1) BatchScan
Output [2]: [value#7, id#8]
Arguments: [value#7, id#8], ParquetScan(org.apache.spark.sql.test.TestSparkSession@6a299b9d,Configuration: core-default.xml, core-site.xml, mapred-default.xml, mapred-site.xml, yarn-default.xml, yarn-site.xml, hdfs-default.xml, hdfs-site.xml, spark_hadoop_conf.xml,org.apache.spark.sql.execution.datasources.InMemoryFileIndex@a51294fc,StructType(StructField(value,IntegerType,true)),StructType(StructField(value,IntegerType,true)),StructType(StructField(id,IntegerType,true)),[Lorg.apache.spark.sql.sources.Filter;@363fe35a,org.apache.spark.sql.util.CaseInsensitiveStringMap@7682ad70,Vector(isnotnull(id#8), (id#8 > 1)),List(isnotnull(value#7), (value#7 > 2)))
(2)...
(3)...
(4)...
|== Physical Plan ==
+- * Filter (3)
+- * ColumnarToRow (2)
+- BatchScan (1)
(1) BatchScan
Output [2]: [value#7, id#8]
DataFilters: [isnotnull(value#7), (value#7 > 2)]
Format: parquet
Location: InMemoryFileIndex[.....]
PartitionFilters: [isnotnull(id#8), (id#8 > 1)]
PushedFilers: [IsNotNull(id), IsNotNull(value), GreaterThan(id,1), GreaterThan(value,2)]
ReadSchema: structvalue:int
(2)...
(3)...
(4)...