将脚本的输出写入配置单元中的文件 [英] Write the output of a script to a file in hive

查看:117
本文介绍了将脚本的输出写入配置单元中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含5个查询集的脚本。我想执行该脚本并将输出写入文件。我应该从hive cli中给出哪些命令。
谢谢

解决方案

示例查询文件(3个查询):



ramisetty @ aspire:〜/ my_tmp $ cat queries.q

  show databases; --query1 
使用my_db; --query2
INSERT OVERWRITE LOCAL DIRECTORY'./outputLocalDir'--query3
select * from students where branch =ECE; --query3

运行HIVE

ramisetty @ aspire:〜/ my_tmp $ hive



配置单元(默认)> source ./queries .q;

   - 控制台Q1的输出----- 

花费的时间:7.689秒

- 控制台Q2的输出-----

花费的时间:1.689秒
____________________________________________________________
Total MapReduce jobs = 1
启动Job 1中的1
由于没有reduce操作符,因此reduce任务的数量设置为0
Starting Job = job_201401251835_0004,跟踪URL = http:// localhost:50030 / jobdetails.jsp?jobid = job_201401251835_0004
Kill Command = /home/ramisetty/VJDATA/hadoop-1.0.4/libexec/../bin/hadoop job -kill job_201401251835_0004
Stage-1的Hadoop作业信息:mappers的数量:1;第一阶段地图= 0%,减少= 0%
2014-01-25 19:06:56,689阶段1地图= 0%,减少= 0%
2014-01-25 19:07:05,868阶段1地图= 100%,减少= 0%,累计CPU 2.07秒
2014-01-25 19:07:14,047阶段1映射= 100%,减少= 0%,累计CPU 2.07秒
2014-01 -25 19:07:15,059第1阶段地图= 100%,减少= 100%,累计CPU 2.07秒
MapReduce总累积CPU时间:2秒70毫秒
完成工作= job_201401251835_0004
**将数据复制到本地目录outputLocalDir
将数据复制到本地目录outputLocalDir **
2加载到outputLocalDir的行
MapReduce作业启动:
作业0:映射:1累积CPU: 2.07秒HDFS读取:525 HDFS写入:66 SUCCESS
Total MapReduce CPU使用时间:2秒70毫秒
OK
名字第二名称dob分数分支
拍摄时间:32.44秒






输出文件

cat ./outputLocalDir/000000_0


I have a script with a set of 5 queries.I would like to execute the script and write the output to a file.What command should I give from the hive cli. Thanks

解决方案

sample Queries file (3 queries) :

ramisetty@aspire:~/my_tmp$ cat queries.q

show databases; --query1
use my_db;  --query2
INSERT OVERWRITE LOCAL DIRECTORY './outputLocalDir' --query3              
select * from students where branch = "ECE";        --query3

Run HIVE:

ramisetty@aspire:~/my_tmp$ hive

hive (default)> source ./queries.q;

--output of Q1 on console-----

Time taken: 7.689 seconds

--output of Q2 on console -----

 Time taken: 1.689 seconds
____________________________________________________________
Total MapReduce jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_201401251835_0004, Tracking URL = http://localhost:50030/jobdetails.jsp?jobid=job_201401251835_0004
Kill Command = /home/ramisetty/VJDATA/hadoop-1.0.4/libexec/../bin/hadoop job  -kill job_201401251835_0004
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
2014-01-25 19:06:56,689 Stage-1 map = 0%,  reduce = 0%
2014-01-25 19:07:05,868 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.07 sec
2014-01-25 19:07:14,047 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.07 sec
2014-01-25 19:07:15,059 Stage-1 map = 100%,  reduce = 100%, Cumulative CPU 2.07 sec
MapReduce Total cumulative CPU time: 2 seconds 70 msec
Ended Job = job_201401251835_0004
**Copying data to local directory outputLocalDir
Copying data to local directory outputLocalDir**
2 Rows loaded to outputLocalDir
MapReduce Jobs Launched: 
Job 0: Map: 1   Cumulative CPU: 2.07 sec   HDFS Read: 525 HDFS Write: 66 SUCCESS
Total MapReduce CPU Time Spent: 2 seconds 70 msec
OK
firstname   secondname  dob score   branch
Time taken: 32.44 seconds


output file :

cat ./outputLocalDir/000000_0

这篇关于将脚本的输出写入配置单元中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆