将元组的行拆分为 RDD 中的两行

Split row of tuple to two row in RDD

我尝试将整数元组拆分为 RDD 中的两行。

vertices=edges.map(lambda x:(x[0],)).union(edges.map(lambda x:(x[1],))).distinct()

我尝试了这段代码,它正在运行,但我希望代码在 运行 时间内减少 运行,而不使用 GraphFrames 包。

您可以使用 flatMap:

edges.flatMap(lambda x: x).distinct()

在 Scala 中,您只需调用 .flatMap(identity)

如果您使用 DataFrame API,您只需在唯一的列上使用 explode,例如df.select(explode("edge"))