You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Sa...@wellsfargo.com on 2015/09/14 18:39:29 UTC
Where can I learn how to write udf?
Hi all,
I am failing to find a proper guide or tutorial onto how to write proper udf functions in scala.
Appreciate the effort saving,
Saif
Re: Where can I learn how to write udf?
Posted by Silvio Fiorito <si...@granturing.com>.
Hi Saif,
There are 2 types of UDFs. Those used by SQL and those used by the Scala DSL.
For SQL, you just register a function like so (this example is from the docs):
sqlContext.udf.register(“strLen”, (s: String) => s.length)
sqlContext.sql(“select name, strLen(name) from people”).show
The other method, for Scala DSL, instead:
import org.apache.spark.sql.functions._
def strLen = udf { (s: String) => s.length }
people.select(people(“name”), strLen(people(“name”))).show
Thanks,
Silvio
From: "Saif.A.Ellafi@wellsfargo.com<ma...@wellsfargo.com>"
Date: Monday, September 14, 2015 at 12:39 PM
To: "user@spark.apache.org<ma...@spark.apache.org>"
Subject: Where can I learn how to write udf?
Hi all,
I am failing to find a proper guide or tutorial onto how to write proper udf functions in scala.
Appreciate the effort saving,
Saif