简体   繁体   English

使用Scala API进行Spark到EdgeRDD(GraphX)的数据帧

[英]Dataframes to EdgeRDD (GraphX) using Scala api to Spark

Is there a nice way of going from a Spark DataFrame to an EdgeRDD without hardcoding types in the Scala code? 从Spark DataFrameEdgeRDD没有在Scala代码中没有硬编码类型的好方法? The examples I've seen use case classes to define the type of the EdgeRDD . 我看过的示例使用案例类定义EdgeRDD的类型。

Let's assume that our Spark DataFrame has StructField ("dstID", LongType, false) and ("srcID", LongType, false) and between 0 and 22 additional StructField (We are constraining this so that we can use a TupleN to represent them). 假设我们的Spark DataFrame具有StructField ("dstID", LongType, false)("srcID", LongType, false)以及介于0和22之间的额外StructField (我们对此进行了限制,以便可以使用TupleN来表示它们) 。 Is there a clean way to define an EdgeRdd[TupleN] by grabbing the types from the DataFrame ? 是否有一种干净的方法可以通过从DataFrame获取类型来定义EdgeRdd[TupleN] As motivation, consider that we are loading a Parquet file that contains type information. 作为动机,请考虑我们正在加载一个包含类型信息的Parquet文件。

I'm very new to Spark and Scala, so I realize the question may be misguided. 我是Spark和Scala的新手,所以我意识到这个问题可能会被误导。 In this case, I'd appreciate learning the "correct" way of thinking about this problem. 在这种情况下,我将不胜感激地学习思考此问题的“正确”方法。

可能最简单的方法是映射到Dataframe中的Row对象(带有map )并以这种方式返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM