通过spark-sql,将查询timstamp字段时间戳转换成日期格式:
val simpleDateFormat = new SimpleDateFormat("yyyyMM")
spark.udf.register("changDate",(x:Long)=> simpleDateFormat.format(new Date(x * 1000L)))
val df: DataFrame = spark.sql("select mid,uid,score,changDate(timstamp) from Ratings")
df.show()
changeDate为函数名。