[英]Query to Cassandra hangs up if I pass the string using Spark RDD
我有一個函數,它接受一個字符串,並使用子字符串從字符串中提取值,並使用這些值查詢Cassandra表。
def formatInputString(line: String) = {
// extract values from line using sub-string and query Cassandra table.
}
如果我通過使用Source.fromFile讀取文本文件來傳遞值,那么它將起作用(從Cassandra打印結果)...
// using Scala getLine()
for (line <- Source.fromFile("file.txt").getLines()) {
formatInputString(line)
}
但是如果像這樣使用Spark RDD就會掛斷...
// using Spark RDD
val line = sc.textFile("file.txt")
val lst = line.map(formatInputString)
有人可以解釋這種現象以及如何解決(我需要使用RDD版本)。
默認情況下,Spark以惰性方式執行許多操作。 如果要調用rdd.map(x =>(某些元素轉換)),則在執行操作之前不會進行此轉換。
http://spark.apache.org/docs/latest/programming-guide.html#actions
您可以嘗試調用“ rdd.foreach”而不是“ map”,如以上文檔所示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.