Hive常用命令

始发与:https://kongdada.github.io/

Hive常见命令
  • 显示所有数据库
    show databases;
  • 指定使用某个数据库
    use database_name;
  • 显示所有表
    show tables;
  • 查询表结构
    desc table_name;
  • 显示表的详细信息
    describe extended table_name;
  • 显示分区信息
    show partitions;
  • HIVEQL创建表
create table if not exists test_klh (
name string comment 'person name', 
age int comment 'person age',
sex string comment 'person sex'
)comment 'person'
row format delimited
# 列分隔符(字段)
fields terminated by '|'
# 行分隔符
lines terminated by '\n'
# 本地文件的格式
stored as textfile;
  • 表结构复制,不会复制数据
    create table if not exists test_klh2 like test_klh;
  • 加载数据(将本地数据加载到Hive表)
    load data local inpath '/kehuduan02/bonc_guanjianji/bonc_klh/test' overwrite[可省] into table test_klh;
  • 加载数据同时创建分区
    load data local inpath 'path/path' overwrite into table table_name partition (sex, age);
  • 导出数据
    insert overwrite local directory 'path' select * from table_name where **
  • 通过查询插入数据
    insert into/overwrite table test_klh select * from test_klh where name = "mike";
  • 单个查询语句中创建表并加载数据
    create table test_klh1 as select * from test_klh where name = "mike" ;
  • 删除表
    drop table if exitst table_name
  • case … when … then …

    select name, sex,
    case
    when test_klh.sex < 22 then 'younger'
    when test_klh.sex > 20 and test_klh.sex < 23 then 'mid'
    when test_klh.sex > 22 then 'bigger'
    else 'bingo'
    end as bracket from test_klh;

    上面这些学完真的就可以去练练手了。
两个很实用的命令

下面介绍;两个很实用的命令
- hive -e: 在 linux 命令行中执行 hive语句,其实就是用hive来解析hive -e 后面的语句。
[root@cloud1 hive-0.13.1]# bin/hive -e 'select * from default.student'
15/10/18 06:55:27 WARN conf.HiveConf: DEPRECATED: hive.metastore.ds.retry.* no longer has any effect. Use hive.hmshandler.retry.* instead
Logging initialized using configuration in jar:file:/opt/hive-0.13.1/lib/hive-common-0.13.1.jar!/hive-log4j.properties
OK
1 jhon
2 mike
3 jack
Time taken: 21.298 seconds, Fetched: 3 row(s)

- hive -f:在linux 命令行中执行 hive的.sql文件,其实就是用hive解析一个.sql 文件。
[root@cloud1 hive-0.13.1]# touch test.sql
[root@cloud1 hive-0.13.1]# vi test.sql
select * from default.student ;
[root@cloud1 hive-0.13.1]# hive -f /opt/hive-0.13.1/test.sql
15/10/18 07:00:12 WARN conf.HiveConf: DEPRECATED: hive.metastore.ds.retry.* no longer has any effect. Use hive.hmshandler.retry.* instead
Logging initialized using configuration in jar:file:/opt/hive-0.13.1/lib/hive-common-0.13.1.jar!/hive-log4j.properties
OK
1 jhon
2 mike
3 jack
Time taken: 13.048 seconds, Fetched: 3 row(s)

注意:我一般都把注释写在代码的上一行。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值