1

Is there a command line in HIVE that can be used to define the format of the output file to CSV?

Something similar to the below example?

set hive.resultset.use.unique.column.names=false;

EDIT - Added the following for further context 12/18.

A terminal window I'm using has predefined settings for the command line when it runs an 'export' through a script. The following is it's commands:

set hive.metastore.warehouse.dir=/idn/home/user;
set mapred.job.queue.name=root.gmis;
set hive.exec.scratchdir=/axp/hivescratch/user;
set hive.resultset.use.unique.column.names=false;
set hive.cli.print.header=true;
set hive.groupby.orderby.position.alias=true;

Is there another command I could add versus the lengthy strings per below? I'm using in the other hive terminal the following; but it's SQL is different(?).

cloak-hive -e "INSERT OVERWRITE LOCAL DIRECTORY '/adshome/user/VS_PMD' ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
GarageKid
  • 23
  • 5
  • Possible duplicate of [Export as csv in beeline hive](https://stackoverflow.com/questions/39577036/export-as-csv-in-beeline-hive) – OneCricketeer Dec 19 '17 at 19:48

2 Answers2

1

You can mention the out put file format to csv refer the following example command. Note that it’s same for beeline and hive

beeline -u jdbc:hive2://localhost:10000/default --silent=true --outputformat=csv2 -e "select * from sample_07 limit 10" > out.txt
roh
  • 1,033
  • 1
  • 11
  • 19
0

On Apache documentation, https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML#LanguageManualDML-Writingdataintothefilesystemfromqueries

Standard syntax:

INSERT OVERWRITE [LOCAL] DIRECTORY directory1
[ROW FORMAT row_format] [STORED AS file_format] 
SELECT ... FROM ...

INSERT OVERWRITE LOCAL DIRECTORY directory1 
ROW FORMAT DELIMITED 
STORED AS TEXTFILE 
SELECT ... FROM ...;

Maybe some work would be needed on ROW FORMAT to achieve expected result. Please note also that LOCAL value refers to local filesystem.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245