更改属于RDD的对象中的属性

时间:2015-05-14 20:20:48

标签: scala class rdd

我有以下代码:

      def generateStoriesnew(outputPath: String, groupedRDD:RDD[(String,Iterable[String])], isInChurnMode: Boolean, isInChurnPeriod: Boolean) {
val windowedRDD = groupedRDD.map(SOME CODE)
 var  windowedRDD2 = windowedRDD.filter(r => r != null).map(a=>a.churnPeriod(isInChurnPeriod,isInChurnMode))  
val prettyStringRDD = windowedRDD2.map(r => {
  r.toString
})
prettyStringRDD.saveAsTextFile(outputPath)

}

以下是ChurnPriod函数的代码:

def churnPeriod( churnPeriod:Boolean, churnMode: Boolean): Unit = {  
if (churnMode && rootEventType.equalsIgnoreCase("c")){
  var churnCustStory: CustStoryN = null
  var nonChurnCustStory: CustStoryN = null
  var churnPeriodEventStory: mutable.MutableList[StoryEventN] = null
  var NonChurnEventstory: mutable.MutableList[StoryEventN] = null
  churnPeriodEventStory = new mutable.MutableList[StoryEventN]
  NonChurnEventstory = new mutable.MutableList[StoryEventN]     
  var lastEventChurnPeriod = true
  var currentEventStory = eventStory
  var max = currentEventStory.length
  println(max);
  if (currentEventStory.size > 0) {
    for (i <- 0 until currentEventStory.length) {
      var currentEvent = currentEventStory(i)
      if (currentEvent.timeSenseRootEvent < 90) {          
        churnPeriodEventStory.+=(currentEvent)
        //lastEventChurnPeriod = true
      }
      else {
        NonChurnEventstory.+=(currentEvent)
        lastEventChurnPeriod = false
      }
    }
  }
if (churnPeriod)
  eventStory = churnPeriodEventStory
else
  eventStory=null

}     }

但是churn period函数不会更改作为custstory类成员的eventstory。我在这里错过了什么?

    class CustStoryN (val custId:String,
             var rootEventType:String,
             var rootEventTime:Long,
             var eventStory:mutable.MutableList[StoryEventN])

我的假设是: 1.map不是我所拥有的函数的正确转换 2.churnPeriod函数永远不会被调用 3.我不能改变作为特定故事类成员的eventstory 有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

通过调试确定这将是微不足道的。只需放几个断点,就可以看到程序是否在函数内部停止,以及发生了什么转换。

我的猜测是问题是这一行:if (currentEventStory.size > 0),因此,从0开始的列表永远保持为0。另一个选择是churnPeriod永远不会成立,因此,您计算了很多但从未分配给eventStory变量。

您的代码确实需要很好的清理; - )