Che*_*rry 6 amazon-web-services aws-glue
AWS 爬网程序具有用于添加新表的前缀属性。因此,如果我将前缀留空并启动爬虫,s3://my-bucket/some-table-backup它会创建名称为的表some-table-backup。有没有办法将其重命名为my-awesome-table并保持爬虫更新重命名的表?或者设置爬虫以创建具有提供名称的新表?
不可能设置爬虫来执行此操作,但创建一个新表的速度非常快,该新表在各方面都与爬虫创建的表相同,除了名称之外。在Python中:
import boto3
database_name = "database"
table_name = "prefix-dir_name"
new_table_name = "more_awesome_name"
client = boto3.client("glue")
response = client.get_table(DatabaseName=database_name, Name=table_name)
table_input = response["Table"]
table_input["Name"] = new_table_name
# Delete keys that cause create_table to fail
table_input.pop("CreatedBy")
table_input.pop("CreateTime")
table_input.pop("UpdateTime")
table_input.pop("DatabaseName")
table_input.pop("IsRegisteredWithLakeFormation")
catalog_id = table_input.pop("CatalogId")
client.create_table(
DatabaseName=database_name,
TableInput=table_input,
CatalogId=catalog_id
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4008 次 |
| 最近记录: |