As the error log shows, you may need to register it as: sqlContext.rgisterFunction(“toHour”, toHour _)
The “_” means you are passing the function as parameter, not invoking it. Cheng Hao From: Xuelin Cao [mailto:xuelin...@yahoo.com.INVALID] Sent: Monday, December 15, 2014 5:28 PM To: User Subject: Why my SQL UDF cannot be registered? Hi, I tried to create a function that to convert an Unix time stamp to the hour number in a day. It works if the code is like this: sqlContext.registerFunction("toHour", (x:Long)=>{new java.util.Date(x*1000).getHours}) But, if I do it like this, it doesn't work: def toHour (x:Long) = {new java.util.Date(x*1000).getHours} sqlContext.registerFunction("toHour", toHour) The system reports an error: <console>:23: error: missing arguments for method toHour; follow this method with `_' if you want to treat it as a partially applied function sqlContext.registerFunction("toHour", toHour) Anyone can help on dealing with this error?