作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在从贝叶斯统计模型中获取样本,使用 Avro 对它们进行序列化,将它们上传到 S3,并使用 Athena 查询它们。
我需要帮助编写一个在表中取消嵌套数组的查询。
CREATE TABLE 查询如下所示:
CREATE EXTERNAL TABLE `model_posterior`(
`job_id` bigint,
`model_id` bigint,
`parents` array<struct<`feature_name`:string,`feature_value`:bigint, `is_zid`:boolean>>,
`posterior_samples` struct <`parameter`:string,`is_scaled`:boolean,`samples`:array<double>>)
WITH samples AS (
SELECT model_id, parents, sample, sample_index
FROM posterior_db.model_posterior
CROSS JOIN UNNEST(posterior_samples.samples) WITH ORDINALITY AS t (sample, sample_index)
WHERE job_id = 111000020709
)
SELECT * FROM samples
最佳答案
您可以使用 transform
功能描述 here .
假设我们有名为 samples
的表与您的问题中提到的结构。然后您可以编写如下所示的查询
SELECT *, transform(parents, parent -> parent.feature_value) as only_ feature_values
FROM samples
关于sql - 在 SQL (Athena) 中取消嵌套 : How to convert array of structs into an array of values plucked from the structs?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48472110/
我是一名优秀的程序员,十分优秀!