[英]Boto3 Athena are not showing all tables
trying to get a list of table names in Athena Table using BOTO3 python.尝试使用 BOTO3 python 获取 Athena 表中的表名列表。
this is my code;这是我的代码; I think my attempts to do paginator is not correct.
我认为我尝试做分页器是不正确的。 Any help is appreciated
任何帮助表示赞赏
import boto3
client = boto3.client('glue')
responseGetDatabases = client.get_databases()
databaseList = responseGetDatabases['DatabaseList']
for databaseDict in databaseList:
databaseName = databaseDict['Name']
if "dbName_" in databaseName:
print '\ndatabaseName: ' + databaseName
responseGetTables = client.get_tables( DatabaseName = databaseName )
paginator = client.get_paginator(['TableList'])
for page in paginator:
tableList = responseGetTables['TableList']
for tables in tableList:
print tables['Name']
The get_paginator function parameter must be the name of the operation. get_paginator 函数参数必须是操作的名称。 It looks like you're trying to paginate on the
get_tables
function so看起来您正在尝试对
get_tables
函数进行分页,因此
paginator = client.get_paginator(['TableList'])
should be:应该:
paginator = client.get_paginator('get_tables')
Once you have the paginator object, you need to call paginator.paginate
to retrieve the iterator.一旦你有了 paginator 对象,你需要调用
paginator.paginate
来检索迭代器。 You can send your database parameters like so:您可以像这样发送数据库参数:
page_iterator = paginator.paginate(
DatabaseName=databaseDict['Name'],
PaginationConfig={
'MaxItems': 123,
'PageSize': 123,
'StartingToken': 'string'
}
)
See the documention for this function here .请在此处查看此功能的文档。
Now that you have the iterator, you can call a for loop by enumerating on it:现在你有了迭代器,你可以通过枚举来调用 for 循环:
for page_index, page in enumerate(page_iterator):
Here's a full working example on how to do it using paginator.这是一个完整的工作示例,说明如何使用分页器进行操作。
Remember to provide region_name
and database_name
.请记住提供
region_name
和database_name
。
import boto3
region_name = '<PROVIDE_AWS_REGION_NAME>'
database_name = '<PROVIDE_YOUR_DATABASE_NAME>'
catalog_name = 'AwsDataCatalog'
athena = boto3.client('athena', region_name=region_name)
paginator = athena.get_paginator('list_table_metadata')
response_iterator = paginator.paginate(
CatalogName=catalog_name,
DatabaseName=database_name
)
table_names = []
for page in response_iterator:
table_names.extend(
(i['Name'] for i in page['TableMetadataList'])
)
print(table_names)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.