如皋做公司網(wǎng)站杭州關(guān)鍵詞優(yōu)化測試
實現(xiàn)一個hive udf,可以將Map中的某一個或者多個key去掉,這里要繼承GenericUDF 這個抽象類,然后Override evaluate這個函數(shù)即可,可以把執(zhí)行這個udf前初始化的一些內(nèi)容放在initialize方法內(nèi),比如參數(shù)的判斷,函數(shù)的返回值類型等等。
代碼寫好之后,可以用如下方法創(chuàng)建這個函數(shù):
add jar hive-udf-1.0-SNAPSHOT.jar;
create temporary function map_remove as 'com.xxx.hive.udf.MapRemove';
測試效果:
功能正常。
下面是關(guān)鍵代碼:
pom.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.xxx</groupId><artifactId>hive-udf</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><hive.version>2.3.5</hive.version></properties><dependencies><dependency>