问题

在使用load data inpathCSV文件导入到hive表时,发现列头被当做数据导入到hive表中,如下图:
hive 向表中导入数据时忽略首行

原数据格式

hive 向表中导入数据时忽略首行

hive建表语句

create table hive_movies
(
     rank int,
     src string,
     name string,
     box_office string,
     avg_price int,
     avg_people int,
     begin_date string
) row format delimited fields terminated by ',';

导入数据

load data inpath '/input/movies.csv' overwrite into table hive_movies;

数据展示

hive 向表中导入数据时忽略首行

解决方案

向表中load数据过滤首行TBLPROPERTIES ('skip.header.line.count'='1')

  • 已建表执行

    alter table hive_movies set TBLPROPERTIES ('skip.header.line.count'='1');
    
  • 新建表

    create table hive_movies
    (
         rank int,
         src string,
         name string,
         box_office string,
         avg_price int,
         avg_people int,
         begin_date string
    ) row format delimited fields terminated by ','
    TBLPROPERTIES ('skip.header.line.count'='1');	
    
  • 重新执行数据导入

    load data inpath '/input/movies.csv' overwrite into table hive_movies;
    

    注:执行load data inpath时,原文件会被删除

  • 效果
    hive 向表中导入数据时忽略首行

相关文章:

  • 2021-12-12
  • 2021-08-03
  • 2022-12-23
  • 2021-10-07
  • 2021-05-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-17
  • 2021-07-16
  • 2021-08-14
相关资源
相似解决方案