gpt4 book ai didi

apache-spark - Spark SQL : Why am I seeing 3 jobs instead of one single job in the Spark UI?

转载 作者:行者123 更新时间:2023-12-03 16:59:46 26 4
gpt4 key购买 nike

根据我的理解,每个action会有一份工作。在 Spark 。
但我经常看到单个操作触发了多个作业。
我试图通过对数据集进行简单的聚合来测试这一点,以获得每个类别的最大值(这里是“主题”字段)
在检查 Spark UI 时,我可以看到为 groupBy 执行了 3 个“作业”。操作,而我期待只有一个。
谁能帮我理解为什么有 3 而不是只有 1?

   students.show(5)

+----------+--------------+----------+----+-------+-----+-----+
|student_id|exam_center_id| subject|year|quarter|score|grade|
+----------+--------------+----------+----+-------+-----+-----+
| 1| 1| Math|2005| 1| 41| D|
| 1| 1| Spanish|2005| 1| 51| C|
| 1| 1| German|2005| 1| 39| D|
| 1| 1| Physics|2005| 1| 35| D|
| 1| 1| Biology|2005| 1| 53| C|
| 1| 1|Philosophy|2005| 1| 73| B|


// Task : Find Highest Score in each subject
val highestScores = students.groupBy("subject").max("score")
highestScores.show(10)

+----------+----------+
| subject|max(score)|
+----------+----------+
| Spanish| 98|
|Modern Art| 98|
| French| 98|
| Physics| 98|
| Geography| 98|
| History| 98|
| English| 98|
| Classics| 98|
| Math| 98|
|Philosophy| 98|
+----------+----------+
only showing top 10 rows
在检查 Spark UI 时,我可以看到为 groupBy 执行了 3 个“作业”。操作,而我期待只有一个。
enter image description here
enter image description here
谁能帮我理解为什么有 3 而不是只有 1?
== Physical Plan ==
*(2) HashAggregate(keys=[subject#12], functions=[max(score#15)])
+- Exchange hashpartitioning(subject#12, 1)
+- *(1) HashAggregate(keys=[subject#12], functions=[partial_max(score#15)])
+- *(1) FileScan csv [subject#12,score#15] Batched: false, Format: CSV, Location: InMemoryFileIndex[file:/C:/lab/SparkLab/files/exams/students.csv], PartitionFilters: [], PushedFilters: [], ReadSchema: struct<subject:string,score:int>

最佳答案

我认为只有 #3 执行实际的“工作”(执行一个计划,如果您在 SQL 选项卡上打开查询的详细信息,您将看到该计划)。另外两个是准备步骤——

  • #1 正在查询 NameNode 来构建 InMemoryFileIndex读取您的 csv 和
  • #2 正在对数据集进行采样以执行 .groupBy("subject").max("score")内部需要一个 sortByKey ( here 是更多细节)。
  • 关于apache-spark - Spark SQL : Why am I seeing 3 jobs instead of one single job in the Spark UI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62611515/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com