【问题标题】:Hadoop Still Treats Commas as Delimiters after Explictly Declaring a Different Character在明确声明不同字符后,Hadoop 仍将逗号视为分隔符
【发布时间】:2015-03-27 22:14:25
【问题描述】:

我目前正在将数据导入配置单元表。当我们创建我们使用的表时

CREATE EXTERNAL TABLE Customers
(
Code      string,
Company      string,
FirstName     string,
LastName     string,
DateOfBirth string,
PhoneNo     string,
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';

因为我们的数据中有逗号。但是,我们现在发现逗号仍被视为字段分隔符,|我们用来分隔字段。有没有办法解决这个问题?我们是否必须转义数据中的每一个逗号,还是有更简单的方法来设置它?

示例数据

1|2|3|4
a|b|c|d
John|Joe|Bob, Jr|Alex

放入表格时显示为

1 2 3 4
a b c d
John Joe Bob Jr

Jr 占据了自己的专栏并将 Alex 从桌子上撞了下来。

【问题讨论】:

  • 你能展示完整的CREATE TABLE声明吗?
  • @Jeremy 更新了完整的声明。可能是因为我们使用的是ROW FORMAT DELIMITED?我已经在所有示例代码中看到了这一点,所以我一直认为它只是意味着这是查找该属性的地方,但我突然想到它可能会以某种方式触发逗号行为?不幸的是,IBM 的文档并不是最好的。
  • DDL 的分隔符部分对我来说看起来是正确的。也许这是特定于您的 BigInsights 版本的东西。
  • BigInsights 2.1.2,Hive 0.12
  • 我没有使用过 BigInsights,所以很抱歉。

标签: hadoop hive biginsights


【解决方案1】:

使用您的数据对我来说效果很好。 Hive 版本是 0.13

hive> create external table foo(
    > first string,
    > second string,
    > third string,
    > forth string)
    > row format delimited fields terminated by '|' lines terminated by '\n';
OK
Time taken: 3.222 seconds
hive> load data inpath '/user/xilan/data.txt' overwrite into table foo;

hive> select third from foo;
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_1422157058628_0001, Tracking URL =    http://host:8088/proxy/application_1422157058628_0001/
Kill Command = /scratch/xilan/hadoop/bin/hadoop job  -kill job_1422157058628_0001
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
2015-03-27 07:05:41,901 Stage-1 map = 0%,  reduce = 0%
2015-03-27 07:05:50,190 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 1.24 sec
MapReduce Total cumulative CPU time: 1 seconds 240 msec
Ended Job = job_1422157058628_0001
MapReduce Jobs Launched:
Job 0: Map: 1   Cumulative CPU: 1.24 sec   HDFS Read: 245 HDFS Write: 12     SUCCESS
Total MapReduce CPU Time Spent: 1 seconds 240 msec
OK
3
c
Bob, Jr
Time taken: 18.853 seconds, Fetched: 3 row(s)
hive>

【讨论】:

  • 您可以在 BigInsights 中查看此内容以供我测试吗?转到文件,然后是目录表并单击表并告诉我它是否工作相同?我们没有使用 Hive 检查,因为它有数百万条记录,我们只是碰巧注意到,当我们通过目录表查看早期记录时,它显示出这种行为。想知道 BI 与 Hive 是否不同,或者 Hive .12 与 .13 是否不同
  • 对不起。我什至没有听说过 BigIndight,也不知道这里。
  • BigInsights 是 IBM 的 Hadoop 版本。不过不用担心,我会看看能不能找到工作。很高兴知道升级至少会解决它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-17
  • 1970-01-01
  • 2017-12-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多