Error loading csv data into Hive table

后端 未结 3 1198
难免孤独
难免孤独 2021-01-05 03:14

i have a csv file in hadoop and i have a Hive table ,now i want to laoad that csv file into this Hive table

i have used load LOAD DATA local \'path/to/csv/file\' ove

相关标签:
3条回答
  • 2021-01-05 03:56

    I think the command to load CSV to Hive table is ( when CSV is in HDFS).

    LOAD DATA INPATH '/user/test/my.csv' INTO TABLE my_test;
    
    0 讨论(0)
  • 2021-01-05 04:00

    As your file is already present in the HDFS remove the keyword Local

    LOAD DATA inpath 'path/to/csv/file' overwrite INTO TABLE tablename;

    0 讨论(0)
  • 2021-01-05 04:01

    I have developed a tool to generate hive scripts from a csv file. Following are few examples on how files are generated. Tool -- https://sourceforge.net/projects/csvtohive/?source=directory

    1. Select a CSV file using Browse and set hadoop root directory ex: /user/bigdataproject/

    2. Tool Generates Hadoop script with all csv files and following is a sample of generated Hadoop script to insert csv into Hadoop

      #!/bin/bash -v
      hadoop fs -put ./AllstarFull.csv /user/bigdataproject/AllstarFull.csv hive -f ./AllstarFull.hive

      hadoop fs -put ./Appearances.csv /user/bigdataproject/Appearances.csv hive -f ./Appearances.hive

      hadoop fs -put ./AwardsManagers.csv /user/bigdataproject/AwardsManagers.csv hive -f ./AwardsManagers.hive

    3. Sample of generated Hive scripts

      CREATE DATABASE IF NOT EXISTS lahman;
      USE lahman;
      CREATE TABLE AllstarFull (playerID string,yearID string,gameNum string,gameID string,teamID string,lgID string,GP string,startingPos string) row format delimited fields terminated by ',' stored as textfile;
      LOAD DATA INPATH '/user/bigdataproject/AllstarFull.csv' OVERWRITE INTO TABLE AllstarFull;
      SELECT * FROM AllstarFull;

    Thanks Vijay

    0 讨论(0)
提交回复
热议问题