代码如下
package TEST
import org.apache.spark.sql.expressions.UserDefinedFunction
import org.apache.spark.sql.functions._
object Test5 {
def main(args: Array[String]): Unit = {
val xgsFunction1: UserDefinedFunction = udf[Long,String](xgs)
val xgsFunction2: UserDefinedFunction = udf((str: String) => {
val str2: Array[String] = str.split(":")
val d: Double = (str2(0).toDouble * 3600L) + (str2(1).toDouble * 60L) + str2(2).toDouble
math.round(d / 300L)
})
}
def xgs(str: String):Long={
val str2: Array[String] = str.split(":")
val d: Double = (str2(0).toDouble * 3600L) + (str2(1).toDouble * 60L) + str2(2).toDouble
math.round(d / 300L)
}
}
|