1.UDF user define function ,用户自定义函数
//current_database(),current_user();
2.显示所有函数
$hive>show functions ;
3.表生成函数
$hive>explode(str,exp); //按照exp来切割str
$hive>select explode(array(1,2,3));
4.显示指定函数帮助:
$hive>describe function split;
$hive>desc function current_databases ;
1.创建类,继承 2.打成jar包到hive的类路径:hive/lib目录的下面 //添加jar到类路径 $hive>add jar /mnt/hgfs/downloads/bigdata/data/HiveDemo-1.0-SNAPSHOT.jar /soft/hive/lib 3.创建临时函数 create temporary function add as ‘com.it18zhang.hiveDemo.udf.addudf‘; 4.在查询中使用自定义函数 $hive>select myadd(1,2); 5.在查询中自定义函数 $hive>select add(1,2); 6.定义日期函数 1)定义 package com.itheim.hivedemo.test;
import org.junit.Test;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
- Created by Administrator
on 2018/7/9 0009.
*/
public class Test3 {
@Test
public void test1(){
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyy/mm/dd HH:mm:ss");
System.out.println(sdf.format(date));
}
public String test2(Date date){
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyy/mm/dd HH:mm:ss");
return sdf.format(date);
}
public String test3(Date date,String frt){
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern(frt);
return sdf.format(date);
}
}
2)导出jar包,通过命令添加到hive的路径(不需要重进hive)
$hive>add jar /mnt/hgfs/downloads/bigdata/data/HiveDemo-1.0-SNAPSHOT.jar3)注册函数
$hive>create temporary function to_char as ‘com.it18zhang.hiveDemo.ToCharUDF‘;
1):自定义分区,再开一个mr进行二次计算 2):
$hive>set hive.optimize.skewjoin=true;//设置一个倾斜连接打开 $hive>set hive.skewjoin.key=100000; $hive>set hive.groupby.skewindata=true;
原文:https://www.cnblogs.com/stone-learning/p/9284929.html