Skip to content

Commit 9cd7674

Browse files
authored
[#5379] Add property commands for filesets in Gravitio CLI (#5382)
### What changes were proposed in this pull request? Added property command for filesets in the Gravitio CLI. ### Why are the changes needed? Expand coverage of Java API in Gravitino CLI. Fix: #5379 ### Does this PR introduce _any_ user-facing change? No, but it adds extra command to the Gravitino CLI. ### How was this patch tested? Compiled and tested locally.
1 parent d5aa571 commit 9cd7674

File tree

7 files changed

+430
-1
lines changed

7 files changed

+430
-1
lines changed

clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ private void handleTopicCommand() {
523523
}
524524

525525
/**
526-
* Handles the command execution for Filesets based on command type and the command line options.
526+
* Handles the command execution for filesets based on command type and the command line options.
527527
*/
528528
private void handleFilesetCommand() {
529529
String url = getUrl();
@@ -546,6 +546,16 @@ private void handleFilesetCommand() {
546546
} else if (CommandActions.DELETE.equals(command)) {
547547
boolean force = line.hasOption(GravitinoOptions.FORCE);
548548
newDeleteFileset(url, ignore, force, metalake, catalog, schema, fileset).handle();
549+
} else if (CommandActions.SET.equals(command)) {
550+
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
551+
String value = line.getOptionValue(GravitinoOptions.VALUE);
552+
newSetFilesetProperty(url, ignore, metalake, catalog, schema, fileset, property, value)
553+
.handle();
554+
} else if (CommandActions.REMOVE.equals(command)) {
555+
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
556+
newRemoveFilesetProperty(url, ignore, metalake, catalog, schema, fileset, property).handle();
557+
} else if (CommandActions.PROPERTIES.equals(command)) {
558+
newListFilesetProperties(url, ignore, metalake, catalog, schema, fileset).handle();
549559
} else if (CommandActions.UPDATE.equals(command)) {
550560
if (line.hasOption(GravitinoOptions.COMMENT)) {
551561
String comment = line.getOptionValue(GravitinoOptions.COMMENT);

clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java

+31
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.apache.gravitino.cli.commands.ListCatalogs;
5353
import org.apache.gravitino.cli.commands.ListColumns;
5454
import org.apache.gravitino.cli.commands.ListEntityTags;
55+
import org.apache.gravitino.cli.commands.ListFilesetProperties;
5556
import org.apache.gravitino.cli.commands.ListFilesets;
5657
import org.apache.gravitino.cli.commands.ListGroups;
5758
import org.apache.gravitino.cli.commands.ListIndexes;
@@ -68,6 +69,7 @@
6869
import org.apache.gravitino.cli.commands.MetalakeDetails;
6970
import org.apache.gravitino.cli.commands.OwnerDetails;
7071
import org.apache.gravitino.cli.commands.RemoveCatalogProperty;
72+
import org.apache.gravitino.cli.commands.RemoveFilesetProperty;
7173
import org.apache.gravitino.cli.commands.RemoveMetalakeProperty;
7274
import org.apache.gravitino.cli.commands.RemoveRoleFromGroup;
7375
import org.apache.gravitino.cli.commands.RemoveRoleFromUser;
@@ -78,6 +80,7 @@
7880
import org.apache.gravitino.cli.commands.SchemaDetails;
7981
import org.apache.gravitino.cli.commands.ServerVersion;
8082
import org.apache.gravitino.cli.commands.SetCatalogProperty;
83+
import org.apache.gravitino.cli.commands.SetFilesetProperty;
8184
import org.apache.gravitino.cli.commands.SetMetalakeProperty;
8285
import org.apache.gravitino.cli.commands.SetOwner;
8386
import org.apache.gravitino.cli.commands.SetSchemaProperty;
@@ -551,4 +554,32 @@ protected UpdateFilesetName newUpdateFilesetName(
551554
String rename) {
552555
return new UpdateFilesetName(url, ignore, metalake, catalog, schema, fileset, rename);
553556
}
557+
558+
protected ListFilesetProperties newListFilesetProperties(
559+
String url, boolean ignore, String metalake, String catalog, String schema, String fileset) {
560+
return new ListFilesetProperties(url, ignore, metalake, catalog, schema, fileset);
561+
}
562+
563+
protected SetFilesetProperty newSetFilesetProperty(
564+
String url,
565+
boolean ignore,
566+
String metalake,
567+
String catalog,
568+
String schema,
569+
String fileset,
570+
String property,
571+
String value) {
572+
return new SetFilesetProperty(url, ignore, metalake, catalog, schema, fileset, property, value);
573+
}
574+
575+
protected RemoveFilesetProperty newRemoveFilesetProperty(
576+
String url,
577+
boolean ignore,
578+
String metalake,
579+
String catalog,
580+
String schema,
581+
String fileset,
582+
String property) {
583+
return new RemoveFilesetProperty(url, ignore, metalake, catalog, schema, fileset, property);
584+
}
554585
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.gravitino.cli.commands;
21+
22+
import java.util.Map;
23+
import org.apache.gravitino.NameIdentifier;
24+
import org.apache.gravitino.cli.ErrorMessages;
25+
import org.apache.gravitino.client.GravitinoClient;
26+
import org.apache.gravitino.exceptions.NoSuchCatalogException;
27+
import org.apache.gravitino.exceptions.NoSuchMetalakeException;
28+
import org.apache.gravitino.exceptions.NoSuchSchemaException;
29+
import org.apache.gravitino.file.Fileset;
30+
31+
/** List the properties of a fileset. */
32+
public class ListFilesetProperties extends ListProperties {
33+
34+
protected final String metalake;
35+
protected final String catalog;
36+
protected final String schema;
37+
protected final String fileset;
38+
39+
/**
40+
* List the properties of a catalog.
41+
*
42+
* @param url The URL of the Gravitino server.
43+
* @param ignoreVersions If true don't check the client/server versions match.
44+
* @param metalake The name of the metalake.
45+
* @param catalog The name of the catalog.
46+
* @param schema The name of the schema.
47+
* @param fileset The name of the fileset.
48+
*/
49+
public ListFilesetProperties(
50+
String url,
51+
boolean ignoreVersions,
52+
String metalake,
53+
String catalog,
54+
String schema,
55+
String fileset) {
56+
super(url, ignoreVersions);
57+
this.metalake = metalake;
58+
this.catalog = catalog;
59+
this.schema = schema;
60+
this.fileset = fileset;
61+
}
62+
63+
/** List the properties of a catalog. */
64+
@Override
65+
public void handle() {
66+
Fileset gFileset = null;
67+
try {
68+
NameIdentifier name = NameIdentifier.of(schema, fileset);
69+
GravitinoClient client = buildClient(metalake);
70+
gFileset = client.loadCatalog(catalog).asFilesetCatalog().loadFileset(name);
71+
} catch (NoSuchMetalakeException err) {
72+
System.err.println(ErrorMessages.UNKNOWN_METALAKE);
73+
return;
74+
} catch (NoSuchCatalogException err) {
75+
System.err.println(ErrorMessages.UNKNOWN_CATALOG);
76+
return;
77+
} catch (NoSuchSchemaException err) {
78+
System.err.println(ErrorMessages.UNKNOWN_SCHEMA);
79+
return;
80+
} catch (Exception exp) {
81+
System.err.println(exp.getMessage());
82+
return;
83+
}
84+
85+
Map<String, String> properties = gFileset.properties();
86+
printProperties(properties);
87+
}
88+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.gravitino.cli.commands;
21+
22+
import org.apache.gravitino.NameIdentifier;
23+
import org.apache.gravitino.cli.ErrorMessages;
24+
import org.apache.gravitino.client.GravitinoClient;
25+
import org.apache.gravitino.exceptions.NoSuchCatalogException;
26+
import org.apache.gravitino.exceptions.NoSuchFilesetException;
27+
import org.apache.gravitino.exceptions.NoSuchMetalakeException;
28+
import org.apache.gravitino.exceptions.NoSuchSchemaException;
29+
import org.apache.gravitino.file.FilesetChange;
30+
31+
/** Remove a property of a fileset. */
32+
public class RemoveFilesetProperty extends Command {
33+
34+
protected final String metalake;
35+
protected final String catalog;
36+
protected final String schema;
37+
protected final String fileset;
38+
protected final String property;
39+
40+
/**
41+
* Remove a property of a fileset.
42+
*
43+
* @param url The URL of the Gravitino server.
44+
* @param ignoreVersions If true don't check the client/server versions match.
45+
* @param metalake The name of the metalake.
46+
* @param catalog The name of the catalog.
47+
* @param schema The name of the schema.
48+
* @param fileset The name of the fileset.
49+
* @param property The name of the property.
50+
*/
51+
public RemoveFilesetProperty(
52+
String url,
53+
boolean ignoreVersions,
54+
String metalake,
55+
String catalog,
56+
String schema,
57+
String fileset,
58+
String property) {
59+
super(url, ignoreVersions);
60+
this.metalake = metalake;
61+
this.catalog = catalog;
62+
this.schema = schema;
63+
this.fileset = fileset;
64+
this.property = property;
65+
}
66+
67+
/** Remove a property of a fileset. */
68+
@Override
69+
public void handle() {
70+
try {
71+
NameIdentifier name = NameIdentifier.of(schema, fileset);
72+
GravitinoClient client = buildClient(metalake);
73+
FilesetChange change = FilesetChange.removeProperty(property);
74+
client.loadCatalog(catalog).asFilesetCatalog().alterFileset(name, change);
75+
} catch (NoSuchMetalakeException err) {
76+
System.err.println(ErrorMessages.UNKNOWN_METALAKE);
77+
return;
78+
} catch (NoSuchCatalogException err) {
79+
System.err.println(ErrorMessages.UNKNOWN_CATALOG);
80+
return;
81+
} catch (NoSuchSchemaException err) {
82+
System.err.println(ErrorMessages.UNKNOWN_SCHEMA);
83+
return;
84+
} catch (NoSuchFilesetException err) {
85+
System.err.println(ErrorMessages.UNKNOWN_FILESET);
86+
return;
87+
} catch (Exception exp) {
88+
System.err.println(exp.getMessage());
89+
return;
90+
}
91+
92+
System.out.println(property + " property removed.");
93+
}
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.gravitino.cli.commands;
21+
22+
import org.apache.gravitino.NameIdentifier;
23+
import org.apache.gravitino.cli.ErrorMessages;
24+
import org.apache.gravitino.client.GravitinoClient;
25+
import org.apache.gravitino.exceptions.NoSuchCatalogException;
26+
import org.apache.gravitino.exceptions.NoSuchFilesetException;
27+
import org.apache.gravitino.exceptions.NoSuchMetalakeException;
28+
import org.apache.gravitino.exceptions.NoSuchSchemaException;
29+
import org.apache.gravitino.file.FilesetChange;
30+
31+
/** Set a property of a fileset. */
32+
public class SetFilesetProperty extends Command {
33+
34+
protected final String metalake;
35+
protected final String catalog;
36+
protected final String schema;
37+
protected final String fileset;
38+
protected final String property;
39+
protected final String value;
40+
41+
/**
42+
* Set a property of a schema.
43+
*
44+
* @param url The URL of the Gravitino server.
45+
* @param ignoreVersions If true don't check the client/server versions match.
46+
* @param metalake The name of the metalake.
47+
* @param catalog The name of the catalog.
48+
* @param schema The name of the schema.
49+
* @param fileset The name of the fileset.
50+
* @param property The name of the property.
51+
* @param value The value of the property.
52+
*/
53+
public SetFilesetProperty(
54+
String url,
55+
boolean ignoreVersions,
56+
String metalake,
57+
String catalog,
58+
String schema,
59+
String fileset,
60+
String property,
61+
String value) {
62+
super(url, ignoreVersions);
63+
this.metalake = metalake;
64+
this.catalog = catalog;
65+
this.schema = schema;
66+
this.fileset = fileset;
67+
this.property = property;
68+
this.value = value;
69+
}
70+
71+
/** Set a property of a fileset. */
72+
@Override
73+
public void handle() {
74+
try {
75+
NameIdentifier name = NameIdentifier.of(schema, fileset);
76+
GravitinoClient client = buildClient(metalake);
77+
FilesetChange change = FilesetChange.setProperty(property, value);
78+
client.loadCatalog(catalog).asFilesetCatalog().alterFileset(name, change);
79+
} catch (NoSuchMetalakeException err) {
80+
System.err.println(ErrorMessages.UNKNOWN_METALAKE);
81+
return;
82+
} catch (NoSuchCatalogException err) {
83+
System.err.println(ErrorMessages.UNKNOWN_CATALOG);
84+
return;
85+
} catch (NoSuchSchemaException err) {
86+
System.err.println(ErrorMessages.UNKNOWN_SCHEMA);
87+
return;
88+
} catch (NoSuchFilesetException err) {
89+
System.err.println(ErrorMessages.UNKNOWN_FILESET);
90+
return;
91+
} catch (Exception exp) {
92+
System.err.println(exp.getMessage());
93+
return;
94+
}
95+
96+
System.out.println(schema + " property set.");
97+
}
98+
}

0 commit comments

Comments
 (0)