Write the output of a script to a file in hive

2019-08-06 01:11发布

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

标签: hive
1条回答
仙女界的扛把子
2楼-- · 2019-08-06 01:52

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

查看更多
登录 后发表回答