运行AWS Athena的information_schema查询时出现GENERIC_INTERNAL_ERROR报错
报错信息
Your query has the following error(s): GENERIC_INTERNAL_ERROR: java.lang.RuntimeException: java.lang.InterruptedException: sleep interrupted This query ran against the "default" database, unless qualified by the query. Please post the error message on our forum or contact customer support with Query Id: 277863e6-3f46-49a0-894b-e712cd49f9c0.
原始执行SQL
SELECT t.table_schema, t.table_name, c.column_name, c.is_nullable, c.data_type FROM information_schema.schemata s INNER JOIN information_schema.tables t on s.schema_name = t.table_schema INNER JOIN information_schema.columns c on c.table_name = t.table_name AND c.table_schema = t.table_schema WHERE c.table_catalog = 'awsdatacatalog'
错误原因
该报错是Athena查询系统元数据表的常见问题,根因是SQL一次性关联拉取的元数据量过大,超出了Athena内部默认的查询时间限制,触发了系统主动中断查询的机制。报错中显示的default是当前会话默认绑定的数据库,会随选中的库自动变更,和报错根因无关。
解决方案
1. 简化SQL删除无效关联
当前SQL里information_schema.schemata表的关联完全多余,你需要的所有字段都可以从columns表直接获取,优化后的最简SQL如下:
SELECT table_schema, table_name, column_name, is_nullable, data_type FROM information_schema.columns WHERE table_catalog = 'awsdatacatalog' -- 可选:按需添加库名过滤缩小扫描范围 -- AND table_schema IN ('目标库名1', '目标库名2')
如果需要关联tables表做过滤(比如仅查询普通表排除视图),可以简化为两表关联:
SELECT t.table_schema, t.table_name, c.column_name, c.is_nullable, c.data_type FROM information_schema.tables t INNER JOIN information_schema.columns c ON c.table_name = t.table_name AND c.table_schema = t.table_schema WHERE c.table_catalog = 'awsdatacatalog'
2. 增加过滤条件缩小扫描范围
如果不需要拉取全账户所有库表的字段元数据,在WHERE条件中增加table_schema的过滤规则,仅查询目标数据库,能大幅降低元数据扫描量,避免超时。
3. 大数量级元数据拆分查询
如果确实需要拉取全量元数据,拆分查询逻辑:先执行SELECT schema_name FROM information_schema.schemata拿到所有库名,再逐个库查询该库下的表字段信息,避免单次请求拉取数据量过大。
4. 联系AWS支持调整阈值
如果优化SQL后仍触发报错,复制报错中的Query ID提交AWS工单,申请调整Athena元数据查询的超时阈值,同时可让后台排查是否存在Glue Data Catalog的元数据异常。
内容的提问来源于stack exchange,提问作者Matt
相关产品推荐
相关产品推荐

