简体   繁体   English

如何将CSV文件导出到带有蜂记录值的Hive表中?

[英]How do I export a CSV file into Hive table with records value with comma?

Input File 输入文件

   11/24/2013,bank of nyc,withdrawl,deposit,in progress
   11/16/2014,bank of dc,opeanig,closing,resolved    

I want them in the table 我要他们在桌子上

  Date           Bank name         issue                status 
  11/24/2013     bank of nyc     withdrawl,deposit     in progress
  11/16/2014     bank of dc      opeanig,closing       resolved

Well, the problem is that the comma is not escaped...how is hive supposed to know if a comma is part of a string, or a separator ? 好吧,问题在于逗号没有被转义...蜂巢应该如何知道逗号是字符串的一部分还是分隔符?

It is possible if you only can have extra commas in one known column, like in this case, the third. 如果只可能在一个已知列中包含多余的逗号,例如本例中的第三列。 You can then write a regular expression that takes anything between the second comma and the last and use it with the Regexp serde. 然后,您可以编写一个在第二个逗号和最后一个逗号之间包含任何内容的正则表达式,并将其与Regexp serde一起使用。 This works for your example, given that only 'issue' may have commas. 鉴于只有“问题”可能有逗号,因此这对您的示例有用。

CREATE TABLE csvsample(
  date STRING,
  bank_name STRING,
  issue STRING,
  status STRING
) ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe' 
  WITH SERDEPROPERTIES (
   "input.regex" = "^([^,]+),([^,]+),(.+),([^,]+)$") ;
hive> select * from csvsample;
OK
11/24/2013  bank of nyc withdrawl,deposit   in progress
11/16/2014  bank of dc  opeanig,closing resolved

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何正确导出到表记录值为CSV的CSV文件? - How do I export to CSV file with table record value with comma in it properly? 如何将包含逗号的 html 表数据导出到 .csv 文件? - How do I export html table data that has contains a comma to a .csv file? 如何将 Hive 表导出为 CSV 文件? - How to export a Hive table into a CSV file? 如何将 html 表格数据导出为 .csv 文件? - How do I export html table data as .csv file? PostgreSQL:如何将表记录拆分/导出为年度切片(CSV)? - PostgreSQL: How do I split/export table records into year wise slices (CSV)? 如何使用mongoexport将集合中的所有记录导出到CSV文件 - How do I use mongoexport to export all records in a collection to a CSV file 如何将这些结果导出到以逗号分隔的csv文件中 - How to export these results in a comma delimited csv file 如何将逗号分隔的 object 导出到 a.csv 文件中 - How to export comma separated object into a .csv file 如何将下面 [10] 中的这两列转换为数据帧/表,以便能够导出到 csv 文件 - How do I convert these 2 columns as seen below in In [10] to a dataframe/table to be able to export to a csv file 如何将 csv 文件复选框值导出到 ruby on rails 中的表中? - how to export csv file checkbox value into table in ruby on rails?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM