【发布时间】:2018-03-14 08:33:57
【问题描述】:
我正在处理我使用 nifi 从 facebook 获得的嵌套 json 数据。我在 hive 中创建了一个表并使用命令加载数据。
CREATE TABLE abmediaanalysis (id string, posts struct< data:array<struct< message:string, shares:struct< count:int>, id:string, reactions:struct< data:array<struct< name:string,id:string>>, paging:struct< cursors:struct< before:string,after:string>, next:string>>, likes:struct< data:array<struct< id:string>>, paging:struct< cursors:struct< before:string,after:string>, next:string>>>>, paging:struct< previous:string,next:string>>, feed struct< data:array<struct< permalink_url:string,message:string,id:string>>, paging:struct< previous:string,next:string>>)ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe';
load data local inpath '/home/10879/facebook1480479682880.json' overwrite into table abmediaanalysis;
我还添加了 jar 文件 json-serde-1.3.8-jar-with-dependencies.jar, 但是当我使用 lateral view explode 打印所有列时,我得到了java heap size error。我也增加了堆大小,但仍然是同样的错误
select id,posts_message,posts_share_count,posts_id,feed_data_permalink_url,feed_data_message,feed_data_id,reaction_data_name,reaction_data_id,posts_likes_data_id from abmediaanalysis
LATERAL VIEW explode(posts.data.message)MSG as posts_message
LATERAL VIEW explode(posts.data.shares.count)CT as posts_share_count
LATERAL VIEW explode(posts.data.id) I as posts_id
LATERAL VIEW explode(feed.data.permalink_url) PU as feed_data_permalink_url
LATERAL VIEW explode(feed.data.message) MSG as feed_data_message
LATERAL VIEW explode(feed.data.id) I as feed_data_id
LATERAL VIEW explode(posts.data.reactions) NM as posts_reactions_name
LATERAL VIEW explode(posts_reactions_name.data.name) NM as reaction_data_name
LATERAL VIEW explode(posts_reactions_name.data.id) NM as reaction_data_id
LATERAL VIEW explode(posts.data.likes) I as likes_data_id
LATERAL VIEW explode(likes_data_id.data.id) I as posts_likes_data_id;
当我尝试打印两列或三列而不是显示 616 条记录时,它大约显示 15625 条记录。 任何人都可以帮助解决这个问题 是否有机会直接从 nifi 将上述 json 数据加载到 hive 表中?如果可以,你能告诉我。
提前致谢
【问题讨论】:
-
我添加了另一种方法,可能对您有用。
标签: json hive apache-nifi