|
case class Student(name: String, age: Int,teacher:Teacher)
case class Teacher(name:String,room:(Int,Int,Int),salary:Int)
def main(args: Array[String]): Unit = {
val teacher = Teacher("teacher-w",(1,2,3),99)
val students = List(Student("a",11,teacher),Student("b",22,teacher))
val benv = ExecutionEnvironment.getExecutionEnvironment
benv.fromElements(students:_*).groupBy("name").sum("teacher.salary").print()
}
以上代码会报错:
Fields 'teacher.salary' are not valid for
'com.lx.list.List1$Student(name: String, age: Integer, teacher:
com.lx.list.List1$Teacher(name: String, room: scala.Tuple3(_1:
Integer, _2: Integer, _3: Integer), salary: Integer))'.
如果把上面的groupBy换成StreamingAip 的 keyBy就可以运行通过
这是为什么?而且据我观察,好像不是groupBy的问题,而是sum方法不认嵌套类型
|