0

How can I use a UDF which works great in spark like

sparkSession.sql("select * from chicago where st_contains(st_makeBBOX(0.0, 0.0, 90.0, 90.0), geom)").show

taken from from http://www.geomesa.org/documentation/user/spark/sparksql.html via spark`s more typesafe scala dataframe API?

0

2 Answers 2

1

If you have created a function, you can register the created UDF using:

sparksession.sqlContext.udf.register(yourFunction)

I hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

0

Oliviervs I think he's looking for something different. I think Georg wants to use the udf by string in the select api of the dataframe. For example:

val squared = (s: Long) => {
  s * s
}
spark.udf.register("square", squared)

df.select(getUdf("square", col("num")).as("newColumn")) // something like this

Question in hand is if there exists a function called getUdf that could be utilized to retrieve a udf registered via string. Georg, Is that right?

1 Comment

;) actually I have a library (geospark) and that registers some functions, but discards / does not store the references returned by sparksession.sqlContext.udf.register and I wonder how to get them back, i.e. to not have to rely on random strings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.