apache-spark - 在 Spark 中比较执行器之间的数据

标签 apache-spark hadoop

我们有一个 spark 应用程序,其中数据在不同的执行程序之间共享。但是我们还需要比较执行器之间的数据,其中一些数据存在于 executor-1 中,一些数据存在于 executor-2 中。我们想知道如何在 spark 中实现?

例如:有一个包含以下详细信息的文件:

Name, Date1, Date2
A, 2019-01-01, 2019-01-23
A, 2019-02-12, 2019-03-21
A, 2019-04-01, 2019-05-31
A, 2019-06-02, 2019-12-30
B, 2019-01-01, 2019-01-21
B, 2019-02-10, 2019-03-21
B, 2019-04-01, 2019-12-31

我需要通过检查第一行的 date2 和第二行的 date1 等等来找出这些元素之间的总差距。即

For example: for Name A: (2019-02-12 - 2019-01-23) + (2019-04-01 - 2019-03-21) + (2019-06-02 -2019-05-31) + (2019-12-31 - 2019-12-30) .. Year is ending on 2019-12-31, so there is gap of 1 day and also number of gaps (if difference between above formula per date > 0) will be 4.

For Name B: (2019-02-10 - 2019-01-21) + (2019-04-01 - 2019-03-21), and number of gaps would be 2.

一种方法是使用 collectAsList(),它将所有数据检索到驱动程序,但是是否有不同的有效方法直接在执行程序之间比较它们,如果是的话,我们该怎么做?

最佳答案

只需编写一个带有滞后窗口、限定的 SQL 查询,检查相邻行的日期和日期减 1,主键限定为名称。在名称中也进行排序。

您不必担心 Executors,Spark 会根据 Name 自动为您散列到由 Executor 服务的分区。

关于apache-spark - 在 Spark 中比较执行器之间的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57494928/

相关文章:

hadoop - 链接 Map Reduce 程序

hadoop - 如果我使用 S3 而不是 HDFS,是否仍然需要 Namenode?

postgresql - Cassandra 作为 PostgreSQL 的替代品

apache-spark - 在 V4 s3 存储桶上使用 s3a 协议(protocol)时出现错误请求

hadoop - 在Hadoop中合并两个SortedMapWritable?

java - Spark : JavaRDD<Tuple2> to JavaPairRDD<>

file - 在 hadoop 文件系统中查找文件

scala - 对由partitionBy创建的一个输出目录中的数据进行排序

scala - Spark : way to join each row of dataframe with all rows of another dataframe

java - Spark : print dataframe in Java