Scala代码未执行 [英] Scala Code not executing

查看:75
本文介绍了Scala代码未执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Spark上执行以下scala代码,但由于某种原因未调用选择性函数

I am trying to execute the following scala code on Spark but due to some reason the function selective is not getting called

var lines = sc.textFile(inputPath+fileName,1)
val lines2 =lines.map(l=>selective(
func,List(2,3),List(1,26),l,";",0           
))
lines2.toArray().foreach(l=>out.write(l))
.......

选择功能定义如下

def selective(f: (String,Boolean) => String , phoneFields: Seq[Int], codeFields: Seq[Int], in: String, delimiter:String, iMode:Int /* 0 for enc, 1 for dec */) :String =
        in.split(delimiter,-1).zipWithIndex
    .map { 

      case (str, ix) 
    if( phoneFields.contains(ix)||codeFields.contains(ix)) => 
        var output=f(str,codeFields.contains(ix))
        var sTemp=str+":"+output+"\n"
        if((iMode==0)&&codeFields.contains(ix)&&(str.compareTo("")!=0)  )
            CodeDictString+=sTemp
        else if(str.compareTo("")!=0)
            PhoneDictString+=sTemp

        output
      case other => other._1
    }.mkString(";").+("\n")

println语句未执行.此外,该函数不返回任何东西.sc是Spark上下文对象

The println statement is not executing. Furthermore the function is not returning any thing. sc is the spark context object

推荐答案

此函数无法编译.语法

{
  some statement
  case ... => ...

无效.案例陈述只能 出现如下:

is not valid. Case statements can only appear like this:

{
   case ... => ...
       ...
   case ... => ...
       ...
}

由于您显然可以编译某物,所以我敢打赌,在 println 之前有一个case语句,并且该case语句未被选中.

Since you obviously got something to compile, I bet there's a case statement before that println, and that case statement is not being selected.

这篇关于Scala代码未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆