Is it possible to create a hive table with text output format?
Asked Answered
F

1

6

My first attempt was:

CREATE TABLE t1 ( 
  a string )       
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS TEXTFILE ;

But the result of that is:

CREATE TABLE t1 ( 
  a string )                                            
ROW FORMAT DELIMITED                                            
  FIELDS TERMINATED BY ','                                      
STORED AS INPUTFORMAT                                           
  'org.apache.hadoop.mapred.TextInputFormat'                    
OUTPUTFORMAT                                                    
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'  ;

which seems to result in a binary file and not a text file.

I insert data into t1:

insert into t1 values ( "hello");
INFO  : Loading data to t1 
INFO  : Table t1 stats: [numFiles=1, numRows=1, totalSize=14, rawDataSize=5]
No rows affected (86.403 seconds)

The hdfs file that results is:

14 2017-10-18 17:20 t1/000000_0.deflate

And the contents are binary. What I actually need is a text file.

So, is it possible to get an hdfs output format which is text?

BTW, I am using a hortonworks big data distribution. HDP 2.5.0.

$ hdp-select | grep hive
hive-metastore - 2.5.0.0-1245
hive-server2 - 2.5.0.0-1245
hive-server2-hive2 - 2.5.0.0-1245
hive-webhcat - 2.5.0.0-1245
Forgotten answered 18/10, 2017 at 6:28 Comment(0)
L
3

zlib/deflate compression format - It is the default data compression format. The file extension of this compression format is .deflate. The following configuration is used to set this format:

SET hive.exec.compress.output=true;
SET mapred.output.compression.codec=org.apache.hadoop.io.compress.DefaultCodec;

To switch-off compression use this:

SET hive.exec.compress.output=false;

And instead of specifying INPUTFORMAT, OUTPUTFORMAT you can just write simply STORED AS TEXTFILE See this answer: https://mcmap.net/q/819623/-difference-between-39-stored-as-inputformat-outputformat-39-and-39-stored-as-39-in-hive

Langrage answered 18/10, 2017 at 7:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.