Skip to content

Commit

Permalink
[#6356] improve(CLI): Add tag support for model in CLI (#6360)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

 Add tag support for model in CLI.

1. `UntagEntity`
2. `TagEntity`
3. `ListEntityTags`

The logic for handling models in these three methods has been added.
need to add the processing logic to the `RemoveAllTags` method.

### Why are the changes needed?

Fix: #6356 

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

local test.
  • Loading branch information
Abyss-lord authored Feb 6, 2025
1 parent d74ce36 commit f4a0ebb
Showing 1 changed file with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,24 @@
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.cli.utils.FullNameUtil;
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.file.Fileset;
import org.apache.gravitino.file.FilesetCatalog;
import org.apache.gravitino.messaging.Topic;
import org.apache.gravitino.messaging.TopicCatalog;
import org.apache.gravitino.model.Model;
import org.apache.gravitino.model.ModelCatalog;
import org.apache.gravitino.rel.Table;
import org.apache.gravitino.rel.TableCatalog;

/* Removes all the tags of an entity. */
public class RemoveAllTags extends Command {
Expand Down Expand Up @@ -66,21 +73,54 @@ public void handle() {
try {

GravitinoClient client = buildClient(metalake);
// TODO fileset and topic
if (name.hasTableName()) {

if (name.getLevel() == 3) {
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);
Catalog catalogObject = client.loadCatalog(catalog);
switch (catalogObject.type()) {
case RELATIONAL:
entity = "table";
TableCatalog tableCatalog = catalogObject.asTableCatalog();
Table gTable = tableCatalog.loadTable(FullNameUtil.toTable(name));
tags = gTable.supportsTags().listTags();
if (tags.length > 0) {
gTable.supportsTags().associateTags(null, tags);
}
break;

case MODEL:
entity = "model";
ModelCatalog modelCatalog = catalogObject.asModelCatalog();
Model gModel = modelCatalog.getModel(FullNameUtil.toModel(name));
tags = gModel.supportsTags().listTags();
if (tags.length > 0) {
gModel.supportsTags().associateTags(null, tags);
}
break;

case FILESET:
entity = "fileset";
FilesetCatalog filesetCatalog = catalogObject.asFilesetCatalog();
Fileset gFileset = filesetCatalog.loadFileset(FullNameUtil.toFileset(name));
tags = gFileset.supportsTags().listTags();
if (tags.length > 0) {
gFileset.supportsTags().associateTags(null, tags);
}
break;

case MESSAGING:
entity = "topic";
TopicCatalog topicCatalog = catalogObject.asTopicCatalog();
Topic gTopic = topicCatalog.loadTopic(FullNameUtil.toTopic(name));
tags = gTopic.supportsTags().listTags();
if (tags.length > 0) {
gTopic.supportsTags().associateTags(null, tags);
}
break;

default:
break;
}
entity = table;
} else if (name.hasSchemaName()) {
String catalog = name.getCatalogName();
String schema = name.getSchemaName();
Expand Down

0 comments on commit f4a0ebb

Please sign in to comment.