robreeves opened a new pull request, #46490:
URL: https://github.com/apache/spark/pull/46490

   <!--
   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 type or message, please read the 
guideline first in
        'common/utils/src/main/resources/error/README.md'.
   -->
   
   ### 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 introduces a new debugging method to identify which values are 
producing skew in a dataset.
   
   
   ### Why are the changes needed?
   Debugging skew join is a pain point. Once the skew is identified from the 
metrics (e.g. one partition has much more data), it is cumbersome to figure out 
exactly where that skew is coming from. Usually you need to write a manual 
aggregation and write the output to the logs. This streamlines the process by 
adding a method `inlineColumnsCount` to do this automatically, inferring the 
join keys to count.
   
   The current solution still requires a code change. A useful extension to 
this would be to add a configuration like `spark.sql.join.countkeyvals=true` so 
this feature can be enabled without any code changes. It would have to be 
enabled for all joins, but for debugging that is okay. This can be useful for 
prod jobs and more generally anytime uploading a code change to test is a 
longer iteration cycle.
   
   I would also like to add a SQL hint for pure SQL jobs.
   
   ### 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'.
   -->
   
   
   ### How was this patch tested?
   Manual testing:
   ```
   import org.apache.spark.sql.execution.debug._
   
   val a = spark.range(3)
   val b = spark.range(100).withColumn("id2", $"id" % 2).select($"id2")
   
   a.join(b, $"id" === $"id2").inlineColumnsCount().collect
   
   Column value counts after processing 10 rows
   id#0L: 0,id2#4L: 0 = 10 (100%)
   Column value counts after processing 20 rows
   id#0L: 0,id2#4L: 0 = 20 (100%)
   Column value counts after processing 30 rows
   id#0L: 0,id2#4L: 0 = 30 (100%)
   Column value counts after processing 40 rows
   id#0L: 0,id2#4L: 0 = 40 (100%)
   Column value counts after processing 50 rows
   id#0L: 0,id2#4L: 0 = 50 (100%)
   Column value counts after processing 60 rows
   id#0L: 0,id2#4L: 0 = 50 (83%)
   id#0L: 1,id2#4L: 1 = 10 (16%)
   Column value counts after processing 70 rows
   id#0L: 0,id2#4L: 0 = 50 (71%)
   id#0L: 1,id2#4L: 1 = 20 (28%)
   Column value counts after processing 80 rows
   id#0L: 0,id2#4L: 0 = 50 (62%)
   id#0L: 1,id2#4L: 1 = 30 (37%)
   Column value counts after processing 90 rows
   id#0L: 0,id2#4L: 0 = 50 (55%)
   id#0L: 1,id2#4L: 1 = 40 (44%)
   Column value counts after processing 100 rows
   id#0L: 0,id2#4L: 0 = 50 (50%)
   id#0L: 1,id2#4L: 1 = 50 (50%)
   ```
   
   Here is an example of what the plan looks like:
   ```
   == Parsed Logical Plan ==
   DebugInlineColumnsCount
   +- Join Inner, (id#17L = id2#21L)
      :- Range (0, 3, step=1, splits=Some(12))
      +- Project [id2#21L]
         +- Project [id#19L, (id#19L % cast(2 as bigint)) AS id2#21L]
            +- Range (0, 100, step=1, splits=Some(12))
   
   == Analyzed Logical Plan ==
   id: bigint, id2: bigint
   DebugInlineColumnsCount [id#17L, id2#21L]
   +- Join Inner, (id#17L = id2#21L)
      :- Range (0, 3, step=1, splits=Some(12))
      +- Project [id2#21L]
         +- Project [id#19L, (id#19L % cast(2 as bigint)) AS id2#21L]
            +- Range (0, 100, step=1, splits=Some(12))
   
   == Optimized Logical Plan ==
   DebugInlineColumnsCount [id#17L, id2#21L]
   +- Join Inner, (id#17L = id2#21L)
      :- Range (0, 3, step=1, splits=Some(12))
      +- Project [(id#19L % 2) AS id2#21L]
         +- Filter isnotnull((id#19L % 2))
            +- Range (0, 100, step=1, splits=Some(12))
   
   == Physical Plan ==
   AdaptiveSparkPlan isFinalPlan=false
   +- DebugInlineColumnsCount [id#17L, id2#21L]
      +- SortMergeJoin [id#17L], [id2#21L], Inner
         :- Sort [id#17L ASC NULLS FIRST], false, 0
         :  +- Exchange hashpartitioning(id#17L, 200), ENSURE_REQUIREMENTS, 
[plan_id=128]
         :     +- Range (0, 3, step=1, splits=12)
         +- Sort [id2#21L ASC NULLS FIRST], false, 0
            +- Exchange hashpartitioning(id2#21L, 200), ENSURE_REQUIREMENTS, 
[plan_id=127]
               +- Project [(id#19L % 2) AS id2#21L]
                  +- Filter isnotnull((id#19L % 2))
                     +- Range (0, 100, step=1, splits=12)
   ```
   
   ### Was this patch authored or co-authored using generative AI tooling?
   No
   


-- 
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.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

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

Reply via email to