-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#5529] [Improvement] Remove all tags from an entity in the Gravitino…
… CLI. #5529 (#5787) What changes were proposed in this pull request? remove all tags from an entity in the Gravitino CLI. Close: #5529 Does this PR introduce any user-facing change? Yes, it enhances the tag -remove option to allow deleting all tags of an entity How was this patch tested? Follow the instructions in the [cli README](https://github.com/apache/gravitino/tree/main/clients/cli) to build the CLI sub-project. Start the Gravitino Playground. To test, use a command like the following: ``` gcli tag --remove --name catalogName ``` ![WhatsApp Image 2024-12-06 at 13 12 14](https://github.com/user-attachments/assets/4cc6fa44-a10c-4343-93e3-56274ccf32b8)
- Loading branch information
1 parent
20b7960
commit 2d160d1
Showing
5 changed files
with
173 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveAllTags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.gravitino.cli.commands; | ||
|
||
import org.apache.gravitino.Catalog; | ||
import org.apache.gravitino.NameIdentifier; | ||
import org.apache.gravitino.Schema; | ||
import org.apache.gravitino.cli.AreYouSure; | ||
import org.apache.gravitino.cli.ErrorMessages; | ||
import org.apache.gravitino.cli.FullName; | ||
import org.apache.gravitino.client.GravitinoClient; | ||
import org.apache.gravitino.exceptions.NoSuchCatalogException; | ||
import org.apache.gravitino.exceptions.NoSuchMetalakeException; | ||
import org.apache.gravitino.exceptions.NoSuchSchemaException; | ||
import org.apache.gravitino.exceptions.NoSuchTableException; | ||
import org.apache.gravitino.rel.Table; | ||
|
||
/* Removes all the tags of an entity. */ | ||
public class RemoveAllTags extends Command { | ||
|
||
protected String metalake; | ||
protected FullName name; | ||
protected final boolean force; | ||
|
||
/** | ||
* Removes all the tags of an entity | ||
* | ||
* @param url The URL of the Gravitino server. | ||
* @param ignoreVersions If true don't check the client/server versions match. | ||
* @param metalake The name of the metalake. | ||
* @param name The name of the entity. | ||
* @param force Force operation. | ||
*/ | ||
public RemoveAllTags( | ||
String url, boolean ignoreVersions, String metalake, FullName name, boolean force) { | ||
super(url, ignoreVersions); | ||
this.metalake = metalake; | ||
this.name = name; | ||
this.force = force; | ||
} | ||
|
||
@Override | ||
public void handle() { | ||
if (!AreYouSure.really(force)) { | ||
return; | ||
} | ||
String entity = "unknown"; | ||
String[] tags = new String[0]; | ||
try { | ||
|
||
GravitinoClient client = buildClient(metalake); | ||
// TODO fileset and topic | ||
if (name.hasTableName()) { | ||
String catalog = name.getCatalogName(); | ||
String schema = name.getSchemaName(); | ||
String table = name.getTableName(); | ||
Table gTable = | ||
client | ||
.loadCatalog(catalog) | ||
.asTableCatalog() | ||
.loadTable(NameIdentifier.of(schema, table)); | ||
tags = gTable.supportsTags().listTags(); | ||
if (tags.length > 0) { | ||
gTable.supportsTags().associateTags(null, tags); | ||
} | ||
entity = table; | ||
} else if (name.hasSchemaName()) { | ||
String catalog = name.getCatalogName(); | ||
String schema = name.getSchemaName(); | ||
Schema gSchema = client.loadCatalog(catalog).asSchemas().loadSchema(schema); | ||
tags = gSchema.supportsTags().listTags(); | ||
if (tags.length > 0) { | ||
gSchema.supportsTags().associateTags(null, tags); | ||
} | ||
entity = schema; | ||
} else if (name.hasCatalogName()) { | ||
String catalog = name.getCatalogName(); | ||
Catalog gCatalog = client.loadCatalog(catalog); | ||
tags = gCatalog.supportsTags().listTags(); | ||
if (tags.length > 0) { | ||
gCatalog.supportsTags().associateTags(null, tags); | ||
} | ||
entity = catalog; | ||
} | ||
} catch (NoSuchMetalakeException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_METALAKE); | ||
return; | ||
} catch (NoSuchCatalogException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_CATALOG); | ||
return; | ||
} catch (NoSuchSchemaException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_SCHEMA); | ||
return; | ||
} catch (NoSuchTableException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_TABLE); | ||
return; | ||
} catch (Exception exp) { | ||
System.err.println(exp.getMessage()); | ||
return; | ||
} | ||
|
||
if (tags.length > 0) { | ||
System.out.println( | ||
entity + " removed tags " + String.join(",", tags) + " now tagged with nothing"); | ||
} else { | ||
System.out.println(entity + " has no tags"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters