Adding a comma separated table to Hive

前端 未结 4 1908
傲寒
傲寒 2021-01-26 08:38

I have a very basic question which is: How can I add a very simple table to Hive. My table is saved in a text file (.txt) which is saved in HDFS. I have tried to create an exter

4条回答
  •  囚心锁ツ
    2021-01-26 09:22

    1. You just need to create an external table pointing to your file location in hdfs and with delimiter properties as below:

      create external table Data (
          dummy INT,
          account_number INT, 
          balance INT, 
          firstname STRING, 
          lastname STRING, 
          age INT, 
          gender CHAR(1), 
          address STRING, 
          employer STRING, 
          email STRING,
          city STRING, 
          state CHAR(2)
      )
      ROW FORMAT DELIMITED
      FIELDS TERMINATED BY ',' 
      LINES TERMINATED BY '\n'
      LOCATION 'hdfs:///KibTEst/Data.txt';
      
    2. You need to run select query(because file is already in HDFS and external table directly fetches data from it when location is specified in create statement). So you test using below select statement:

    SELECT * FROM Data;

提交回复
热议问题