有两个DataFrames(Scala中,阿帕奇星火1.6.1)如何在Scala和Apache Spark中连接两个DataFrame?
1)匹配
MatchID | Player1 | Player2
--------------------------------
1 | John Wayne | John Doe
2 | Ive Fish | San Simon
2)个人资料
Player | BirthYear
--------------------------------
John Wayne | 1986
Ive Fish | 1990
San Simon | 1974
john Doe | 1995
怎么会用 'BirthYear' 一个新的数据帧对于双方球员来说
MatchID | Player1 | Player2 | BYear_P1 |BYear_P2 | Diff
-------------------------------------------------------------
1 | John Wayne | John Doe | 1986 | 1995 | 9
2 | Ive Fish | San Simon | 1990 | 1974 | 16
?
我试图
val df = MatchesDF.join(PersonalDF, MatchesDF("Player1") === PersonalDF("Player"))
然后第二个玩家
val resDf = df.join(PersonalDF, df("Player2") === PersonalDF("Player"))
再次加入,但它是非常耗时的操作。
可能是Scala和Apache Spark中的另一种方法吗?
再次做两联接,它是如何做的更好? – void
这对匹配表运行约2分钟,约10000行, 玩家表约700记录 – gmlvsv
使用数据框为您的连接,而不是普通的SQL更好的性能。 – dheee