将脚本的输出写入配置单元中的文件

时间:2014-01-24 19:07:32

标签: hive

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

1 个答案:

答案 0 :(得分:0)

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

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

运行HIVE:

ramisetty @ aspire:〜/ my_tmp $ hive

hive(默认)> 来源./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

输出文件

cat ./outputLocalDir/000000_0