Hive命令行参数

$HIVE_HOME/bin/hive是一个shell工具,它可以用来运行于交互或批处理方式配置单元查询。

语法:

Usage: hive [-hiveconf x=y]*[<-i filename>]* [<-ffilename>|<-equery-string>] [-S]

-i<filename>: Initialization Sql fromfile (executed automatically and silently before any othercommands)

-e 'quoted querystring': 运行引号内sql查询语句 Sql from command line

-f<filename>: 从文件中运行sql语句 Sqlfrom file

-S: Silent mode in interactive shellwhere only data is emitted

-hiveconf x=y: Use this to sethive/hadoop configuration variables.

-e 与 -f 不能同时使用。In the absence ofthese options, interactive shell is started. 但是,-i 能够与任意参数同时使用。多个–i 的实例可以用来执行多个初始化脚本scripts。However, -i can be used with any otheroptions. Multiple instances of -i can be used to execute multipleinit scripts.

通过命令:hive –h 可以查看应用的帮助文档.To see thisusage help, run hive -h

运行一个查询:

$HIVE_HOME/bin/ hive -e 'selectcount(*) from c02_clickstat_fatdt1'

Example of setting hive configurationvariables

$HIVE_HOME/bin/hive -e 'select a.colfrom tab1 a' -hiveconfhive.exec.scratchdir=/home/my/hive_scratch -hiveconfmapred.reduce.tasks=32

将查询结果导出到一个文件

HIVE_HOME/bin/hive -S -e 'select count(*) from c02_clickstat_fatdt1' >a.txt

运行一个脚本

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

Example of running an initializationscript before entering interactive mode

HIVE_HOME/bin/hive -i/home/my/hive-init.sql


hive使用 ^A 符号作为域的分隔符
在python中可以使用line.split('\x01')来进行切分

如果不用命令行形式,用insert overwrite local directory ‘path’ select *

则用命令 sed -e 's/\x01/\t/g'  file  自定义分隔符来替换hive默认分隔符


echo "abc  23" | sed 's/[ ]\{2,\}/ /'  把多个空格替换成一个空格


在python中可以使用line.split('\x01')来进行切分

如果确实需要将查询结果导出到本地文件,最好使用hive的命令:

  1. bin/hive -e "select * from test" >> res.csv  
  2.   
  3. 或者是:  
  4.   
  5. bin/hive -f sql.q >> res.csv  
  6.   
  7. 其中文件sql.q写入你想要执行的查询语句  

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值