【发布时间】:2014-08-05 23:01:56
【问题描述】:
我正在尝试使用具有此包结构的 JSON 文件:
{
"user_id": "kim95",
"type": "Book",
"title": "Modern Database Systems: The Object Model, Interoperability, and Beyond.",
"year": "1995",
"publisher": "ACM Press and Addison-Wesley",
"authors": [
{
"name": "null"
}
],
"source": "DBLP"
}
{
"user_id": "marshallo79",
"type": "Book",
"title": "Inequalities: Theory of Majorization and Its Application.",
"year": "1979",
"publisher": "Academic Press",
"authors": [
{
"name": "Albert W. Marshall"
},
{
"name": "Ingram Olkin"
}
],
"source": "DBLP"
}
我尝试使用 serde 为 Hive 加载 JSON 数据。我遵循了我在这里看到的两种方式:http://blog.cloudera.com/blog/2012/12/how-to-use-a-serde-in-apache-hive/
使用此代码:
CREATE EXTERNAL TABLE IF NOT EXISTS serd (
user_id:string,
type:string,
title:string,
year:string,
publisher:string,
authors:array<struct<name:string>>,
source:string)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION '/user/hdfs/data/book-seded_workings-reduced.json';
我收到了这个错误:
error while compiling statement: failed: parseexception line 2:17 cannot recognize input near ':' 'string' ',' in column type
我也试过这个版本:https://github.com/rcongiu/Hive-JSON-Serde
这给出了一个不同的错误:
Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Cannot validate serde: org.openx.data.jsonserde.JsonSerde
有什么想法吗?
我还想知道有哪些替代方法可以使用这样的 JSON 来查询“作者”中的“姓名”字段。是猪还是蜂巢?
我已经将其转换为“tsv”文件。但是,由于我的作者列是一个元组,如果我从这个文件构建一个表,我不知道如何使用 Hive 对“名称”提出请求。我应该更改我的脚本以进行“tsv”转换还是保留它?或者有没有 Hive 或 Pig 的替代品?
【问题讨论】:
-
忘了说我在 cdh5 quickstart 中使用了这个脚本进行 tsv 转换:stackoverflow.com/questions/24976373/…
-
位置'/user/hdfs/data/book-seded_workings-reduced.json';它应该是目录而不是文件。 “book-seded_workings-reduced.json”在我看来是文件。
标签: hadoop hive apache-pig hue cloudera-cdh