示例
// Define and register a one-argument UDF
val plusOne = udf((x: Int) => x + 1)
spark.udf.register("plusOne", plusOne)
spark.sql("SELECT plusOne(5)").show()
// +------+
// |UDF(5)|
// +------+
// | 6|
// +------+
SQL 语句注册 UDF
drop 函数
spark.sql("Drop FUNCTION IF EXISTS IP2Region");
创建临时函数
CREATE TEMPORARY FUNCTION IP2Region AS 'xxx.udf.IP2RegionSparkUDF'
SHOW USER FUNCTIONS;
select IP2Region("1.192.45.132", 1);
创建永久函数
CREATE FUNCTION IP2Region AS 'xxx.udf.IP2RegionSparkUDF'
在数据库层面上创建永久函数
CREATE FUNCTION default.IP2Region AS 'xxx.udf.IP2RegionSparkUDF';
select default.IP2Region("1.192.45.132", 1);