spark 自定义partitioner

    xiaoxiao2021-03-25  111

    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 }
    转载请注明原文地址: https://ju.6miu.com/read-23484.html

    最新回复(0)