首页 > 解决方案 > 如何使用 ETL (AWS Glue) 聚合数据,以便我们可以使用 Athena 通过特定属性仅选择一部分数据

问题描述

如果有更好的地方可以问这类问题,请告诉我。

我有一个存储和尝试阅读文档的服务。对于每个文档,该服务都会以一定的信心提取和读取行和单词。

单个文档(ETL 前)的有效负载如下所示

{
        "Blocks": [
            {
                "Type": "LINE",
                "Confidence": 90
                "Value": "this is a sentence"
                ...
            },
            {
                "Type": "WORD",
                "Confidence": 99
                "Value": "this"
                ...
            },
            {
                "Type": "WORD",
                "Confidence": 97
                "Value": "is"
                ...
            },
            {
                "Type": "WORD",
                "Confidence": 89
                "Value": "a"
                ...
            },
            {
                "Type": "WORD",
                "Confidence": 99
                "Value": "sentence"
                ...
            },
            {
                "Type": "WORD",
                "Confidence": 50
            },
            {
                "Type": "LINE",
                "Confidence": 90
                "Value": "example of another line"
                ...
            },
            ...
        ]
    }

我正在为 ETL 聚合函数寻找高级算法或想法,这样我就可以使用 Athena 进行查询,这会给我类似的东西

“给我所有 30% 单词置信度 > 60 的文档”

标签: pysparkbigdataetlaws-glueamazon-athena

解决方案


您不需要 etl,雅典娜可以原生读取 json,请参阅

https://docs.aws.amazon.com/athena/latest/ug/querying-JSON.html

在您创建表之后,您需要为您的任务编写正确的查询。你的陈述“给我所有的文档,其中 x% 的单词有一些信任”是非常标准的。细节取决于你如何定义你的表列,但你可以这样做:

SELECT docid from mytable group by docid
 having count_if(confidende>60)* 1./count(*) > 0.3

推荐阅读