Athena/Presto - UNNEST MAP 到列
Athena/Presto - UNNEST MAP to columns
假设我有一个像这样的table,
table: qa_list
id | question_id | question | answer |
---------+--------------+------------+-------------
1 | 100 | question1 | answer |
2 | 101 | question2 | answer |
3 | 102 | question3 | answer |
4 | ...
... | ...
和给出以下结果的查询(因为我找不到直接转置 table 的方法),
table: qa_map
id | qa_map
--------+---------
1 | {question1=answer,question2=answer,question3=answer, ....}
其中 qa_map 是 map_agg 任意数量的问题和答案的结果。
有没有办法 UNNEST qa_map 到任意数量的列,如下所示?
id | Question_1 | Answer_1 | Question_2 | Answer_2 | Question_3 | ....
---------+-------------+-----------+-------------+-----------+-------------+
1 | question | answer | question | answer | question | ....
AWS Athena/Presto-0.172
不,无法编写根据数据产生不同列数的查询。在查询执行开始之前必须知道这些列。您拥有的地图与您将要获得的地图一样接近。
如果您包含想要这样做的动机,我们可能会通过其他方式帮助您实现最终目标。
假设我有一个像这样的table,
table: qa_list
id | question_id | question | answer |
---------+--------------+------------+-------------
1 | 100 | question1 | answer |
2 | 101 | question2 | answer |
3 | 102 | question3 | answer |
4 | ...
... | ...
和给出以下结果的查询(因为我找不到直接转置 table 的方法),
table: qa_map
id | qa_map
--------+---------
1 | {question1=answer,question2=answer,question3=answer, ....}
其中 qa_map 是 map_agg 任意数量的问题和答案的结果。
有没有办法 UNNEST qa_map 到任意数量的列,如下所示?
id | Question_1 | Answer_1 | Question_2 | Answer_2 | Question_3 | ....
---------+-------------+-----------+-------------+-----------+-------------+
1 | question | answer | question | answer | question | ....
AWS Athena/Presto-0.172
不,无法编写根据数据产生不同列数的查询。在查询执行开始之前必须知道这些列。您拥有的地图与您将要获得的地图一样接近。
如果您包含想要这样做的动机,我们可能会通过其他方式帮助您实现最终目标。