//spark进行二次排序 先按第一列排,相等情况下按第二列排
class SecondarySortKey(val first:Int,val second:Int) extends Ordered[SecondarySortKey] with Serializable{
//必须重写compare
def compare(other:SecondarySortKey):Int ={
if(this.first - other.first != 0){
// 两种情况>0 <0
this.first - other.first
} else{
//三种情况 >0 =0 <0
this.second - other.second
}
}
}
//spark进行自定义排序
//先按第一列String类型进行排序,相同情况下按第二列Int类型进行排序
class DefineSortKey(val first:String,val second:Int) extends Ordered[DefineSortKey] with Serializable{
def compare(other:DefineSortKey):Int = {
if(this.first != other.first){
if(this.first > other.first) 1
else -1
} else{
this.second - other.second
}
}
}