Spark和Scala语法总结
1,193 阅读
1、require断言,一般是对参数的限制,在方法定义完成后第一时间使用require检查参数的类型等。:
例如如下,要求参数p必须大于1。
def norm(vector: Vector, p: Double): Double = {
require(p >= 1.0, "To compute the p-norm of the vector, we require that you specify a p>=1. " +
"You specified p=$p.")
}
2、match,比switch更强大的条件筛选,例如如下判断test1的结果
val result1 = test1 match {
case "1" => {
"one"
}
case "2" => "two"
case _ => "other"
}
3、persist(),RDD数据的持久化保存,和cache()类似,cache只有一个默认的缓存级别MEMORY_ONLY ,而persist可以根据情况设置其它的缓存级别。
