Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#6356] improve(CLI): Add tag support for model in CLI #6360

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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