Hive SQL:访问 Json 数组的最后一个元素
我有一个名为“schedule_info”的 json 列,其格式如下:
{schedule: [{"date":"2020-01-01"},{"date":"2021-01-01"},{"date":"2022-01-01"},{"date":"2022 -02-01"},{"date":"2022-03-01"}]}
我可以通过以下方式轻松访问第一个元素:
get_json_object(schedule_info, '$.schedule[0].date') 作为first_date。
但是,当我尝试访问最后一个日期时,我无法..
我尝试过“get_json_object(schedule_info, '$.schedule[-1].date')”。但是,这仅返回整个计划数组。我也尝试过将数组长度包含在括号中,但效果不佳。有没有一种简单的方法可以做到这一点?
我想轻松地从 json 数组的最后一个元素解析出数据,而不必分解数组。
I have a json column called "schedule_info" with a format like the following:
{schedule: [{"date":"2020-01-01"},{"date":"2021-01-01"},{"date":"2022-01-01"},{"date":"2022-02-01"},{"date":"2022-03-01"}]}
I'm able to access the first element easily with:
get_json_object(schedule_info, '$.schedule[0].date') as first_date.
However, When I try to access the last date, I'm not able to..
I've tried "get_json_object(schedule_info, '$.schedule[-1].date')". But, this just returns the whole schedule array. I've also tried including the array length in the brackets, which didn't work as well.. Is there an easy way to do this?
I want to easily parse out data from the last element of a json array without having to explode the array.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用brickhouse,
json_split
可以帮助您:这里您使用
json_split
两次,一次用于获取数组元素,另一次用于获取数组大小或使用
reverse< /code> 消除对
json_split
的一次调用json_split 博客
brickhouse github
if you use brickhouse,
json_split
could help you like this:here you use
json_split
twice, one for get array element, another for get array sizeor use
reverse
to eliminate one call tojson_split
json_split blog
brickhouse github