我有一个像这样的rdd
<item name="android:windowBackground">@android:color/black</item>
我想用相同的辅助工具将所有东西拆分到一个新的rdd然后缓存以供以后使用,因此每个独特的辅助工具有一个rdd。我看到了其他一些答案,但他们正在将rdds保存到文件中。在内存中保存这么多rdds有问题吗?它可能大约是30k +
我使用spark jobserver保存缓存的rdd。
答案 0 :(得分:0)
我建议您cache
grouped rdd
如下所示
假设您已将数据转换为:
val rddData = sparkContext.parallelize(Seq(
("55-BHA", 58, 15, "2017-05-09"),
("07-YET", 18, 5, "2017-05-09"),
("32-KXD", 27, 20, "2017-05-09"),
("19-OJD", 10, 1, "2017-05-09"),
("55-BHA", 1, 0, "2017-05-09"),
("55-BHA", 19, 3, "2017-05-09"),
("32-KXD", 787, 345, "2017-05-09"),
("07-YET", 4578, 1947, "2017-05-09"),
("07-YET", 23, 5, "2017-05-09"),
("32-KXD", 85, 11, "2017-05-09")))
您可以通过“援助”分组来cache
数据,并使用filter
选择您需要的grouped data
:
val grouped = rddData.groupBy(_._1).cache
val filtered = grouped.filter(_._1 equals("32-KXD"))
但我建议你使用DataFrame
,如下所示,这比rdd
s
import sqlContext.implicits._
val dataFrame = Seq(
("55-BHA", 58, 15, "2017-05-09"),
("07-YET", 18, 5, "2017-05-09"),
("32-KXD", 27, 20, "2017-05-09"),
("19-OJD", 10, 1, "2017-05-09"),
("55-BHA", 1, 0, "2017-05-09"),
("55-BHA", 19, 3, "2017-05-09"),
("32-KXD", 787, 345, "2017-05-09"),
("07-YET", 4578, 1947, "2017-05-09"),
("07-YET", 23, 5, "2017-05-09"),
("32-KXD", 85, 11, "2017-05-09")).toDF("aid", "session", "sessionnew", "date").cache
val newDF = dataFrame.select("*").where(dataFrame("aid") === "32-KXD")
newDF.show
我希望它有所帮助