Hive基本操作

hive的基本使用

新建表

创建数据(文本以tab分隔)
~ vi /home/cos/demo/t_hive.txt

16 2 3
61 12 13
41 2 31
17 21 3
71 2 31
1 12 34
11 2 34

创建新表
hive> CREATE TABLE t_hive (a int, b int, c int) ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t’;

导入数据t_hive.txt到t_hive表
hive> LOAD DATA LOCAL INPATH ‘/home/cos/demo/t_hive.txt’ OVERWRITE INTO TABLE t_hive ;

查看表和数据

查看表
hive> show tables;

正则匹配表名
hive>show tables ‘t‘;

查看表数据
hive> select * from t_hive;

查看表结构
hive> desc t_hive;

修改表

增加一个字段
hive> ALTER TABLE t_hive ADD COLUMNS (new_col String);

hive> desc t_hive;
OK
a int
b int
c int
new_col string
Time taken: 0.086 seconds

重命令表名
hive>ALTER TABLE t_hive RENAME TO t_hadoop;
OK
Time taken: 0.45 seconds
hive> show tables;
OK
t_hadoop
Time taken: 0.07 seconds

删除表

hive> DROP TABLE t_hadoop;

数据导入

创建表结构
hive> CREATE TABLE t_hive (a int, b int, c int) ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t’;

从操作本地文件系统加载数据(LOCAL)
hive> LOAD DATA LOCAL INPATH ‘/home/cos/demo/t_hive.txt’ OVERWRITE INTO TABLE t_hive ;

创建表t_hive2
hive> CREATE TABLE t_hive2 (a int, b int, c int) ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t’;

从HDFS加载数据
hive> LOAD DATA INPATH ‘/user/hive/warehouse/t_hive/t_hive.txt’ OVERWRITE INTO TABLE t_hive2;

从其他表导入数据
hive> INSERT OVERWRITE TABLE t_hive2 SELECT * FROM t_hive ;

创建表并从其他表导入数据
hive> CREATE TABLE t_hive AS SELECT * FROM t_hive2 ;

仅复制表结构不导数据
hive> CREATE TABLE t_hive3 LIKE t_hive;

数据导出

通过Hive导出到本地文件系统
hive> INSERT OVERWRITE LOCAL DIRECTORY ‘/tmp/t_hive’ SELECT * FROM t_hive;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值