Hive 常用命令和语句

1、 创建表 create-table.sql

create table if not exists db_hive.tb_user
(
    id int,
    username string comment '用户名',
    age int comment '年龄',
    address string comment '地址'
)
comment '用户表'
row format delimited fields terminated by ',' 
stored as textfile
location '/user/hive/warehouse/db_hive.db/db_user'

2、执行创建表

hive -f 'create-table.sql'

3、加载数据到 tb_user 表中

数据文件  /root/files/tb_user.txt

1001,Logan,16,shenzhen
1002,Herry potter,12,Magic school
1003,孙悟空,500,花果山

Hive交互式命令行执行命令  load data local inpath '/root/files/tb_user.txt' into table db_hive.tb_user;

如下所示:

hive (db_hive)> load data local inpath '/root/files/tb_user.txt' into table db_hive.tb_user;

4、查询数据

hive -e "select id,username from db_hive.tb_user"

5、根据已有表创建只有部分字段的子表

create table if not exists db_hive.tb_user_sub 
as 
select id,username from db_hive.tb_user;

6、

7、

 待续。。。

.

猜你喜欢

转载自www.cnblogs.com/jonban/p/10779938.html
今日推荐