【问题标题】:In Hive, when I load data from csv file, I only get a part of columns, not the whole things在 Hive 中,当我从 csv 文件加载数据时,我只得到部分列,而不是全部
【发布时间】:2018-10-25 01:18:34
【问题描述】:

这是我的数据源中的列

BibNum  
Title   
Author  
ISBN    
PublicationYear 
Publisher   
Subjects    
ItemType    
ItemCollection  
FloatingItem    
ItemLocation    
ReportDate  
ItemCount

我只得到publisher 列的值。 我上传了一个截图,如果你知道原因和方法可以修复,请告诉我,将不胜感激:

下面是第一行的真实值(我用//标记分隔每一列)

3011076// 
A tale of two friends / adapted by Ellie O'Ryan ; illustrated by Tom Caulfield, Frederick Gardner, Megan Petasky, and Allen Tam.     // 
O'Ryan, Ellie   // 
1481425730, 1481425749, 9781481425735, 9781481425742    // 
2014    // 
Simon Spotlight,    Musicians Fiction, Bullfighters Fiction, Best friends Fiction, Friendship Fiction, Adventure and adventurers Fiction    // 
jcbk    // 
ncrdr   // 
Floating // 
qna  // 
09/01/2017 //   
1

这是第二行的真实值

2248846 //  
Naruto. Vol. 1, Uzumaki Naruto / story and art by Masashi Kishimoto ; [English adaptation by Jo Duffy]. // 
Kishimoto, Masashi, 1974- //    
1569319006  // 
2003, c1999.    // 
Viz,    Ninja Japan Comic books strips etc, Comic books strips etc Japan Translations into English, Graphic novels //   
acbk//  
nycomic//   
NA//    
lcy//   
09/01/2017//    
1



hive> select * from timesheet limit 3;
OK
NULL    Title   Author  ISBN    PublicationYear Publisher   Subjects    ItemType    ItemCollection  FloatingItem    ItemLocation    ReportDate  ItemCount
3011076 "A tale of two friends / adapted by Ellie O'Ryan ; illustrated by Tom Caulfield Frederick Gardner    Megan Petasky   and Allen Tam."    "O'Ryan  Ellie" "1481425730  1481425749  9781481425735   9781481425742" 2014.   "Simon Spotlight
2248846 "Naruto. Vol. 1  Uzumaki Naruto / story and art by Masashi Kishimoto ; [English adaptation by Jo Duffy]."   "Kishimoto   Masashi     1974-" 1569319006  "2003    c1999."    "Viz    "   "Ninja Japan Comic books strips etc  Comic books strips etc Japan Translations into English
Time taken: 0.149 seconds
hive> desc timesheet
    > ;
OK
bibnum  bigint  
title   string  
author  string  
isbn    string  
publication string  
publisher   string  
subjects    string  
itemtype    string  
itemcollection  string  
floatingitem    string  
itemlocation    string  
reportdate  string  
itemcount   string  
Time taken: 0.21 seconds

BibNum,Title,Author,ISBN,PublicationYear,Publisher,Subjects,ItemType,ItemCollection,FloatingItem,ItemLocation,ReportDate,ItemCount |空 |空 |空 |空 |空 |空 |空 |空 |空 |空 |空 |空 | |

3011076,"两个朋友的故事 / 由 Ellie O'Ryan 改编;由 Tom Caulfield、Frederick Gardner、Megan Petasky 和 ​​Allen Tam 绘制。","O'Ryan, Ellie","1481425730, 1481425749, 9781481425735 , 9781481425742",2014.,"Simon Spotlight,","音乐家小说, 斗牛士小说, 好朋友小说, 友谊小说, 冒险和冒险家小说",jcbk,ncrdr,浮动,qna,09/01/2017,1 |空 |空 |空 |空 |空 |空 |空 |空 |空 |空 |空 |空|

【问题讨论】:

  • 您在导入时是否引用了新数据集中的所有逗号?
  • 你是怎么导入的?很可能每列中的逗号没有被转义
  • 我使用的方式是先创建表,然后使用 create table table_name(column names data types..) row format delimited fields by ',' 以 '\n' 结尾的行存储为文本文件;并将路径中的数据 '/path/' 加载到表 table_name
  • 你能上传一些 hive 认为的数据,而不仅仅是一张图片吗?
  • 可能是逗号被引号括起来的问题

标签: hive loading import-from-csv


【解决方案1】:

所以 Apache Hive 本身无法处理像这个 CSV 这样的数据,但使用 SerDe(序列化器/反序列化器)它可以帮助解决这个问题

在 hive v0.14+ 中内置了 serde,默认分隔符为 ,,因此对于您的 CSV,这应该可以工作

create table table_name(column names data types..) 
row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
stored as textfile; 
and load data inpath '/path/' 
into table table_name 

如果任何列中有未转义的引号,您将不得不手动进入并确定哪些列是哪些列...

【讨论】:

  • 无法验证 serde:com.bizo.hive.serde.csv.CSVSerde。我收到了这个错误,你知道这个错误吗?
  • 您是否包含了.jar 文件?
  • 我在 /usr/lib/hive/lib 位置有一个 hive-serde-0.10.0-cdh4.2.1.jar
  • 失败:元数据错误:无法验证 serde:com.bizo.hive.serde.csv.CSVSerde 失败:执行错误,从 org.apache.hadoop.hive.ql.exec 返回代码 1。 DDLTask 错误如上所说。
  • 你能在第二个问题中发布这个吗?给它相同的标签,我会寻找它
【解决方案2】:

由于 csv 文件由逗号分隔,如果您将列指定为字符串,则整行将加载到该列中。因此,在创建表时,您可以指定行值由逗号分隔。

create table table_name (
....
) row format delimited fields terminated by ',' lines terminated by '\n';

然后使用加载 csv 文件

load data local inpath path_to_file to table table_name;

希望这会有所帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 2023-03-11
    相关资源
    最近更新 更多