【以下的问题经过翻译处理】 我正在尝试使用 AWS Data Wrangler 运行 Athena 查询,该查询失败并出现错误,指示无法解析列。但是,当我在 Athena 控制台中查看失败的查询并在那里重新运行时,没有出现任何错误。我觉得它与表名或列名的格式有关,但我一直未能找到解决方法。当我尝试使用 vanilla boto3 进行相同的查询时,同样失败并出现相同的错误。下面是失败的代码示例,随后在控制台中运行了相同的成功查询。 (为了安全起见,一些名字被匿名化了)更奇怪的是,如果我删除 JOIN部分 ,它将错误指示无法解析选择中的第一列,但相同的查询在控制台中依然成功运行。
Python代码
import awswrangler as wr
query = """
SELECT
t1.description,
t1.model_number as model,
t1.p_id as p_id,
t1.created_at as createdAt,
t1.updated_at as updatedAt,
t3.description as platform,
t2.name as module
FROM
database_with_underscores.first_table t1
LEFT JOIN
database_with_underscores.other_table t2
ON
t2.id = t1.module_id
LEFT JOIN
database_with_underscores.lasttable t3
ON
t1.platform_id = t3.id
"""
df = wr.athena.read_sql_query(query, workgroup="primary", database="database_with_underscores")
Python 运行结果
awswrangler.exceptions.QueryFailed: SYNTAX_ERROR: line 19:5: Column 't2.id' cannot be resolved
AWS Athena 控制台运行如下SQL
SELECT
t1.description,
t1.model_number as model,
t1.p_id as p_id,
t1.created_at as createdAt,
t1.updated_at as updatedAt,
t3.description as platform,
t2.name as module
FROM
database_with_underscores.first_table t1
LEFT JOIN
database_with_underscores.other_table t2
ON
t2.id = t1.module_id
LEFT JOIN
database_with_underscores.lasttable t3
ON
t1.platform_id = t3.id
Athena控制台运行结果
Successful
这里我有一个类似问题的链接,同样是,相同的查询,但一个成功,另一个失败 https://imgur.com/a/V9QSbIn