如何在hive表中加载csv文件?

时间:2013-12-17 11:48:14

标签: hive

我在hive中创建表并从hdfs加载csv文件但是当我尝试在创建的表上执行select查询时,我得到加密格式的结果,请你为此提供解决方案。

create table if not exists studentsinforamtion(
  studentnumber string ,
  universityname  string,
  collegename   string,
  studentname string, 
  branch string, 
  percentage string,
  areaters string,
  rankatuniversity INT,
  eligibleforcompnay string,
  selectedcompanylist int) 
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
stored as textfile;

load data inpath '/user/root/jobportal/studentinfo.ods' overwrite into table studentsinforamtion;

select * from studentsinforamtion limit 5;

ERROR:

OK
PK5:�C�l9�.mimetypeapplication/vnd.oasis.opendocument.spreadsheetPK5:�C�{C44meta.xml<?xml version="1.0" encoding="UTF-8"?>  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL
<office:document-meta xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:grddl="http://www.w3.org/2

1 个答案:

答案 0 :(得分:0)

看起来你的文件不是纯粹的逗号分隔文件(或者从我的表的分隔符中看到的制表符分隔符)。它有一些opendocument元数据“mimetypeapplication / vnd.oasis.opendocument.spreadsheetPK5: C {C44meta.xml”。尝试以.csv格式保存您的文档,或使用简单的文本编辑器创建所需的电子表格。

FYI - 选择结果中的“NULL”通常表示列类型和值类型不同 - 例如你有一个包含列类型(int,int,int)的表,并且你已经使用值(15,23,userinfo)将文件下载到其中 - select应该返回15,23,NULL。 Hive在上传过程中不会检查值的类型,因此请注意它们。