forked from apache/gravitino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[apache#6242] improve(CLI): Add tag support to Models in Gravtitino CLI.
Add tag support to Models in Gravtitino CLI. currently, the CLI support untagEntity, tagEntity, listTags from a model.
- Loading branch information
1 parent
eb3fb31
commit 5394f16
Showing
7 changed files
with
318 additions
and
35 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
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
79 changes: 79 additions & 0 deletions
79
clients/cli/src/main/java/org/apache/gravitino/cli/utils/FullNameUtil.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,79 @@ | ||
/* | ||
* 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.utils; | ||
|
||
import org.apache.gravitino.NameIdentifier; | ||
import org.apache.gravitino.cli.FullName; | ||
|
||
/** Utility class for helping with creating NameIdentifiers from {@link FullName}. */ | ||
public class FullNameUtil { | ||
|
||
/** | ||
* Returns a NameIdentifier for a model. | ||
* | ||
* @param fullName the {@link FullName} of the model. | ||
* @return a NameIdentifier for the model. | ||
*/ | ||
public static NameIdentifier toModel(FullName fullName) { | ||
String schema = fullName.getSchemaName(); | ||
String model = fullName.getModelName(); | ||
|
||
return NameIdentifier.of(schema, model); | ||
} | ||
|
||
/** | ||
* Returns a NameIdentifier for a table. | ||
* | ||
* @param fullName the {@link FullName} of the table. | ||
* @return a NameIdentifier for the table. | ||
*/ | ||
public static NameIdentifier toTable(FullName fullName) { | ||
String schema = fullName.getSchemaName(); | ||
String table = fullName.getTableName(); | ||
|
||
return NameIdentifier.of(schema, table); | ||
} | ||
|
||
/** | ||
* Returns a NameIdentifier for a fileset. | ||
* | ||
* @param fullName the {@link FullName} of the fileset. | ||
* @return a NameIdentifier for the fileset. | ||
*/ | ||
public static NameIdentifier toFileset(FullName fullName) { | ||
String schema = fullName.getSchemaName(); | ||
String fileset = fullName.getFilesetName(); | ||
|
||
return NameIdentifier.of(schema, fileset); | ||
} | ||
|
||
/** | ||
* Returns a NameIdentifier for a topic. | ||
* | ||
* @param fullName the {@link FullName} of the topic. | ||
* @return a NameIdentifier for the topic. | ||
*/ | ||
public static NameIdentifier toTopic(FullName fullName) { | ||
String schema = fullName.getSchemaName(); | ||
String topic = fullName.getTopicName(); | ||
|
||
return NameIdentifier.of(schema, topic); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
clients/cli/src/test/java/org/apache/gravitino/cli/TestFullNameUtil.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,80 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.DefaultParser; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.commons.cli.ParseException; | ||
import org.apache.gravitino.NameIdentifier; | ||
import org.apache.gravitino.cli.utils.FullNameUtil; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestFullNameUtil { | ||
private Options options; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
Main.useExit = false; | ||
options = new GravitinoOptions().options(); | ||
} | ||
|
||
@Test | ||
void testToModel() throws ParseException { | ||
String[] args = {"table", "list", "-i", "--name", "Model_catalog.schema.model"}; | ||
CommandLine commandLine = new DefaultParser().parse(options, args); | ||
FullName fullName = new FullName(commandLine); | ||
NameIdentifier modelIdent = FullNameUtil.toModel(fullName); | ||
Assertions.assertEquals("model", modelIdent.name()); | ||
Assertions.assertArrayEquals(new String[] {"schema"}, modelIdent.namespace().levels()); | ||
} | ||
|
||
@Test | ||
void testToTable() throws ParseException { | ||
String[] args = {"table", "list", "-i", "--name", "Table_catalog.schema.table"}; | ||
CommandLine commandLine = new DefaultParser().parse(options, args); | ||
FullName fullName = new FullName(commandLine); | ||
NameIdentifier tableIdent = FullNameUtil.toTable(fullName); | ||
Assertions.assertEquals("table", tableIdent.name()); | ||
Assertions.assertArrayEquals(new String[] {"schema"}, tableIdent.namespace().levels()); | ||
} | ||
|
||
@Test | ||
void testToFileset() throws ParseException { | ||
String[] args = {"fileset", "list", "-i", "--name", "Fileset_catalog.schema.fileset"}; | ||
CommandLine commandLine = new DefaultParser().parse(options, args); | ||
FullName fullName = new FullName(commandLine); | ||
NameIdentifier filesetIdent = FullNameUtil.toFileset(fullName); | ||
Assertions.assertEquals("fileset", filesetIdent.name()); | ||
Assertions.assertArrayEquals(new String[] {"schema"}, filesetIdent.namespace().levels()); | ||
} | ||
|
||
@Test | ||
void testToTopic() throws ParseException { | ||
String[] args = {"topic", "list", "-i", "--name", "Topic_catalog.schema.topic"}; | ||
CommandLine commandLine = new DefaultParser().parse(options, args); | ||
FullName fullName = new FullName(commandLine); | ||
NameIdentifier topicIdent = FullNameUtil.toTopic(fullName); | ||
Assertions.assertEquals("topic", topicIdent.name()); | ||
Assertions.assertArrayEquals(new String[] {"schema"}, topicIdent.namespace().levels()); | ||
} | ||
} |
Oops, something went wrong.