【发布时间】:2017-05-30 23:14:22
【问题描述】:
我有 2 个数据帧
case class UserTransactions(id: Long, transactionDate: java.sql.Date, currencyUsed: String, value: Long)
ID, TransactionDate, CurrencyUsed, value
1, 2016-01-05, USD, 100
1, 2016-01-09, GBP, 150
1, 2016-02-01, USD, 50
1, 2016-02-10, JPN, 10
2, 2016-01-10, EURO, 50
2, 2016-01-10, GBP, 100
case class ReportingTime(userId: Long, reportDate: java.sql.Date)
userId, reportDate
1, 2016-01-05
1, 2016-01-31
1, 2016-02-15
2, 2016-01-10
2, 2016-02-01
现在我想通过组合userId、reportDate 和sum 之前使用的所有货币来获得摘要。结果应如下所示:
userId, reportDate, trasactionSummary
1, 2016-01-05, None
1, 2016-01-31, (USD -> 100)(GBP-> 150) // combined above 2 transactions less than 2016-01-31
1, 2016-02-15, (USD -> 150)(GBP-> 150)(JPN->10) // combined transactions less than 2016-02-15
2, 2016-01-10, None
2, 2016-02-01, (EURO-> 50) (GBP-> 100)
执行此操作的最佳方法是什么?我们有超过 3 亿笔交易,每个用户最多可以有 10,000 笔交易。
【问题讨论】:
-
在您的示例输出中,您为什么显示
None对应于reportDates 对应于UserTransactionsDataFrame 中的第一个事务?你总是想“跳过”第一笔交易吗? -
因为在第一笔交易中用户没有任何历史记录,所以总而言之,它显示 None 并且从第二笔交易开始,它将有类似 (USD -> 100)(GBP-> 150) 的总结
标签: scala apache-spark spark-dataframe parquet apache-spark-dataset