2.通过构造方法向Function传递参数(复合数据)
执行程序
package code.book.batch.sinksource.scala
import org.apache.flink.api.common.functions.MapFunction
import org.apache.flink.api.scala.{DataSet, ExecutionEnvironment, _}
object Parameters002 {
def main(args: Array[String]): Unit = {
val env = ExecutionEnvironment.getExecutionEnvironment
case class Worker(name: String, salaryPerMonth: Double)
val workers: DataSet[Worker] = env.fromElements(
Worker("zhagnsan", 1356.67),
Worker("lisi", 1476.67)
)
val month = 4
workers.map(new SalarySumMap(month)).print()
class SalarySumMap(m: Int) extends MapFunction[Worker, Worker] {
override def map(w: Worker): Worker = {
Worker(w.name, w.salaryPerMonth * m)
}
}
}
}
执行效果
Worker(zhagnsan,5426.68)
Worker(lisi,5906.68)