【发布时间】:2016-08-24 21:36:03
【问题描述】:
我有一个类似的 DataFrame
+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+-----+
| disc_created_dt| disc_modified_dt| disc_line_id| quarter_num| period_year| start_date| end_date| test|
+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+-----+
|2012-05-31 10:50:...|2016-03-12 10:41:...|138371.0000000000...|4.000000000000000000|2012.000000000000...|2012-05-27 09:30:...|2012-06-23 09:30:...|42012|
|2011-09-27 03:40:...|2016-03-12 10:39:...|141773.0000000000...|1.000000000000000000|2012.000000000000...|2011-09-25 09:30:...|2011-10-29 09:30:...|12012|
|2011-06-22 02:41:...|2016-03-12 10:40:...|59374.00000000000...|4.000000000000000000|2011.000000000000...|2011-05-29 09:30:...|2011-06-25 09:30:...|42011|
|2012-02-24 23:46:...|2016-03-12 10:39:...|272176.0000000000...|3.000000000000000000|2012.000000000000...|2012-01-29 10:30:...|2012-02-25 10:30:...|32012|
|2012-09-16 15:02:...|2016-03-12 10:42:...|450778.0000000000...|1.000000000000000000|2013.000000000000...|2012-08-26 09:30:...|2012-09-22 09:30:...|12013|
+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+-----+
disc_line_id 可以有重复的值。
有两个要求:
根据我使用 dropDuplicates 命令所做的
created_date,我只希望每个disc_line_id有 1 条记录。我想要所有记录,除了首先基于
modified_date的disc_line_id
如果两者都可以在一次转换中完成,那就太好了。
例子
disc_line_id|created_date|modified_date
1 2016-08-24 2016-08-24
1 2016-08-21 2016-08-21
1 2016-08-21 2016-08-24
2 2016-08-23 2016-08-24
3 2016-08-22 2016-08-22
3 2016-08-22 2016-08-23
3 2016-08-22 2016-08-24
对于我想要的以下数据框
Req 1(每个光盘行 id 基于创建日期):
disc_line_id|created_date|modified_date
1 2016-08-21 2016-08-21
2 2016-08-23 2016-08-24
3 2016-08-22 2016-08-22
Req 2(每个光盘行 id 基于修改日期):
disc_line_id|created_date|modified_date
1 2016-08-24 2016-08-24
1 2016-08-21 2016-08-24
3 2016-08-22 2016-08-23
3 2016-08-22 2016-08-24
我是 spark 和 scala 的新手,任何帮助将不胜感激。火花版本 1.4.1
【问题讨论】:
-
我不确定我是否理解你想要的。你能举一个你想要的输出的例子吗?
-
@shakedzy 添加示例
-
Req1 中的第一个
modified_date应该是2016-08-24对吧?另外,我不明白你在 Req2 中做了什么。为什么这些行被省略了? -
Req 1 中没有我正在使用最旧的创建日期。并且在 Req 2 中,我将取除第一个创建的行之外的所有重复行
标签: scala apache-spark