Add glue.batch_update_partition (#3534)

* Add glue.batch_update_partition

* Fix error output for glue.batch_update_partition and add test case for non-existent partition in the batch update
This commit is contained in:
Don Kuntz 2020-12-10 14:03:37 -06:00 committed by GitHub
commit effb075b62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 142 additions and 0 deletions

View file

@ -663,6 +663,119 @@ def test_update_partition_move():
)
@mock_glue
def test_batch_update_partition():
client = boto3.client("glue", region_name="us-east-1")
database_name = "myspecialdatabase"
table_name = "myfirsttable"
values = [
["2020-12-04"],
["2020-12-05"],
["2020-12-06"],
]
new_values = [
["2020-11-04"],
["2020-11-05"],
["2020-11-06"],
]
helpers.create_database(client, database_name)
helpers.create_table(client, database_name, table_name)
batch_update_values = []
for idx, value in enumerate(values):
helpers.create_partition(client, database_name, table_name, values=value)
batch_update_values.append(
{
"PartitionValueList": value,
"PartitionInput": helpers.create_partition_input(
database_name,
table_name,
values=new_values[idx],
columns=[{"Name": "country", "Type": "string"}],
),
}
)
response = client.batch_update_partition(
DatabaseName=database_name, TableName=table_name, Entries=batch_update_values,
)
for value in values:
with pytest.raises(ClientError) as exc:
helpers.get_partition(client, database_name, table_name, value)
exc.value.response["Error"]["Code"].should.equal("EntityNotFoundException")
for value in new_values:
response = client.get_partition(
DatabaseName=database_name, TableName=table_name, PartitionValues=value
)
partition = response["Partition"]
partition["TableName"].should.equal(table_name)
partition["StorageDescriptor"]["Columns"].should.equal(
[{"Name": "country", "Type": "string"}]
)
@mock_glue
def test_batch_update_partition_missing_partition():
client = boto3.client("glue", region_name="us-east-1")
database_name = "myspecialdatabase"
table_name = "myfirsttable"
values = [
["2020-12-05"],
["2020-12-06"],
]
new_values = [
["2020-11-05"],
["2020-11-06"],
]
helpers.create_database(client, database_name)
helpers.create_table(client, database_name, table_name)
batch_update_values = []
for idx, value in enumerate(values):
helpers.create_partition(client, database_name, table_name, values=value)
batch_update_values.append(
{
"PartitionValueList": value,
"PartitionInput": helpers.create_partition_input(
database_name,
table_name,
values=new_values[idx],
columns=[{"Name": "country", "Type": "string"}],
),
}
)
# add a non-existent partition to the batch update values
batch_update_values.append(
{
"PartitionValueList": ["2020-10-10"],
"PartitionInput": helpers.create_partition_input(
database_name,
table_name,
values=["2019-09-09"],
columns=[{"Name": "country", "Type": "string"}],
),
}
)
response = client.batch_update_partition(
DatabaseName=database_name, TableName=table_name, Entries=batch_update_values,
)
response.should.have.key("Errors")
response["Errors"].should.have.length_of(1)
response["Errors"][0]["PartitionValueList"].should.equal(["2020-10-10"])
@mock_glue
def test_delete_partition():
client = boto3.client("glue", region_name="us-east-1")