DataFrame中支持的类型如 Struct此类型我们是用对象进行的封装,但是要对strcut里的数据进行排序,个人想到的办法还是把struct转位Json,然后反解析Json
sqlcontext.udf.register("stuSort", (stuList: Seq[String]) => { val rs = Option(conponList) match { case None => "" case Some(c) => { val couponInfoList = ArrayBuffer[CouponInfo]() conponList.foreach(x => { couponInfoList.append(readAsBeanByJson4s[CouponInfo](x)) })
//基于Ordering的隐式参数 implicit object CouponOrdering extends Ordering[CouponInfo] { override def compare(s1: CouponInfo, s2: CouponInfo): Int = { if (s1.coupon_bank == s2.coupon_bank) if (s1.coupon_list == s2.coupon_list) s1.coupon_st.compareTo(s2.coupon_st) else s1.coupon_list.compareTo(s2.coupon_list) else s1.coupon_bank.compareTo(s2.coupon_bank) } } couponInfoList.sorted.mkString(",") } } rs.toString })