hive - 使用 hive 函数对数据进行排序
问题描述
我有一张蜂巢桌
create table abc ( id int, channel string, time int );
insert into table abc values
(1,'a', 12),
(1,'c', 10),
(1,'b', 15),
(2,'a', 15),
(2,'c', 12),
(2,'c', 7);
我希望结果表看起来像这样 -
id , journey
1, c->a->b
2, c->c->a
journey
列按时间升序排列id
我努力了
select id , concat_ws(">", collect_list(channel)) as journey
from abc
group by id
但它不保持秩序。
解决方案
使用子查询并按时间排序(以保留顺序),然后在外部查询中使用带有 group by 子句的 collect_list。
hive> select id , concat_ws("->", collect_list(channel)) as journey from
(
select * from abc order by time
)t
group by id;
+-----+----------------+--+
| id | journey |
+-----+----------------+--+
| 1 | 'c'->'a'->'b' |
| 2 | 'c'->'c'->'a' |
+-----+----------------+--+
推荐阅读
- reactjs - 为什么渲染延迟 > 5 秒?
- typescript - 如何在 typescript 中使用 reset()、.value 和其他 DOM 键?
- dart - FloatingActionButton 结束对齐剪切图标
- javascript - Vue:如何将变量名作为参数传递?
- google-cloud-platform - 如果我的 Google Cloud Scheduler 作业失败,如何发送电子邮件提醒?
- regex - 崇高的文字替换字母周围的空格
- c# - 如何使用 EF core 2.2 在运行时更新模型?
- javascript - AMCharts - 在较小分辨率下不可见的数据点
- git - 以最低权限限制 GitHub API 访问
- jenkins - 如何使用 Jenkins kubernetes 插件模板化我的 Pod 定义?