标签:
一. Hive安装
Hive只在一个节点上安装即可
1. 上传tar包3.1 配置HIVE_HOME环境变量
3.2 安装mysql
查询以前安装的mysql相关包: rpm -qa | grep mysql添加如下内容:
<property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://hadoop00:3306/hive?createDatabaseIfNotExist=true</value> <description>JDBC connect string for a JDBC metastore</description> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> <description>Driver class name for a JDBC metastore</description> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>root</value> <description>username to use against metastore database</description> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>123</value> <description>password to use against metastore database</description> </property>
建分区表:
create table td_part(id bigint, account string, income double, expenses double, time string) partitioned by (logdate string) row format delimited fields terminated by ‘\t‘;
建外部表:
create external table td_ext(id bigint, account string, income double, expenses double, time string) row format delimited fields terminated by ‘\t‘ location ‘/td_ext‘;select nation, avg(size) from beauties group by nation order by avg(size);
二. UDF
自定义UDF要继承org.apache.hadoop.hive.ql.exec.UDF类实现evaluate
public class AreaUDF extends UDF{ private static Map<Integer, String> areaMap = new HashMap<Integer, String>(); static { areaMap.put(1, "北京"); areaMap.put(2, "上海"); areaMap.put(3, "广州"); } public Text evaluate(Text in){ String result = areaMap.get(Integer.parseInt(in.toString())); if(result == null){ result = "其他"; } return new Text(result); } }
标签:
原文地址:http://blog.csdn.net/zdp072/article/details/42197905