Hive配置和基本操作.doc_第1页
Hive配置和基本操作.doc_第2页
Hive配置和基本操作.doc_第3页
Hive配置和基本操作.doc_第4页
Hive配置和基本操作.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验报告(四)大数据存储实验报告实验名称:Hive操作姓名/学号:日期:实验环境:操作系统:LinuxHadoop版本:2.x版本HBase版本:1.1.1或以上Zookeeper版本:3.4.6或以上JDK版本:1.6或以上版本Java IDE:EclipseHIVE版本:实验内容与完成情况:一:Hive的配置hive的安装十分简单,只需要在一台服务器上部署即可。上传hive安装包,解压缩,将其配入环境变量。解压Hive的Jar包后,进入conf目录,修改配置文件:cp hive-env.sh.template hive-env.shcp hive-default.xml.template hive-default.xmlcp perties.template pertiescp perties.template perties在hive-env.sh文件中配置hadoop的home目录。新建一个hive-site.xml文件并增加内容hive.exec.local.scratchdir/usr/local/hive/iotmphive.exec.scratchdir/tmp/hivehive.server2.logging.operation.log.location/usr/local/hive/iotmphive.downloaded.resources.dir/usr/local/hive/iotmphive.querylog.location/usr/local/hive/iotmphive.metastore.warehouse.dir/user/hive/warehousejavax.jdo.option.ConnectionDriverNamecom.mysql.jdbc.Driverjavax.jdo.option.ConnectionURLjdbc:mysql:/localhost:3306/hive?characterEncoding=UTF-8javax.jdo.option.ConnectionUserNamehivejavax.jdo.option.ConnectionPasswordhivehive.metastore.localfalsehive.metastore.uristhrift:/localhost:9083二:Hive的基本操作创建表:hive CREATE TABLE pokes (foo INT, bar STRING); Creates a table called pokes with two columns, the first being an integer and the other a string创建一个新表,结构与其他一样hive create table new_table like records;创建分区表:hive create table logs(ts bigint,line string) partitioned by (dt String,country String);加载分区表数据:hive load data local inpath /home/hadoop/input/hive/partitions/file1 into table logs partition (dt=2001-01-01,country=GB);展示表中有多少分区:hive show partitions logs;展示所有表:hive SHOW TABLES; lists all the tableshive SHOW TABLES .*s;lists all the table that end with s. The pattern matching follows Java regularexpressions. Check out this link for documentation显示表的结构信息hive DESCRIBE invites; shows the list of columns更新表的名称:hive ALTER TABLE source RENAME TO target;添加新一列hive ALTER TABLE invites ADD COLUMNS (new_col2 INT COMMENT a comment);删除表:hive DROP TABLE records;删除表中数据,但要保持表的结构定义hive dfs -rmr /user/hive/warehouse/records;从本地文件加载数据:hive LOAD DATA LOCAL INPATH /home/hadoop/input/ncdc/micro-tab/sample.txt OVERWRITE INTO TABLE records;显示所有函数:hive show functions;查看函数用法:hive describe function substr;查看数组、map、结构hive select col10,col2b,col3.c from complex;内连接:hive SELECT sales.*, things.* FROM sales JOIN things ON (sales.id = things.id);查看hive为某个查询使用多少个MapReduce作业hive Explain SELECT sales.*, things.* FROM sales JOIN things ON (sales.id = things.id);外连接:hive SELECT sales.*, things.* FROM sales LEFT OUTER JOIN things ON (sales.id = things.id);hive SELECT sales.*, things.* FROM sales RIGHT OUTER JOIN things ON (sales.id = things.id);hive SELECT sales.*, things.* FROM sales FULL OUTER JOIN things ON (sales.id = things.id);in查询:Hive不支持,但可以使用LEFT SEMI JOINhive SELECT * FROM things LEFT SEMI JOIN sales ON (sales.id = things.id);Map连接:Hive可以把较小的表放入每个Mapper的内存来执行连接操作hive SELECT /*+ MAPJOIN(things) */ sales.*, things.* FROM sales JOIN things ON (sales.id = things.id);INSERT OVERWRITE TABLE .SELECT:新表预先存在hive FROM records2 INSERT OVERWRITE TABLE stations_by_year SELECT year, COUNT(DISTINCT station) GROUP BY year INSERT OVERWRITE TABLE records_by_year SELECT year, COUNT(1) GROUP BY year INSERT OVERWRITE TABLE good_records_by_year SELECT year, COUNT(1) WHERE temperature != 9999 AND (quality = 0 OR quality = 1 OR quality = 4 OR quality = 5 OR quality = 9) GROUP BY year;CREATE TABLE . AS SELECT:新表表预先不存在hiveCREATE TABLE target AS SELECT col1,col2

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论