Athena/Presto - UNNEST MAP to columns



假设我有一个这样的表,

表:qa_list

id   |  question_id |  question  | answer    |  
---------+--------------+------------+-------------
1    |  100         |  question1 | answer    |  
2    |  101         |  question2 | answer    |  
3    |  102         |  question3 | answer    |  
4    |  ... 
...  |  ...

以及一个给出以下结果的查询(因为我找不到直接的方法来转换表(,

表:qa_map

id   |  qa_map
--------+---------
1   | {question1=answer,question2=answer,question3=answer, ....}

其中qa_map是任意数量的问题和答案的map_agg的结果。

是否有方法将qa_map取消嵌套到任意数量的列,如下所示?

id   |  Question_1 |  Answer_1 |  Question_2 |  Answer_2 |  Question_3 | ....
---------+-------------+-----------+-------------+-----------+-------------+
1    |  question   | answer    |  question   | answer    |  question   | ....

AWS Athena/Presto-0.172

不,没有办法编写一个根据数据产生不同列数的查询。在开始执行查询之前,列必须是已知的。你所拥有的地图和你要得到的一样近。

如果你包含了想要这样做的动机,我们可能会通过其他方式帮助你实现最终目标。

最新更新