35

Hello Friends,

I created table in hive with help of following command -

CREATE TABLE db.test 
  ( 
     fname STRING, 
     lname STRING, 
     age   STRING, 
     mob   BIGINT 
  ) row format delimited fields terminated BY '\t' stored AS textfile; 

Now to load data in table from file, I am using following command -

load data local inpath '/home/cluster/TestHive.csv' into table db.test;

Problem is, all the rows are getting inserted, and I don't want first row because it contains only column names.

Please suggest me a way to skip first line.

Thanks in advance.

Jim Counts
  • 12,535
  • 9
  • 45
  • 63
Pankaj
  • 369
  • 1
  • 4
  • 7
  • 2
    Looks like a duplicate http://stackoverflow.com/questions/15751999/hive-external-table-skip-first-row/15753145#15753145 – Rohit Menon Dec 28 '13 at 10:51
  • possible duplicate of [Hive External table-CSV File- Header row](http://stackoverflow.com/questions/16457267/hive-external-table-csv-file-header-row) – Marek Grzenkowicz Aug 13 '14 at 09:43
  • Does this answer your question? [How to skip CSV header in Hive External Table?](https://stackoverflow.com/questions/15751999/how-to-skip-csv-header-in-hive-external-table) – Jacek Laskowski Jun 29 '21 at 08:44

3 Answers3

56

To get this you can use hive's property which is TBLPROPERTIES ("skip.header.line.count"="1")
you can also refer example -

CREATE TABLE temp 
  ( 
     name STRING, 
     id   INT 
  ) 
row format delimited fields terminated BY '\t' lines terminated BY '\n' 
tblproperties("skip.header.line.count"="1"); 
Jim Counts
  • 12,535
  • 9
  • 45
  • 63
Bector
  • 1,324
  • 19
  • 35
10

Just for those who have already created the table with the header. Here is the alter command for the same.

ALTER TABLE tablename SET TBLPROPERTIES ("skip.header.line.count"="1");

3

Just don't mix double quotes and single quotes in the same CLI command:

CREATE TABLE db.test 
  ( 
     fname STRING, 
     lname STRING, 
     age   STRING, 
     mob   BIGINT 
  ) row format delimited fields terminated BY '\t' tblproperties('skip.header.line.count'='1') stored AS textfile; 

otherwise hive load NULL values.

Erkan Şirin
  • 1,935
  • 18
  • 28