本文整理汇总了Scala中org.apache.spark.util.Utils类的典型用法代码示例。如果您正苦于以下问题:Scala Utils类的具体用法?Scala Utils怎么用?Scala Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Utils类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: HashAwarePartitioner
//设置package包名称以及导入依赖的类
package org.apache.spark.lineage
import org.apache.spark.Partitioner
import org.apache.spark.util.Utils
class HashAwarePartitioner(partitions: Int) extends Partitioner {
def numPartitions = partitions
def getPartition(key: Any): Int = Utils.nonNegativeMod(key.asInstanceOf[Int], numPartitions)
override def equals(other: Any): Boolean = other match {
case h: HashAwarePartitioner =>
h.numPartitions == numPartitions
case _ =>
false
}
}
示例2: reflect
//设置package包名称以及导入依赖的类
package org.apache.spark.sql.crossdata.utils
import org.apache.spark.util.Utils
import scala.reflect.ClassTag
import scala.util.control.NonFatal
def reflect[T, Arg1 <: AnyRef, Arg2 <: AnyRef](
className: String,
ctorArg1: Arg1,
ctorArg2: Arg2)(
implicit ctorArgTag1: ClassTag[Arg1],
ctorArgTag2: ClassTag[Arg2]): T = {
try {
val clazz = Utils.classForName(className)
val ctor = clazz.getDeclaredConstructor(ctorArgTag1.runtimeClass, ctorArgTag2.runtimeClass)
val args = Array[AnyRef](ctorArg1, ctorArg2)
ctor.newInstance(args: _*).asInstanceOf[T]
} catch {
case NonFatal(e) =>
throw new IllegalArgumentException(s"Error while instantiating '$className':", e)
}
}
}