arrays - 无法运行 HIVE 查询
问题描述
我table
在 Cloudera VM 中使用 HIVE 查询创建了一个,下面是我DDL
创建名为incremental_tweets
.
CREATE EXTERNAL TABLE incremental_tweets (
id BIGINT,
created_at STRING,
source STRING,
favorited BOOLEAN,
retweet_count INT,
retweeted_status STRUCT<
text:STRING,
user:STRUCT<screen_name:STRING,name:STRING>>,
entities STRUCT<
urls:ARRAY<STRUCT<expanded_url:STRING>>,
user_mentions:ARRAY<STRUCT<screen_name:STRING,name:STRING>>,
hashtags:ARRAY<STRUCT<text:STRING>>>,
text STRING,
user STRUCT<
screen_name:STRING,
name:STRING,
friends_count:INT,
followers_count:INT,
statuses_count:INT,
verified:BOOLEAN,
utc_offset:INT,
time_zone:STRING>,
in_reply_to_screen_name STRING
)
ROW FORMAT SERDE 'com.cloudera.hive.serde.JSONSerDe'
LOCATION '/twitteranalytics/incremental/';
在成功创建表上执行此操作后HUE HIVE Editor
,现在的问题是我无法执行SELECT
引发以下错误的语句。
SELECT Statement
Select id, entities.user_mentions.name FROM incremental_tweets;
ERROR
Error while processing statement: FAILED: Execution Error, return code 2
from org.apache.hadoop.hive.ql.exec.mr.MapRedTask
此外,由于HUE editor
提供了自动完成功能,下面是它给出的语句和错误。
Statement
Select id, entities.`,user_mentions`.name FROM incremental_tweets;
ERROR
Error while compiling statement: FAILED: RuntimeException cannot find field
,user_mentions(lowercase form: ,user_mentions) in [urls, user_mentions,
hashtags]
什么是正确的SELECT statement
?我错过了任何语法吗?
解决方案
user_mentions
是一个结构数组。您只能通过指定数组索引来处理内部结构元素:
entities.user_mentions[0].name --get name from first array element
或者如果要选择所有数组元素,请使用explode()
+ :lateral view
select id, user_mention.name
from incremental_tweets
lateral view outer explode(entities.user_mentions) s as user_mention
;
推荐阅读
- java - 将具有不同时区的日期和时间转换为时间戳
- javascript - 我使用 jquery 在 onclick() 函数中传递了产品名称?但错误
- qt - 如何正确截断/调整 QList<> 的大小
- android - 如何检测 android cordova 应用程序当前是否正在任何设备上运行?
- php - 使用搜索 api 使用寻呼机从查看结果中删除重复记录
- c++ - 每次使用 std::cout 时是否可以执行函数?
- javascript - Javascript forEach 方法
- php - 与主管一起运行两个 Laravel 项目队列
- angular - '""' 类型的参数不能分配给 '"prototype"' jasmine 类型的参数
- c# - 更新 TreeView 文件资源管理器代码以在 UWP 中使用 Microsoft.UI.Xaml