sql - aws athena 转换数组> 到餐桌
问题描述
我有一个 s3 存储桶,其中包含很多包含以下内容的文件:
{time:123456, state:{{1,2,3,4},{4,5,6,7}...}
在我使用 Athena 读取它之后,结果是具有 2 个列的数据集:第一个是 time int
,第二个是array<array<string>>
,是否可以使用 athena sql 将此表转换为:
select time, col1,col2,col3,col4
from table
当 col1...4 是数组中列的名称时?
解决方案
使用CROSS JOIN UNNEST 取消嵌套上层数组:
select a.time,
state_array[1] as col1,
state_array[2] as col2,
state_array[3] as col3,
state_array[4] as col4
from my_table a
CROSS JOIN UNNEST(state) as t(state_array)
推荐阅读
- c# - Xamarin.Android - 向布局设计器添加版本
- tensorflow - 我最近在使用 tf.frompixels 时遇到了一个错误,这是我以前没有遇到的。下面是我正在使用的代码
- javascript - 创建 ID 不相互跟随的父子树 JSON
- java - Java Swing 计时器第一个实例崩溃
- javascript - Javascript - 带有 switch 语句的石头、纸、剪刀?如果不是,有什么替代方案?
- android - Android 相当于 iOS 的“缩放填充”
- laravel - Laravel Eloquent 计算多个数据范围
- django - 如何为两因素身份验证配置 Django Authy
- sql - SQL 将范围拆分为单行
- java - 使用改造和可观察解析 REST 响应消息