我有一些文档文件,我尝试读取数据,然后使用 zipWithIndex() 函数使用索引压缩如下:
JavaRDD<String> rawTextRDD = sc.textFile("demo.txt");
JavaPairRDD<String, Long> zipIndex = rawTextRDD.zipWithIndex();
之后 zipIndex 的值是一个包含键值对的 JavaPairRDD,看起来像 ["This is the beautiful picture", 0], ["This is another picture", 1]。
但是现在,我想使用以下方法将 zipIndex 转换为 DataFrame:
DataFrame docDF = sqlContext.createDataFrame(zipIndex, TextId.class);
函数 createDataFrame 不接受参数 zipIndex(TextId 是具有 2 个属性的类:String text 和 int docId)。
我在 Scala 中也有一个代码,它运行得很好。请参考这个:
val rawTextRDD = sc.textFile("demo.txt")
val docDF = rawTextRDD.zipWithIndex.toDF("text", "docId")
如果有什么解决办法。请帮我解决。谢谢