Skip to content

Commit

Permalink
add update commands for fileset
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmclean committed Oct 30, 2024
1 parent 5b5453d commit 19cc513
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
import org.apache.gravitino.cli.commands.UntagEntity;
import org.apache.gravitino.cli.commands.UpdateCatalogComment;
import org.apache.gravitino.cli.commands.UpdateCatalogName;
import org.apache.gravitino.cli.commands.UpdateFilesetComment;
import org.apache.gravitino.cli.commands.UpdateFilesetName;
import org.apache.gravitino.cli.commands.UpdateMetalakeComment;
import org.apache.gravitino.cli.commands.UpdateMetalakeName;
import org.apache.gravitino.cli.commands.UpdateTagComment;
Expand Down Expand Up @@ -479,11 +481,19 @@ private void handleFilesetCommand() {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
boolean managed = line.hasOption(GravitinoOptions.MANAGED);
String location = line.getOptionValue(GravitinoOptions.LOCATION);

new CreateFileset(url, ignore, metalake, catalog, schema, fileset, comment, managed, location)
.handle();
} else if (CommandActions.DELETE.equals(command)) {
new DeleteFileset(url, ignore, metalake, catalog, schema, fileset).handle();
} else if (CommandActions.UPDATE.equals(command)) {
if (line.hasOption(GravitinoOptions.COMMENT)) {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
new UpdateFilesetComment(url, ignore, metalake, catalog, schema, fileset, comment).handle();
}
if (line.hasOption(GravitinoOptions.RENAME)) {
String newName = line.getOptionValue(GravitinoOptions.RENAME);
new UpdateFilesetName(url, ignore, metalake, catalog, schema, fileset, newName).handle();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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.NameIdentifier;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
import org.apache.gravitino.exceptions.NoSuchFilesetException;
import org.apache.gravitino.exceptions.NoSuchMetalakeException;
import org.apache.gravitino.exceptions.NoSuchSchemaException;
import org.apache.gravitino.file.FilesetChange;

/** Update the comment of a catalog. */
public class UpdateFilesetComment extends Command {

protected final String metalake;
protected final String catalog;
protected final String schema;
protected final String fileset;
protected final String comment;

/**
* Update the comment of a fileset.
*
* @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 catalog The name of the catalog.
* @param schema The name of the schema.
* @param fileset The name of the fileset.
* @param comment New metalake comment.
*/
public UpdateFilesetComment(
String url,
boolean ignoreVersions,
String metalake,
String catalog,
String schema,
String fileset,
String comment) {
super(url, ignoreVersions);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
this.fileset = fileset;
this.comment = comment;
}

/** Update the comment of a catalog. */
public void handle() {
try {
NameIdentifier filesetName = NameIdentifier.of(schema, fileset);
GravitinoClient client = buildClient(metalake);
FilesetChange change = FilesetChange.updateComment(comment);

client.loadCatalog(catalog).asFilesetCatalog().alterFileset(filesetName, change);
} 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 (NoSuchFilesetException err) {
System.err.println(ErrorMessages.UNKNOWN_FILESET);
return;
} catch (Exception exp) {
System.err.println(exp.getMessage());
return;
}

System.out.println(fileset + " comment changed.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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.NameIdentifier;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
import org.apache.gravitino.exceptions.NoSuchFilesetException;
import org.apache.gravitino.exceptions.NoSuchMetalakeException;
import org.apache.gravitino.exceptions.NoSuchSchemaException;
import org.apache.gravitino.file.FilesetChange;

/** Update the name of a fileset. */
public class UpdateFilesetName extends Command {

protected final String metalake;
protected final String catalog;
protected final String schema;
protected final String fileset;
protected final String name;

/**
* Update the name of a fileset.
*
* @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 catalog The name of the catalog.
* @param schema The name of the schema.
* @param fileset The name of the fileset.
* @param name The new metalake name.
*/
public UpdateFilesetName(
String url,
boolean ignoreVersions,
String metalake,
String catalog,
String schema,
String fileset,
String name) {
super(url, ignoreVersions);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
this.fileset = fileset;
this.name = name;
}

/** Update the name of a catalog. */
public void handle() {
try {
NameIdentifier filesetName = NameIdentifier.of(schema, fileset);
GravitinoClient client = buildClient(metalake);
FilesetChange change = FilesetChange.rename(name);
client.loadCatalog(catalog).asFilesetCatalog().alterFileset(filesetName, change);
} 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 (NoSuchFilesetException err) {
System.err.println(ErrorMessages.UNKNOWN_FILESET);
return;
} catch (Exception exp) {
System.err.println(exp.getMessage());
return;
}

System.out.println(fileset + " name changed.");
}
}

0 comments on commit 19cc513

Please sign in to comment.