尝试使用spark在单个foreach中创建多个数据帧,如下所示
当我尝试打印时,我会获得值传递并点击row.getAs("type")
。
val check = eachrec.foreach(recrd => recrd.map(row => {
row.getAs("type") match {
case "delivery" => val delivery_data = delivery(row.get(0).toString,row.get(1).toString)
case "click" => val click_data = delivery(row.get(0).toString,row.get(1).toString)
case _ => "not sure if this impacts"
}})
)
但是低于错误:
错误:(41,14)类型不匹配; found:String(" delivery")required:Nothing 案例"交付" => val delivery_data = delivery(row.get(0).toString,row.get(1).toString) ^
我的计划是在创建delivery_data和click_data引用的各个交付对象后,使用todf()
创建数据框:
delivery_data.toDF() and click_data.toDF().
答案 0 :(得分:0)
val
声明会使您的前2 case
返回类型为unit
,但在第三种情况下,您会返回String
例如,此处z
类型由编译器Unit
推断:
def x = {
val z: Unit = 3 match {
case 2 => val a = 2
case _ => val b = 3
}
}