Amazon web services 如何设置已爬网表的名称?
AWS爬虫具有用于添加新表的prefix属性。所以,如果我将前缀保留为空并启动爬虫程序到Amazon web services 如何设置已爬网表的名称?,amazon-web-services,aws-glue,Amazon Web Services,Aws Glue,AWS爬虫具有用于添加新表的prefix属性。所以,如果我将前缀保留为空并启动爬虫程序到s3://my bucket/some table backup,它将创建名为some table backup的表。有没有办法将其重命名为my awesome table,并让爬虫不断更新重命名后的表?或者设置爬虫程序以使用提供的名称创建新表?不可能设置爬虫程序来执行此操作,但创建一个与爬虫程序创建的表在各个方面都相同的新表(名称除外)的速度非常快。在: 正如dan提到的,爬虫程序无法重命名表。要么在粘合作
s3://my bucket/some table backup
,它将创建名为some table backup
的表。有没有办法将其重命名为my awesome table
,并让爬虫不断更新重命名后的表?或者设置爬虫程序以使用提供的名称创建新表?不可能设置爬虫程序来执行此操作,但创建一个与爬虫程序创建的表在各个方面都相同的新表(名称除外)的速度非常快。在:
正如dan提到的,爬虫程序无法重命名表。要么在粘合作业中使用python脚本重命名,要么在AmazonAthena中创建一个新的外部配置单元表,并将其指向旧表的位置 遇到了同样的问题。需要删除比Dan Hook答案中更多的属性,然后才能在红移中查询表
table_input="$(aws glue --region us-west-2 get-table --database-name database --name old_table --query 'Table' | jq '{Name: "new_table", StorageDescriptor, TableType, Parameters}')"
aws glue create-table --region us-west-2 --database-name database --table-input "$table_input"
aws glue delete-table --region us-west-2 --database-name database --name "old_table"
Dan解决方案的扩展,但使用分区表
import boto3
database_name = "some_database"
table_name = "old_table_name"
new_table_name = "new_table_name"
client = boto3.client("glue", region_name='us-east-1')
response = client.get_table(DatabaseName=database_name, Name=table_name)
partitions = client.get_partitions(DatabaseName=database_name, TableName=table_name)["Partitions"]
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")
# Delete unnecessary keys in partitions
for partition in partitions:
partition.pop("DatabaseName")
partition.pop("TableName")
partition.pop("CreationTime")
# Create new table table
client.create_table(DatabaseName=database_name, TableInput=table_input)
# Create partitions
client.batch_create_partition(DatabaseName=database_name, TableName=new_table_name, PartitionInputList=partitions)
这是一个很好的方法,但这不适用于分区表。
import boto3
database_name = "some_database"
table_name = "old_table_name"
new_table_name = "new_table_name"
client = boto3.client("glue", region_name='us-east-1')
response = client.get_table(DatabaseName=database_name, Name=table_name)
partitions = client.get_partitions(DatabaseName=database_name, TableName=table_name)["Partitions"]
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")
# Delete unnecessary keys in partitions
for partition in partitions:
partition.pop("DatabaseName")
partition.pop("TableName")
partition.pop("CreationTime")
# Create new table table
client.create_table(DatabaseName=database_name, TableInput=table_input)
# Create partitions
client.batch_create_partition(DatabaseName=database_name, TableName=new_table_name, PartitionInputList=partitions)