0
我是Spark/Scala世界的新手,我對從數據框中選擇數據有疑問。 我有一個表與下面的數據,我需要選擇每個卡斯特和USER_ID對,所有的最後修改的記錄,用最大MODIFY_TIME:如何從數據框中爲一對密鑰選擇最近的數據?
原始數據幀:
+--------+----------+------------+--------------------+
| cust | user_id | another_id | modify_time |
+--------+----------+------------+--------------------+
| cust1| 1 | 222|2017-03-22 07:29 |
| cust1| 1 | 111|2017-03-22 07:29 |
| cust2| 2 | 111|2017-03-21 07:29 |
| cust1| 1 | 333|2017-03-21 07:29 |
| cust2| 2 | 444|2017-03-22 07:29 |
| cust2| 2 | 333|2017-03-22 07:29 |
+--------+----------+------------+--------------------+
所需的結果:
+--------+----------+------------+--------------------+
| cust | user_id | another_id | modify_time |
+--------+----------+------------+--------------------+
| cust1| 1 | 222|2017-03-22 07:29 |
| cust1| 1 | 111|2017-03-22 07:29 |
| cust2| 2 | 444|2017-03-22 07:29 |
| cust2| 2 | 333|2017-03-22 07:29 |
+--------+----------+------------+--------------------+
什麼是最有效的方式來做到這一點?