Hive command常用

本文详细介绍了Hive的各种命令用法,包括数据查询、表操作、数据加载和脚本执行等。同时,展示了如何在Hive客户端进行交互式shell命令,如添加列、更改列类型和重命名表等。此外,还提到了Hive的静默模式和结果输出到文件的设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

hive 相关命令使用:

  1. hive -S -e "select * from table_name limit 10" > /tmp/myquery
    1. -S 开启静默模式,将结果输出到文件
  2. show create table table_name;
  3. CREATE TABLE table_name(`id` string, ...) STORED AS orc;
  4. hive -f insert.sql (执行sql脚本)
  5. row format delimited fields terminated by '\001' collection items terminated by '\002' map keys terminated by '\003' lines terminated by '\n' stored as textfile;
  6. LOAD DATA LOCAL INPATH '/root/chenc/data/usrGSPPBZ.txt' INTO TABLE usrGSPPBZ;
  7. hive -e 'set hive.execution.engine=tez; set hive.cli.print.header=true; set hive.resultset.use.unique.column.names=false; select xwbt, xwnr from jyqyqb.usrzxzb limit 100' | sed 's/,/,/g' | sed 's/\t/,/g' > ./bydata.csv
  8. hive -e "set hive.execution.engine=mr; set hive.cli.print.header=true; set hive.resultset.use.unique.column.names=false; select rowkey, id, xxfbrq, xxfbsj, mtcc, mtcccl, xwly, xwlymc, lmfl, mtlm, xwbt, xwfbt, xwzy, substr(xwnr,1,20000) xwnr, zxzz, zxjg, zxjgbh, bmh, bmxx, ljdz, xwnrhc, xxjb, sjybm, sjybmmc, qgzfm, zzs, hfs, djs, gkbz, xgry, xgry2, xgsj, fbsj, shry, jsid, host, msgsourceurl, msgtype, msgsubtype, substr(contentimglinks,1,5000) contentimglinks, contentimglinkslocations, sector, infotype, infoflag from jyqyqb.usrzxzb where fbsj like '2018-12-04%'" | sed 's/,/,/g' | sed 's/\t/,/g' > ./bydata.csv

hive client:

hive --help / hive -H

hive -e 'select a.col from db1.tab1 a'

hive -S -e 'select a.col from db1.tab1 a' > a.txt (-S 静默模式)

hive -f /home/my/hive-script.sql

hive -f hdfs://<namenode>:<port>/hive-script.sql

hive interactive shell commands:

ALTER TABLE table_name ADD COLUMNS (new_col INT);

ALTER TABLE usrzxzb CHANGE id id string;

ALTER TABLE usrzxzb ADD COLUMNS (zxdl int);

ALTER TABLE name DROP [COLUMN] column_name

ALTER TABLE name CHANGE column_name new_name new_type;

ALTER TABLE events RENAME TO 3koobecaf;

INSERT INTO table_name SELECT * FROM ...;

INSERT OVERWRITE TABLE table_name SELECT * FROM ...;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mylife512

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值