You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Xuelin Cao <xu...@yahoo.com.INVALID> on 2014/12/15 10:27:40 UTC
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?
RE: Why my SQL UDF cannot be registered?
Posted by "Cheng, Hao" <ha...@intel.com>.
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:xuelincao@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?