当查询包含来自多个数据库的表的连接时,如何在 boto3 中设置 QueryExecutionContext? [英] How to set QueryExecutionContext in boto3 when the query contains joining of tables from multiple databases?
问题描述
我在 python3 中使用 Boto3 包来执行 Athena 查询.来自 Boto3 的文档,我知道我可以指定查询执行上下文,即必须在其下执行查询的数据库名称.使用正确指定的查询执行上下文,我们可以从查询中省略完全限定的表名(db_name.table_name
),而只使用表名.
I am using Boto3 package in python3 to execute an Athena query. From the documentation of Boto3, I understand that I can specify a query execution context, i.e. a database name under which the query has to be executed. With a properly specified query execution context, we can omit the fully qualified table name(db_name.table_name
) from the query and instead use just the table name.
因此查询 SELECT * FROM db1.tab1
可以转换为 SELECT * FROM tab1
使用 QueryExecutionContext : {'database':'db1'}代码>
So the query SELECT * FROM db1.tab1
can be converted to SELECT * FROM tab1
with QueryExecutionContext : {'database':'db1'}
问题:我需要从 python 对 Athena 运行一个查询,它看起来像这样
The problem: I need to run a query on Athena from python which looks something like this
SELECT *
FROM ((SELECT *
FROM db1.tab1 AS Temp1)
INNER JOIN (SELECT *
FROM db2.tab2 AS Temp2)
ON temp1.id = temp2.id)
如我们所见,查询连接了来自两个不同数据库的表.如果我想从这个查询中省略数据库名称,我该如何指定 QueryExecutionContext
?
As we can see, the query joins tables from two different databases. If I want to omit the database names from this query, how do I specify the QueryExecutionContext
?
推荐答案
QueryExecutionContext 只接受一个数据库作为参数.因此,如果您想跨多个数据库运行查询,则必须将完全限定的表名与数据库一起传递.
QueryExecutionContext accepts only one database as an argument.So if you want to run a query across multiple databases then you have to pass fully qualified table name along with database.
这篇关于当查询包含来自多个数据库的表的连接时,如何在 boto3 中设置 QueryExecutionContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!