简体   繁体   中英

How to call Groovy or Scala UDF to update Oracle, using Java?

I have a JDBC connection to an Oracle DB. I also have some function f(x) written in Groovy or Scala. For example, f(x) simply returns 2x.

Now my question is: how should I call this f(x) in my Java code, to apply f(x) to all values in a column, and update this column to 2x in the above example?

You can use withColumn api to update the column's values.

If your function is returning a constant lit should be a good choice. You can find a lot of functions too.

You can use udf function too as

def func = udf((column: Int)=> 2*column)
dataframe.withColumn("column1", func(dataframe("column1")))

but udf function would need serialization and deserialization column values. So if other functions should be preferred.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM