1.下载 [url]http://labs.renren.com/apache-mirror/hive/stable/hive-0.8.1.tar.gz[/url]
2.安装
安装hive之前确保已经安装了hadoop,hadoop简单安装请查看[url] http://alikevin2011.iteye.com/blog/1534712[/url]
[code="java"]
# tar -zxvf hive-0.8.1.tar.gz
[/code]
配置HIVE_HOME
[code="java"]
# vi /etc/profile
..
export HIVE_HOME=/home/kevin/work/hive
export HADOOP_HOME=/home/kevin/work/hadoop
export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$ANTX_HOME/bin:$HIVE_HOME/bin:$HADOOP_HOME/bin:$PAT
...
[/code]
配置文件生效
[code="java"]
# source /etc/profile
[/code]
3.进入hive的shell
[code="java"]
# bin/hive
Logging initialized using configuration in jar:file:/home/kevin/work/hive/lib/hive-common-0.8.1.jar!/hive-log4j.properties
Hive history file=/tmp/root/hive_job_log_root_201206061019_1215788833.txt
hive>
[/code]
4.创建简单表
[code="java"]
# su - work
[work@inc-platform-dev-145-5 ~]$ /home/kevin/work/hive/bin/hive
Logging initialized using configuration in jar:file:/home/kevin/work/hive/lib/hive-common-0.8.1.jar!/hive-log4j.properties
Hive history file=/tmp/work/hive_job_log_work_201206061022_606817436.txt
hive> CREATE TABLE pokes (foo INT, bar STRING);
OK
Time taken: 11.116 seconds
[/code]
5.创建带有分区的表
6.显示所有表
7.显示表结构
8.修改表结构
9.删除表结构
10.由文件加载数据到表中
数据文件片段examples/files/kv1.txt
加载到pokes表
2.安装
安装hive之前确保已经安装了hadoop,hadoop简单安装请查看[url] http://alikevin2011.iteye.com/blog/1534712[/url]
[code="java"]
# tar -zxvf hive-0.8.1.tar.gz
[/code]
配置HIVE_HOME
[code="java"]
# vi /etc/profile
..
export HIVE_HOME=/home/kevin/work/hive
export HADOOP_HOME=/home/kevin/work/hadoop
export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$ANTX_HOME/bin:$HIVE_HOME/bin:$HADOOP_HOME/bin:$PAT
...
[/code]
配置文件生效
[code="java"]
# source /etc/profile
[/code]
3.进入hive的shell
[code="java"]
# bin/hive
Logging initialized using configuration in jar:file:/home/kevin/work/hive/lib/hive-common-0.8.1.jar!/hive-log4j.properties
Hive history file=/tmp/root/hive_job_log_root_201206061019_1215788833.txt
hive>
[/code]
4.创建简单表
[code="java"]
# su - work
[work@inc-platform-dev-145-5 ~]$ /home/kevin/work/hive/bin/hive
Logging initialized using configuration in jar:file:/home/kevin/work/hive/lib/hive-common-0.8.1.jar!/hive-log4j.properties
Hive history file=/tmp/work/hive_job_log_work_201206061022_606817436.txt
hive> CREATE TABLE pokes (foo INT, bar STRING);
OK
Time taken: 11.116 seconds
[/code]
5.创建带有分区的表
hive> CREATE TABLE invites (foo INT, bar STRING) PARTITIONED BY (ds STRING);
OK
Time taken: 0.05 seconds
6.显示所有表
hive> SHOW TABLES;
OK
invites
pokes
Time taken: 0.099 seconds
hive> SHOW TABLES '.*s';
OK
invites
pokes
Time taken: 0.044 seconds
7.显示表结构
hive> DESCRIBE invites;
OK
foo int
bar string
ds string
Time taken: 0.131 seconds
8.修改表结构
hive> ALTER TABLE pokes ADD COLUMNS (new_col INT);
OK
Time taken: 4.712 seconds
hive> ALTER TABLE invites ADD COLUMNS (new_col2 INT COMMENT 'a comment');
OK
Time taken: 0.112 seconds
hive> ALTER TABLE events RENAME TO 3koobecaf;
9.删除表结构
hive> show tables;
OK
invites
pokes
Time taken: 0.101 seconds
hive> DROP TABLE pokes;
OK
Time taken: 3.353 seconds
hive> show tables;
OK
invites
Time taken: 0.069 seconds
hive>
10.由文件加载数据到表中
数据文件片段examples/files/kv1.txt
...
86val_86
311val_311
27val_27
165val_165
409val_409
255val_255
278val_278
98val_98
484val_484
265val_265
193val_193
401val_401
150val_150
273val_273
224val_224
369val_369
66val_66
...
加载到pokes表