我有一个 lambda,它尝试查明之前执行的 athena 查询是否返回了任何行。为此,我使用 boto3
函数 get_query_runtime_statistics然后提取“Rows”
数据:
response = athena_client.get_query_runtime_statistics(QueryExecutionId=query_id)
row_count = response["QueryRuntimeStatistics"]["Rows"]["OutputRows"]
但是,在之前的执行中,响应对象未包含“Rows”
数据,导致抛出KeyError
。我知道我可以通过使用 .get("Rows", {}).get("OutputRows")
等来解决 KeyError
问题。
我在 athena 控制台中重新运行了完全相同的查询(它返回 0 行),然后使用查询 ID 来获取此重复查询执行的运行时统计信息。这次它的响应中有“Rows”
数据。因此,对于给定的查询字符串,行为似乎不一致;但是,如果我获取原始查询执行的统计信息,响应始终不包含“Rows”
数据。
我想知道的是,每次“Rows”
数据不存在时,我是否可以假设输出行计数为零?
我在 AWS 文档中找不到任何内容来解释为什么 “Rows”
可能并不总是出现在 API 响应中。
谢谢:)
PS。如果您不想点击文档链接,这里是根据 boto3 的响应架构:{
'QueryRuntimeStatistics': {
'Timeline': {
'QueryQueueTimeInMillis': 123,
'QueryPlanningTimeInMillis': 123,
'EngineExecutionTimeInMillis': 123,
'ServiceProcessingTimeInMillis': 123,
'TotalExecutionTimeInMillis': 123
},
'Rows': {
'InputRows': 123,
'InputBytes': 123,
'OutputBytes': 123,
'OutputRows': 123
},
'OutputStage': {
'StageId': 123,
'State': 'string',
'OutputBytes': 123,
'OutputRows': 123,
'InputBytes': 123,
'InputRows': 123,
'ExecutionTime': 123,
'QueryStagePlan': {
'Name': 'string',
'Identifier': 'string',
'Children': [
{'... recursive ...'},
],
'RemoteSources': [
'string',
]
},
'SubStages': [
{'... recursive ...'},
]
}
}
}
最佳答案
我提出了支持请求并得到了以下回复:
The query finished successfully but it failed as an async process of getting runtime stats. This is an internal issue and internal team is aware about it and is working on it to fix the same.
我要求澄清此问题是否仅发生在产生零结果的查询上,这是响应:
The issue could happen regardless of the query. Also as informed by internal team, it may take approximately 15-30 days to know the root cause and fix the issue.
[于2023年2月10日发送]
我希望这对遇到此问题的其他人有所帮助:)
关于python - boto3 get_query_runtime_statistics 有时不返回 "rows"数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75299987/