Hive中UDF练习
1.截取请求地址
代码:
package hiveUDF;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
/**
*
* 从 "GET /course/view.php?id=27 HTTP/1.1" 中获取请求地址,即 /course/view.php?id=27
*
*/
public class TruncationRequestAdd extends UDF {
public Text evaluate(Text add) {
// 过滤
if (add == null) {
return null;
}
// 按照空格分割
String[] strings = add.toString().split(" ");
// 过滤分割后长度小于3的字符
if (strings.length < 3) {
return null;
}
// 设置返回的结果
Text result = new Text(strings[1]);
return result;
}
}
截取主地址
代码:
package hiveUDF;
i