World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#9307] improvement(server): a missing partition will cause sever error (#9397)
Salmane Khalili484fb766c115
diff --git a/server/src/main/java/org/apache/gravitino/server/web/rest/PartitionOperations.java b/server/src/main/java/org/apache/gravitino/server/web/rest/PartitionOperations.javaindex b4bf0eeed4..654f401e33 100644--- a/server/src/main/java/org/apache/gravitino/server/web/rest/PartitionOperations.java+++ b/server/src/main/java/org/apache/gravitino/server/web/rest/PartitionOperations.java@@ -180,19 +180,22 @@ public class PartitionOperations {@PathParam("schema") @AuthorizationMetadata(type = Entity.EntityType.SCHEMA) String schema,@PathParam("table") @AuthorizationMetadata(type = Entity.EntityType.TABLE) String table,AddPartitionsRequest request) {- LOG.info(- "Received add {} partition(s) request for table {}.{}.{}.{} ",- request.getPartitions().length,- metalake,- catalog,- schema,- table);- Preconditions.checkArgument(- request.getPartitions().length == 1, "Only one partition is supported");+ try {+ if (request == null || request.getPartitions() == null) {+ throw new IllegalArgumentException("partitions must not be null");+ }+ LOG.info(+ "Received add {} partition(s) request for table {}.{}.{}.{} ",+ request.getPartitions().length,+ metalake,+ catalog,+ schema,+ table);+ Preconditions.checkArgument(+ request.getPartitions().length == 1, "Only one partition is supported");- request.validate();+ request.validate();- try {return Utils.doAs(httpRequest,() -> {diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestPartitionOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestPartitionOperations.javaindex 05b2a8e491..ea3dd7ec61 100644--- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestPartitionOperations.java+++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestPartitionOperations.java@@ -326,4 +326,23 @@ public class TestPartitionOperations extends JerseyTest {Assertions.assertEquals(0, noExistDropResponse.getCode());Assertions.assertFalse(noExistDropResponse.dropped());}++ @Test+ public void testAddPartitionWithNullPartitions() {+ AddPartitionsRequest invalidReq = new AddPartitionsRequest();++ Response resp =+ target(partitionPath(metalake, catalog, schema, table))+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .post(Entity.entity(invalidReq, MediaType.APPLICATION_JSON_TYPE));++ Assertions.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());++ ErrorResponse errorResponse = resp.readEntity(ErrorResponse.class);+ Assertions.assertEquals(ErrorConstants.ILLEGAL_ARGUMENTS_CODE, errorResponse.getCode());+ Assertions.assertEquals(+ IllegalArgumentException.class.getSimpleName(), errorResponse.getType());+ Assertions.assertTrue(errorResponse.getMessage().contains("partitions must not be null"));+ }}