在spark 1.6.0中(我对spark和scala不是很熟悉)当我迭代一个集合并在迭代结束时将数据添加到数组时,数组似乎是空的。
var testing = unlabeled.map { line =>
val parts = line.split(',')
val text = parts(7).split(' ')
(line, htf.transform(text))
}
var lowPropQueue = new mutable.ArrayBuffer[(String, org.apache.spark.mllib.linalg.Vector)]
var highPropQueue = new mutable.ArrayBuffer[(String, org.apache.spark.mllib.linalg.Vector)]
for(counter <- 1 to 5){
logger.info("this is the " + counter + " run -----------------")
for (i <- testing) {
val label = model.predict(i._2).toString
// logger.info(i._1.split(",")(7))
// logger.info(label)
var probs = model.predictProbabilities(i._2)
logger.info("prob 0 : " + probs(0))
logger.info("prob 1 : " + probs(1))
logger.info("--------------------- ")
if (probs(0).toDouble <= 0.95 && probs(1).toDouble <= 0.95 ) {
lowPropQueue.+=(i)
} else {
highPropQueue.+=((i._1 + "," + label , i._2))
}
logger.info("size of high array : " + highPropQueue.length)
logger.info("size of low array : " + lowPropQueue.length)
}
logger.info("passed: " + lowPropQueue.length)
logger.info("NOT passed: " + highPropQueue.length)
var xx= sc.parallelize(highPropQueue).collect()
var yy = sc.parallelize(lowPropQueue).collect()
logger.info("passed: " + xx.length)
logger.info("NOT passed: " + yy.length)
...
}
但基于日志,内循环似乎在元数据中添加元素,即:
16/10/11 11:22:31 INFO SelfLearningMNB $:高阵列的大小:500
16/10/11 11:22:31 INFO SelfLearningMNB $:低阵列的大小:83
16/10/11 11:22:31 INFO SelfLearningMNB $:prob 0:0.37094327822665185
16/10/11 11:22:31 INFO SelfLearningMNB $:prob 1:0.6290567217733481
16/10/11 11:22:31 INFO SelfLearningMNB $:---------------------
16/10/11 11:22:31 INFO SelfLearningMNB $:高阵列的大小:500
16/10/11 11:22:31 INFO SelfLearningMNB $:低阵列的大小:84
16/10/11 11:22:31 INFO SelfLearningMNB $:prob 0:0.16872929936216619
16/10/11 11:22:31 INFO SelfLearningMNB $:prob 1:0.8312707006378338
但是当内循环结束时,我得到了这个:
16/10/11 11:43:53 INFO SelfLearningMNB $:传递:0
16/10/11 11:43:53 INFO SelfLearningMNB $:未通过:0
发生了什么事?
修改
如何从执行程序获取数据或将数据从执行程序保存到HDFS,以便以后可以从主节点读取它们?
答案 0 :(得分:1)
<强> TL; DR 这在Spark中无效。
发生了什么事?
lowPropQueue
,highPropQueue
。 FYI Naive追加ArrayBuffer
不是线程安全的。