From f114cf6c8f9dbb637dac7ceecbf4cf5a405a0f67 Mon Sep 17 00:00:00 2001 From: mchades Date: Tue, 23 Apr 2024 20:45:21 +0800 Subject: [PATCH] [#3140] docs(partition): add docs and OAS for drop partition operation (#3141) ### What changes were proposed in this pull request? add docs and OAS for drop partition operation ### Why are the changes needed? Fix: #3140 ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? no --- .../manage-table-partition-using-gravitino.md | 54 ++++++++++++++++--- docs/open-api/partitions.yaml | 25 +++++++++ docs/open-api/tables.yaml | 11 ++++ 3 files changed, 83 insertions(+), 7 deletions(-) diff --git a/docs/manage-table-partition-using-gravitino.md b/docs/manage-table-partition-using-gravitino.md index 3b9ab3a5964..2b44a1a1d2c 100644 --- a/docs/manage-table-partition-using-gravitino.md +++ b/docs/manage-table-partition-using-gravitino.md @@ -19,13 +19,13 @@ Although many catalogs inherently manage partitions automatically, there are sce The following table shows the partition operations supported across various catalogs in Gravitino: -| Operation | Hive catalog | Iceberg catalog | Jdbc-Mysql catalog | Jdbc-PostgreSQL catalog | -|-----------------------|-------------------------------------------------------------------------------|-------------------------------------------------------------------------------|--------------------|-------------------------| -| Add Partition | ✔ | ✘ | ✘ | ✘ | -| Get Partition by Name | ✔ | ✘ | ✘ | ✘ | -| List Partition Names | ✔ | ✘ | ✘ | ✘ | -| List Partitions | ✔ | ✘ | ✘ | ✘ | -| Drop Partition | 🚀([Coming Soon](https://github.com/datastrato/gravitino/issues/1655)) | 🚀([Coming Soon](https://github.com/datastrato/gravitino/issues/1655)) | ✘ | ✘ | +| Operation | Hive catalog | Iceberg catalog | Jdbc-Mysql catalog | Jdbc-PostgreSQL catalog | +|-----------------------|--------------|-------------------------------------------------------------------------------|--------------------|-------------------------| +| Add Partition | ✔ | ✘ | ✘ | ✘ | +| Get Partition by Name | ✔ | ✘ | ✘ | ✘ | +| List Partition Names | ✔ | ✘ | ✘ | ✘ | +| List Partitions | ✔ | ✘ | ✘ | ✘ | +| Drop Partition | ✔ | 🚀([Coming Soon](https://github.com/datastrato/gravitino/issues/1655)) | ✘ | ✘ | :::tip[WELCOME FEEDBACK] If you need additional partition management support for a specific catalog, please feel free to [create an issue](https://github.com/datastrato/gravitino/issues/new/choose) on the [Gravitino repository](https://github.com/datastrato/gravitino). @@ -374,5 +374,45 @@ Partition[] partitions = .listPartitions(); ``` + + + +### Drop a partition by name + +You can drop a partition by its name via sending a `DELETE` request to the `/api/metalakes/{metalake_name}/catalogs/{catalog_name}/schemas/{schema_name}/tables/{partitioned_table_name}/partitions/{partition_name}` endpoint or by using the Gravitino Java client. +The following is an example of dropping a partition by its name: + + + + +```shell +curl -X DELETE -H "Accept: application/vnd.gravitino.v1+json" \ +-H "Content-Type: application/json" \ +http://localhost:8090/api/metalakes/metalake/catalogs/catalog/schemas/schema/tables/table/partitions/p20200321 +``` + +:::tip +If the partition name contains special characters, you should use [URL encoding](https://en.wikipedia.org/wiki/Percent-encoding#Reserved_characters). For example, if the partition name is `dt=2008-08-08/country=us` you should use `dt%3D2008-08-08%2Fcountry%3Dus` in the URL. +::: + + + + +```java +GravitinoClient gravitinoClient = GravitinoClient + .builder("http://127.0.0.1:8090") + .withMetalake("metalake") + .build(); + +// Assume that you have a partitioned table named "metalake.catalog.schema.table". +Partition Partition = + gravitinoClient + .loadCatalog(NameIdentifier.of("metalake", "catalog")) + .asTableCatalog() + .loadTable(NameIdentifier.of("metalake", "catalog", "schema", "table")) + .supportPartitions() + .dropPartition("partition_name"); +``` + \ No newline at end of file diff --git a/docs/open-api/partitions.yaml b/docs/open-api/partitions.yaml index dc4d7cce444..fc40b98ff57 100644 --- a/docs/open-api/partitions.yaml +++ b/docs/open-api/partitions.yaml @@ -105,6 +105,22 @@ paths: "5xx": $ref: "./openapi.yaml#/components/responses/ServerErrorResponse" + delete: + tags: + - partition + summary: Drop partition by name + operationId: dropPartition + description: Drops the specified partition + parameters: + - $ref: "#/components/parameters/purge" + responses: + "200": + $ref: "./openapi.yaml#/components/responses/DropResponse" + "400": + $ref: "./openapi.yaml#/components/responses/BadRequestErrorResponse" + "5xx": + $ref: "./openapi.yaml#/components/responses/ServerErrorResponse" + components: parameters: @@ -117,6 +133,15 @@ components: type: boolean default: false + purge: + name: purge + in: query + description: Purge the partition data + required: false + schema: + type: boolean + default: false + partition: name: partition in: path diff --git a/docs/open-api/tables.yaml b/docs/open-api/tables.yaml index abbbfbd12d4..e0e116c0f2d 100644 --- a/docs/open-api/tables.yaml +++ b/docs/open-api/tables.yaml @@ -141,6 +141,8 @@ paths: - table summary: Drop table operationId: dropTable + parameters: + - $ref: "#/components/parameters/purge" responses: "200": $ref: "./openapi.yaml#/components/responses/DropResponse" @@ -151,6 +153,15 @@ paths: components: + parameters: + purge: + name: purge + in: query + description: Removes both the metadata and the directory associated with the table completely and skipping trash. + required: false + schema: + type: boolean + default: false schemas: TableCreateRequest: