spark sql自定义udf
已有 1251 次阅读2017-8-21 13:08
|个人分类:spark
import org.apache.spark.sql.functions._
val convert = udf((str:String) =>
"1"
)
val df = hiveContext.sql("")
val df2 = hiveContext.sql("select 1 as time")
hiveContext.udf.register("convert",((str:String) =>
if(str.substring(5,7).toInt>=1 && str.substring(5,7).toInt<=3) "1"
))
df.withColumn("",df2("time").substr(1,2))
.withColumn("",convert(df2("")))