maropu opened a new pull request #32511: URL: https://github.com/apache/spark/pull/32511
<!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html 2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html 3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'. 4. Be sure to keep the PR description updated to reflect all changes. 5. Please write your PR title to summarize what this PR proposes. 6. If possible, provide a concise example to reproduce the issue for a faster review. 7. If you want to add a new configuration, please read the guideline first for naming configurations in 'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'. 8. If you want to add or modify an error message, please read the guideline first: https://spark.apache.org/error-message-guidelines.html --> ### What changes were proposed in this pull request? <!-- Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below. 1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers. 2. If you fix some SQL features, you can provide some references of other DBMSes. 3. If there is design documentation, please add the link. 4. If there is a discussion in the mailing list, please add the link. --> This PR proposes to print formatted strings for logical plans in the `formatted` mode, e.g., ``` scala> sql("""SELECT (SELECT avg(a) FROM t GROUP BY b), (SELECT sum(b) FROM t WHERE b > 1 GROUP BY b)""").explain("formatted") == Parsed Logical Plan == 'Project [unresolvedalias(scalar-subquery#0 [], None), unresolvedalias(scalar-subquery#1 [], None)] : :- 'Aggregate ['b], [unresolvedalias('avg('a), None)] : : +- 'UnresolvedRelation [t], [], false : +- 'Aggregate ['b], [unresolvedalias('sum('b), None)] : +- 'Filter ('b > 1) : +- 'UnresolvedRelation [t], [], false +- OneRowRelation == Analyzed Logical Plan == scalarsubquery(): double, scalarsubquery(): bigint Project (2) +- OneRowRelation (1) (1) OneRowRelation Output: [] (2) Project Input: [] Arguments: [scalar-subquery#0 [] AS scalarsubquery()#10, scalar-subquery#1 [] AS scalarsubquery()#11L] ===== Subqueries ===== Subquery:1 Hosting operator id = 2 Hosting Expression = scalar-subquery#0 [] Aggregate (5) +- SubqueryAlias (4) +- Relation parquet default.t (3) (3) Relation parquet default.t Output [2]: [a#2, b#3] (4) SubqueryAlias Input [2]: [a#2, b#3] Arguments: spark_catalog.default.t (5) Aggregate Input [2]: [a#2, b#3] Arguments: [b#3], [avg(a#2) AS avg(a)#5] Subquery:2 Hosting operator id = 2 Hosting Expression = scalar-subquery#1 [] Aggregate (9) +- Filter (8) +- SubqueryAlias (7) +- Relation parquet default.t (6) (6) Relation parquet default.t Output [2]: [a#8, b#9] (7) SubqueryAlias Input [2]: [a#8, b#9] Arguments: spark_catalog.default.t (8) Filter Input [2]: [a#8, b#9] Condition : (b#9 > 1) (9) Aggregate Input [2]: [a#8, b#9] Arguments: [b#9], [sum(b#9) AS sum(b)#7L] == Optimized Logical Plan == Project (2) +- OneRowRelation (1) (1) OneRowRelation Output: [] (2) Project Input: [] Arguments: [scalar-subquery#0 [] AS scalarsubquery()#10, scalar-subquery#1 [] AS scalarsubquery()#11L] ===== Subqueries ===== Subquery:1 Hosting operator id = 2 Hosting Expression = scalar-subquery#0 [] Aggregate (4) +- Relation parquet default.t (3) (3) Relation parquet default.t Output [2]: [a#2, b#3] (4) Aggregate Input [2]: [a#2, b#3] Arguments: [b#3], [avg(a#2) AS avg(a)#5] Subquery:2 Hosting operator id = 2 Hosting Expression = scalar-subquery#1 [] Aggregate (8) +- Project (7) +- Filter (6) +- Relation parquet default.t (5) (5) Relation parquet default.t Output [2]: [a#8, b#9] (6) Filter Input [2]: [a#8, b#9] Condition : (isnotnull(b#9) AND (b#9 > 1)) (7) Project Input [2]: [a#8, b#9] Arguments: [b#9] (8) Aggregate Input [1]: [b#9] Arguments: [b#9], [sum(b#9) AS sum(b)#7L] == Physical Plan == AdaptiveSparkPlan (3) +- Project (2) +- Scan OneRowRelation (1) (1) Scan OneRowRelation Output: [] Arguments: ParallelCollectionRDD[0] at explain at <console>:24, OneRowRelation, UnknownPartitioning(0) (2) Project Output [2]: [Subquery subquery#0, [id=#17] AS scalarsubquery()#10, Subquery subquery#1, [id=#32] AS scalarsubquery()#11L] Input: [] (3) AdaptiveSparkPlan Output [2]: [scalarsubquery()#10, scalarsubquery()#11L] Arguments: isFinalPlan=false ===== Subqueries ===== Subquery:1 Hosting operator id = 2 Hosting Expression = Subquery subquery#0, [id=#17] AdaptiveSparkPlan (8) +- HashAggregate (7) +- Exchange (6) +- HashAggregate (5) +- Scan parquet default.t (4) (4) Scan parquet default.t Output [2]: [a#2, b#3] Batched: true Location: InMemoryFileIndex [file:/Users/maropu/Repositories/spark/spark-master/spark-warehouse/t] ReadSchema: struct<a:int,b:int> (5) HashAggregate Input [2]: [a#2, b#3] Keys [1]: [b#3] Functions [1]: [partial_avg(a#2)] Aggregate Attributes [2]: [sum#14, count#15L] Results [3]: [b#3, sum#16, count#17L] (6) Exchange Input [3]: [b#3, sum#16, count#17L] Arguments: hashpartitioning(b#3, 200), ENSURE_REQUIREMENTS, [id=#15] (7) HashAggregate Input [3]: [b#3, sum#16, count#17L] Keys [1]: [b#3] Functions [1]: [avg(a#2)] Aggregate Attributes [1]: [avg(a#2)#4] Results [1]: [avg(a#2)#4 AS avg(a)#5] (8) AdaptiveSparkPlan Output [1]: [avg(a)#5] Arguments: isFinalPlan=false Subquery:2 Hosting operator id = 2 Hosting Expression = Subquery subquery#1, [id=#32] AdaptiveSparkPlan (14) +- HashAggregate (13) +- Exchange (12) +- HashAggregate (11) +- Filter (10) +- Scan parquet default.t (9) (9) Scan parquet default.t Output [1]: [b#9] Batched: true Location: InMemoryFileIndex [file:/Users/maropu/Repositories/spark/spark-master/spark-warehouse/t] PushedFilters: [IsNotNull(b), GreaterThan(b,1)] ReadSchema: struct<b:int> (10) Filter Input [1]: [b#9] Condition : (isnotnull(b#9) AND (b#9 > 1)) (11) HashAggregate Input [1]: [b#9] Keys [1]: [b#9] Functions [1]: [partial_sum(b#9)] Aggregate Attributes [1]: [sum#18L] Results [2]: [b#9, sum#19L] (12) Exchange Input [2]: [b#9, sum#19L] Arguments: hashpartitioning(b#9, 200), ENSURE_REQUIREMENTS, [id=#30] (13) HashAggregate Input [2]: [b#9, sum#19L] Keys [1]: [b#9] Functions [1]: [sum(b#9)] Aggregate Attributes [1]: [sum(b#9)#6L] Results [1]: [sum(b#9)#6L AS sum(b)#7L] (14) AdaptiveSparkPlan Output [1]: [sum(b)#7L] Arguments: isFinalPlan=false ``` This PR comes from the @cloud-fan comment: https://github.com/apache/spark/pull/28097#issuecomment-833177979 ### Why are the changes needed? <!-- Please clarify why the changes are needed. For instance, 1. If you propose a new API, clarify the use case for a new API. 2. If you fix a bug, you can clarify why it is a bug. --> For better explain mode. ### Does this PR introduce _any_ user-facing change? <!-- Note that it means *any* user-facing change including all aspects such as the documentation fix. If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible. If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master. If no, write 'No'. --> Yes, this PR makes the explain results of the `formatted` mode change. ### How was this patch tested? <!-- If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible. If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future. If tests were not added, please describe why they were not added and/or why it was difficult to add. --> Will add tests later. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org