impala 中的乘法行

发布于 2025-01-12 11:32:22 字数 546 浏览 1 评论 0原文

我正在通过 sqoop 从带有一些连接表的视图中获取一些数据到 impala 的外部表中。但是我看到一个表中的列乘以行。 例如

id first_name surname step name       value
1  ted         kast    1   museum     visitor
1  ted         kast    1   shop       buyer
1  ted         kast    2   museum     visitor
1  ted         kast    2   shop       buyer

,但我想成为这样的人,

id first_name surname step name_value
1  ted        kast    1    [(museum visitor), (shop buyer)]
1  ted        kast    2    [(museum visitor), (shop buyer)]

我怎样才能在黑斑羚中实现这一目标?

I am fetching some data from a view with some joined tables through sqoop into an external table in impala. However I saw that the columns from one table multiply the rows.
For example

id first_name surname step name       value
1  ted         kast    1   museum     visitor
1  ted         kast    1   shop       buyer
1  ted         kast    2   museum     visitor
1  ted         kast    2   shop       buyer

But I want to be something like that

id first_name surname step name_value
1  ted        kast    1    [(museum visitor), (shop buyer)]
1  ted        kast    2    [(museum visitor), (shop buyer)]

How can I achieve that in impala?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福还没到 2025-01-19 11:32:22

我们可以在此处将聚合与 GROUP_CONCAT 一起使用:

SELECT
    id,
    first_name,
    surname,
    step,
    CONCAT('[', GROUP_CONCAT(CONCAT('(', CONCAT_WS(' ', name, value), ')'), ', '), ']') AS name_value
FROM yourTable
GROUP BY
    id,
    first_name,
    surname,
    step
ORDER BY id;

这是一个 MySQL 的 demo,其语法与 Impala 几乎相同。

We can use aggregation here along with GROUP_CONCAT:

SELECT
    id,
    first_name,
    surname,
    step,
    CONCAT('[', GROUP_CONCAT(CONCAT('(', CONCAT_WS(' ', name, value), ')'), ', '), ']') AS name_value
FROM yourTable
GROUP BY
    id,
    first_name,
    surname,
    step
ORDER BY id;

Here is a demo for MySQL, where the syntax is almost the same as for Impala.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文