Sam
Sam

Reputation: 27

How to locate/export Hive query?

I am new at Hive and am attempting to export a hive query to a local file on my computer that way I can import results to excel.

When I do from inside hive;

hive -e select * from TABLE limit 10'>output.txt;

I get "FAILED: ParseException line 1:0 cannot recognize input near 'hive' '-' 'e'"

when I do

hive -S -e "USE DATABASE; select * from TABLE limit 10" > /tmp/test/test.csv;

from shell OR

insert overwrite local directory '/tmp/hello' select * from TABLE limit 10;

It goes to the hdfs system in Hive -- how do I get this to my local machine?

Upvotes: 0

Views: 727

Answers (2)

venkata
venkata

Reputation: 477

You are seeing the error as you are running the hive -e commands in the hive repl as show below

hive (venkat)> hive -e 'select * from a';
NoViableAltException(26@[])
        at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1084)
        at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:202)
        at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:437)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:320)
        at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1219)
        at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1260)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1156)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1146)
        at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:216)
        at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:168)
        at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:379)
        at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:739)
        at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:684)
        at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:624)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.hadoop.util.RunJar.run(RunJar.java:233)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:148)
FAILED: ParseException line 1:0 cannot recognize input near 'hive' '-' 'e'

you have to do it in the OS shell as shown below

[venkata_udamala@gw02 ~]$ hive -e 'use database_name;select * from table_name;' > temp.txt

Upvotes: 0

HISI
HISI

Reputation: 4797

You can export query to CSV file like:

hive -e 'select * from your_Table' > /home/yourfile.csv

to get this file to your local machine, you should use HDFS:

HDFS DFS -get /tmp/hello /PATHinLocalMachine

Check out this Question

Upvotes: 0

Related Questions