大华的Hive技术文档
。。。。。
如何在Linux上安装并配置Hive
##############
# HIVE 3.1.2 #
##############
# 1、解压并重命名
cd /opt/download
tar -zxvf apache-hive-3.1.2-bin.tar.gz -C /opt/software/
mv /opt/software/apache-hive-3.1.2-bin/ /opt/software/hive312
cd /opt/software/hive312
# 2、环境变量并激活
vim /etc/profile.d/my.sh
#-----------------------------------------
# hive
export HIVE_HOME=/opt/software/hive312
export PATH=$PATH:$HIVE_HOME/bin
#-----------------------------------------:
source /etc/profile
# 3、配置文件
mv conf/hive-default.xml.template conf/hive-default.xml
vim conf/hive-site.xml
#-----------------------------------------
<configuration>
<!--hdfs仓库路径-->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/hive312/warehouse</value>
</property>
<!--metastore(元)数据库类型-->
<property>
<name>hive.metastore.db.type</name>
<value>mysql</value>
<description>Expects one of [derby, oracle, mysql, mssql, postgres].</description>
</property>
<!--连接mysql字符串-->
<property>
<name>javax.jdo.option.ConnectionURL</name>mysql
<value>jdbc:mysql://192.168.71.128:3306/hive312?createDatabaseIfNotExist=true</value>
</property>
<!--mysql连接驱动-->
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<!--mysql连接账号-->
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<!--mysql本地连接密码-->
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>kb16</value>
</property>
<!--关闭schema验证-->
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
</property>
<!--提示当前库名-->
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
<description>Whether to include the current database in the Hive prompt.</description>
</property>
<!--查询输出显示列名-->
<property>
<name>hive.cli.print.header</name>
<value>true</value>
<description>Whether to print the names of the columns in query output.</description>
</property>
</configuration>
#-----------------------------------------
${hive.exec.scratchdir} =DEFAULT=> /tmp/hive
is still used for other temporary files, such as job plans
#4、拷贝mysql驱动
cp /opt/download/mysql-connector-java-5.1.47.jar /opt/software/hive312/lib/
#5、更新guava包和hadoop一致
ls lib/|grep guava
# guava-19.0.jar
rm -f lib/guava-19.0.jar
find /opt/software/hadoop313/ -name guava*
#/opt/software/hadoop313/share/hadoop/common/lib/guava-27.0-jre.jar
#/opt/software/hadoop313/share/hadoop/hdfs/lib/guava-27.0-jre.jar
cp /opt/software/hadoop313/share/hadoop/hdfs/lib/guava-27.0-jre.jar lib/
#6、mysql授权
grant all on *.* to root@master01 identified by 'kb16';
flush privileges;
#7、初始化
bin目录下
schematool -dbType mysql -initSchema
s
#8、hive启动模式
#首先启动元数据服务
nohup hive --service metastore 1>/dev/null 2>&1 &
#1、方法一 hive客户端
hive
#2、方法二 基于metastore和hiveserver2的beeline
#启动hiveserver2服务
nohup hive --service hiveserver2 1>/dev/null 2>&1 &
beeline -u jdbc:hive2://localhost:10000
如何在hive中实现对手机号的加密
public class EncrypPhoneNumber extend UDF{
public String evaluate(String phoNum){
String encrypPhoneNum=null;
//判断手机号不为空,并且为11位
if(StringUtils.isNotEmpty(phoNum))&&phoNum.trim.length()==11{
//判断数据满足中国大陆手机号码规范
String regex ="^(1[3-9]\\d{9}$)";
Pattern p=Pattern.compile(regex);
Matcher m=p.matcher(phoNum);
if(m.matcher()){//进入这里的都是符合手机号规则的
//使用正则替换,返回加密后的数据
encrypPhoneNum=phoNum.trim().replaceAll("(\\d{3}\\d{4}(\\d{4})","$1****$2");
}else{
//不符合手机号规则,数据直接原封不动返回
encrypPhoneNum=phoNum;
}
}else{
//不符合11位,数据直接原封不动返回
encrypPhoneNum=phoNum;
}
return encrypPhoneNum;
}
}
//建一个maven工程,贴两个依赖
//粘到IDEA里打jar包,拖到moba里(位置任意)
//用虚拟机执行: add jar /root/hive-udf-1.0-SNAPSHOT.jar;(这个路径 要写对)
//注册成为临时函数,给UDF函数命名,格式为:create temporary function 函数名 as 'UDF类全路径';
//我改为create temporary encrypt_phoNum as '粘->类的copy reference';
//使用这个函数,如select encrypt_phoNum(); 括号里输你的参数