Install hadoop, install hive, 及hive的使用

hadoop , hive 安装过程和配置文件(附件)。
注意:

hadoop Name Node未作ha.
Hive, 仍是基本的hive on MR, 未使用on tez, on spark,  未配置LLAP、 HCatalog and WebHCat

安装完以后,如下是hive使用例子:

 apache

从本地系统导入文件

 

LOAD DATA LOCAL INPATH '/tmp/student.csv' OVERWRITE  INTO TABLE student_csv

 

从hdfs文件中导入数据到表

 

LOAD DATA INPATH '/tmp/student.csv' OVERWRITE  INTO TABLE student_csv


 

1 create csv file.

 

student.csv

 

4,Rose,M,78,77,765,Mike,F,99,98,98


 

2 put it to hdfs.  (这一步非必须, hive也能够从本地文件系统中导放)

 

# hdfs dfs -put student.csv /input


 

3 create table in hive.

 

create table student_csv(sid int, sname string, gender string, language int, math int, english int)row format delimited fields terminated by ',' stored as textfile;

 

4 load hdfs file to hive.

 

load data inpath '/input/student.csv' into table student_csv;

 

5 verify.

 

hive> select * from student_csv;OK4 Rose M 78 77 765 Mike F 99 98 98



 

四、数据导入到SEQUENCEFILE

 

SequenceFile是Hadoop API提供的一种二进制文件支持,其具备使用方便、可分割、可压缩的特色。

 

SequenceFile支持三种压缩选择:NONE, RECORD, BLOCK。 Record压缩率低,通常建议使用BLOCK压缩。

 

示例:

 

create table test2(str STRING) STORED AS SEQUENCEFILE;

 

OK

 

Time taken: 5.526 seconds

 

hive> SET hive.exec.compress.output=true;

 

hive> SET io.seqfile.compression.type=BLOCK;

 

hive> INSERT OVERWRITE TABLE test2 SELECT * FROM test1;


 

INSERT OVERWRITE TABLE student_csv_orc SELECT * FROM student_csv;


 

把一个textfile 格式的表,转化成orc格式的表

 

hive>  INSERT OVERWRITE TABLE student_csv_orc SELECT * FROM student_csv;

 

执行命令的打印:

 

Query ID = hadoop_20180722122259_3a968951-7388-4f67-ba90-8ad47ffaa7d7

 

Total jobs = 1

 

Launching Job 1 out of 1

 

Number of reduce tasks determined at compile time: 1

 

In order to change the average load for a reducer (in bytes):

 

  set hive.exec.reducers.bytes.per.reducer=<number>

 

In order to limit the maximum number of reducers:

 

  set hive.exec.reducers.max=<number>

 

In order to set a constant number of reducers:

 

  set mapreduce.job.reduces=<number>

 

Starting Job = job_1532216763790_0001, Tracking URL = http://serv10.bigdata.com:8088/p ... 1532216763790_0001/

 

Kill Command = /opt/hadoop/bin/mapred job  -kill job_1532216763790_0001

 

Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 1



 

注意:

 

只有TEXTFILE表能直接加载数据,必须,本地load数据,和external外部表直接加载运路径数据,都只能用TEXTFILE表。  更深一步,hive默认支持的压缩文件(hadoop默认支持的压缩格式),也只能用TEXTFILE表直接读取。其余格式不行。能够经过TEXTFILE表加载后insert到其余表中。  换句话说,SequenceFile、RCFile表不能直接加载数据,数据要先导入到textfile表,再从textfile表经过insert select from 导入到SequenceFile,RCFile表。  SequenceFile、RCFile表的源文件不能直接查看,在hive中用select看。RCFile源文件能够用 hive --service rcfilecat /xxxxxxxxxxxxxxxxxxxxxxxxxxx/000000_0查看,可是格式不一样,很乱。  hive默认支持压缩文件格式参考 http://blog.csdn.net/longshenlmj/article/details/50550580


 

ORC格式

 

   ORC是RCfile的升级版,性能有大幅度提高,    并且数据能够压缩存储,压缩比和Lzo压缩差很少,比text文件压缩比能够达到70%的空间。并且读性能很是高,能够实现高效查询。    具体介绍 https://cwiki.apache.org/conflue ... /LanguageManual+ORC建表语句以下:  同时,将ORC的表中的NULL取值,由默认的\N改成'',
相关文章
相关标签/搜索