Hadoop 未在配置单元表中读取V Json数据
我正在从Twitter的一个Hive外部表中读取一行Hadoop 未在配置单元表中读取V Json数据,hadoop,hive,Hadoop,Hive,我正在从Twitter的一个Hive外部表中读取一行json数据。该表已创建,但在读取数据时,出现了一个错误。我想读标签。我遵循了以下步骤: hive (test)> add jar /usr/lib/hive/lib/hive-serdes-1.0-SNAPSHOT.jar; Added /usr/lib/hive/lib/hive-serdes-1.0-SNAPSHOT.jar to class path Added resource: /usr/
json
数据。该表已创建,但在读取数据时,出现了一个错误。我想读标签。我遵循了以下步骤:
hive (test)> add jar /usr/lib/hive/lib/hive-serdes-1.0-SNAPSHOT.jar;
Added /usr/lib/hive/lib/hive-serdes-1.0-SNAPSHOT.jar to class path
Added resource: /usr/lib/hive/lib/hive-serdes-1.0-SNAPSHOT.jar
文件中的数据:
hive (test)> dfs -cat abhijit_hdfs/flume2/tweets/Twitter_test.js;
"entities":{"symbols":[],"urls":[],"hashtags":[{"text":"AchieveMore","indices":[56,68]}]}
DDL语句
hive (test)> create external table tt4
> (entities struct<hashtags:array<struct<text:string>>>)
> row format serde 'com.cloudera.hive.serde.JSONSerDe'
> LOCATION '/user/training/abhijit_hdfs/flume2/tweets/' ;
OK
Time taken: 0.193 seconds.
hive (test)> select * from tt4;
OK
Failed with exception java.io.IOException:org.apache.hadoop.hive.serde2.SerDeException: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.LinkedHashMap out of VALUE_STRING token
at [Source: java.io.StringReader@1cc892e; line: 1, column: 1]
Time taken: 0.384 seconds
hive(测试)>创建外部表tt4
>(实体结构)
>行格式serde'com.cloudera.hive.serde.JSONSerDe'
>位置“/user/training/abhijit_hdfs/flume2/tweets/”;
好啊
所用时间:0.193秒。
蜂巢(测试)>从tt4中选择*;
好啊
失败,出现异常java.io.IOException:org.apache.hadoop.hive.serde2.SerDeException:org.codehaus.jackson.map.JsonMappingException:无法反序列化java.util.LinkedHashMap的实例超出值\u字符串标记
在[来源:java.io。StringReader@1cc892e;行:1,列:1]
所用时间:0.384秒
请指导。这看起来像是一个与Hadoop或hive无关的问题,而更像是一个JSON序列化程序错误。您所指的serde内部使用org.codehaus.jackson 在尝试JSON时,似乎出现了此错误
`Error: Parse error on line 1:"entities":{"symbols":[],"urls
----------^
Expecting 'EOF', '}', ',', ']', got ':'`
我还没有尝试过整个设置,但是JSON似乎缺少一个{开头是一个好的可解析JSON
{"entities":{"symbols":[],"urls":[],"hashtags":[{"text":"AchieveMore","indices":[56,68]}]}}
当使用hcatalog JsonSerDe时,在添加周围的curl括号(
{…}
)后,它确实可以工作
create external table tt4
(
entities struct<hashtags:array<struct<text:string>>>
)
row format serde 'org.apache.hive.hcatalog.data.JsonSerDe'
;
JSON文件的JsonSerDe在Hive0.12及更高版本中可用 在某些发行版中,对hive hcatalog core.jar的引用是 必需。添加JAR/usr/lib/hive-hcatalog/lib/hive-hcatalog-core.JAR JsonSerDe从HCatalog移动到蜂箱中,在它进入之前 配置单元contrib项目。它是由 蜂箱-4895
亲爱的朋友,这个问题已经解决了,我下载并保存了以下jar,并重新启动了我的claudera VM(非商业用途)。感谢您的帮助,为我解决这个问题提供了方向
hive>添加jar/usr/lib/hive/lib/json-serde-1.3.6-jar-with-dependencies.jar;
将/usr/lib/hive/lib/json-serde-1.3.6-jar-with-dependencies.jar添加到类路径中
添加的资源:/usr/lib/hive/lib/json-serde-1.3.6-jar-with-dependencies.jar
hive>创建外部表t24
(实体结构)
行格式serde'org.openx.data.jsonserde.jsonserde'
位置“/user/training/abhijit_hdfs/flume4/tweets/”
;
好的
所用时间:1.623秒
蜂巢>从t24中选择*;
好啊
{“hashtags”:[{“text”:“AchieveMore”}]}
无效的
所用时间:1.13秒
蜂巢>
您好,格雷,谢谢您的回复。我已按照您所述对数据进行了更改,但现在我收到了以下错误,
,原因是:org.apache.hadoop.hive.ql.metadata.HiveException:hive运行时在处理可写时出错
原因:org.apache.hadoop.hive.serde2.SerDeException:java.io.eofeException:由于输入结束,没有要映射到对象的内容
您好Dudu谢谢您的回复,您使用了哪个jar,我收到的错误是,`hive(test)>create external table t17>(entities struct)>行格式serde'org.apache.hive.hcatalog.data.JsonSerDe'>LOCATION'/user/training/abhijit_hdfs/flume3/tweets/>;失败:元数据错误:无法验证serde:org.apache.hive.hcatalog.data.JsonSerDe失败:执行错误,从org.apache.hadoop.hive.ql.exec.ddls返回代码1直到艰难地完成。检查我的最新答案。都都非常感谢你,我注意到了你的最新回复。你在帮助新学员方面做得很好。
select * from tt4
;
+---------------------------------------+
| entities |
+---------------------------------------+
| {"hashtags":[{"text":"AchieveMore"}]} |
+---------------------------------------+