有什么方法可以在 sparksql 中实现存储过程或函数等 sql 功能?
我知道 hbase 中的 hpl sql 和协处理器。但是想知道 spark 中是否有类似的东西。
最佳答案
您可以考虑使用User Defined Function和内置功能
一个简单的例子
val dataset = Seq((0, "hello"), (1, "world")).toDF("id", "text")
val upper: String => String = _.toUpperCase
import org.apache.spark.sql.functions.udf
val upperUDF = udf(upper)
// Apply the UDF to change the source dataset
scala> dataset.withColumn("upper", upperUDF('text)).show
结果
| id| text|upper|
+---+-----+-----+
| 0|hello|HELLO|
| 1|world|WORLD|
关于hadoop - SparkSql 中的存储过程/函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42931954/