赞
踩
package inpv
import org.apache.spark.Partitioner
class PvPartitioner(numParts: Int) extends Partitioner {
override def numPartitions: Int = numParts
override def getPartition(key: Any): Int = {
val code = (key.toString().hashCode % numPartitions)
if (code < 0) {
code + numPartitions
} else {
code
}
}
override def equals(other: Any): Boolean = other match {
case p: PvPartitioner =>
p.numPartitions == numPartitions
case _ =>
false
}
override def hashCode: Int = numPartitions
}

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。