Karver01
Karver01

Reputation: 79

Error while exporting the results of a HiveQL query to CSV?

I am a beginner in Hadoop/Hive. I did some research to find out a way to export results of HiveQL query to CSV. I am running below command line in Putty -

Hive -e ‘use smartsourcing_analytics_prod; select *  from solution_archive_data limit 10;’ > /home/temp.csv;

However below is the error I am gettingenter image description here

ParseException line 1:0 cannot recognize input near 'Hive' '-' 'e'

I would appreciate inputs regarding this.

Upvotes: 0

Views: 507

Answers (2)

belostoky
belostoky

Reputation: 974

  • Run your command from outside the hive shell - just from the linux shell.
  • Run with 'hive' instead of 'Hive'
  • Just redirecting your output into csv file won't work. You can do:
    hive -e 'YOUR QUERY HERE' | sed 's/[\t]/,/g' > sample.csv
    like was offered here: How to export a Hive table into a CSV file?
  • AkashNegi answer will also work for you... a bit longer though

Upvotes: 1

kashmoney
kashmoney

Reputation: 97

One way I do such things is to create an external table with the schema you want. Then do INSERT INTO TABLE target_table ... Look at the example below:

CREATE EXTERNAL TABLE isvaliddomainoutput (email_domain STRING, `count` BIGINT) 
ROW FORMAT DELIMITED FIELDS TERMINATED BY ","
STORED AS TEXTFILE
LOCATION "/user/cloudera/am/member_email/isvaliddomain";

INSERT INTO TABLE isvaliddomainoutput

SELECT * FROM member_email WHERE isvalid = 1;

Now go to "/user/cloudera/am/member_email/isvaliddomain" and find your data.

Hope this helps.

Upvotes: 1

Related Questions