Commit 618784a6 authored by 黄贵华's avatar 黄贵华

StringUnionUDF

parent 2458ea52
...@@ -39,7 +39,7 @@ dependencies { ...@@ -39,7 +39,7 @@ dependencies {
// compileOnly('org.apache.hive:hive-exec:1.1.0-cdh5.14.0') // compileOnly('org.apache.hive:hive-exec:1.1.0-cdh5.14.0')
// compile group: 'org.apache.hive', name: 'hive-exec', version: '1.1.0' // compile group: 'org.apache.hive', name: 'hive-exec', version: '1.1.0'
compileOnly('org.apache.hive:hive-exec:1.1.0') compileOnly('org.apache.hive:hive-exec:1.1.0')
// compile group: 'cz.mallat.uasparser', name: 'uasparser', version: '0.6.2' compile group: 'cz.mallat.uasparser', name: 'uasparser', version: '0.6.2'
compile group: 'nl.basjes.parse.useragent', name: 'yauaa', version: '5.21' compile group: 'nl.basjes.parse.useragent', name: 'yauaa', version: '5.21'
} }
......
package cn.com.duiba.udf;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hive.ql.exec.UDF;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* 字符串求差值
*/
public class StringUnionUDF extends UDF{
public String evaluate(String stra, String strb, String delimiter) {
if (StringUtils.isBlank(stra)) {
return strb;
}
if (StringUtils.isBlank(strb)) {
return stra;
}
if (StringUtils.isBlank(delimiter)) {
return null;
}
List<String> listA = Lists.newArrayList(StringUtils.split(stra, delimiter));
List<String> listB = Lists.newArrayList(StringUtils.split(strb, delimiter));
Set<String> set = new HashSet<>();
//用set的特性去做
set.addAll(listA);
set.addAll(listB);
return StringUtils.join(set, delimiter);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment