Skip to content

Commit

Permalink
Allow override/force options when add schema (apache#11572)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangfu0 authored Sep 14, 2023
1 parent 3caf9ab commit a8b5fe7
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.net.URI;
import java.util.Collections;
import org.apache.pinot.common.utils.FileUploadDownloadClient;
import org.apache.pinot.spi.auth.AuthProvider;
Expand Down Expand Up @@ -48,6 +49,14 @@ public class AddSchemaCommand extends AbstractBaseAdminCommand implements Comman
@CommandLine.Option(names = {"-schemaFile"}, required = true, description = "Path to schema file.")
private String _schemaFile = null;

@CommandLine.Option(names = {"-override"}, required = false, description = "Whether to override the schema if the "
+ "schema exists.")
private boolean _override = false;

@CommandLine.Option(names = {"-force"}, required = false, description = "Whether to force overriding the schema if "
+ "the schema exists.")
private boolean _force = false;

@CommandLine.Option(names = {"-exec"}, required = false, description = "Execute the command.")
private boolean _exec;

Expand Down Expand Up @@ -87,8 +96,8 @@ public String getName() {
@Override
public String toString() {
String retString = ("AddSchema -controllerProtocol " + _controllerProtocol + " -controllerHost " + _controllerHost
+ " -controllerPort " + _controllerPort + " -schemaFile " + _schemaFile + " -user " + _user + " -password "
+ "[hidden]");
+ " -controllerPort " + _controllerPort + " -schemaFile " + _schemaFile + " -override " + _override + " _force "
+ _force + " -user " + _user + " -password " + "[hidden]");

return ((_exec) ? (retString + " -exec") : retString);
}
Expand Down Expand Up @@ -117,6 +126,16 @@ public AddSchemaCommand setSchemaFilePath(String schemaFilePath) {
return this;
}

public AddSchemaCommand setOverride(boolean override) {
_override = override;
return this;
}

public AddSchemaCommand setForce(boolean force) {
_force = force;
return this;
}

public void setUser(String user) {
_user = user;
}
Expand Down Expand Up @@ -155,8 +174,10 @@ public boolean execute()

Schema schema = Schema.fromFile(schemaFile);
try (FileUploadDownloadClient fileUploadDownloadClient = new FileUploadDownloadClient()) {
fileUploadDownloadClient.addSchema(FileUploadDownloadClient
.getUploadSchemaURI(_controllerProtocol, _controllerHost, Integer.parseInt(_controllerPort)),
URI schemaURI = FileUploadDownloadClient
.getUploadSchemaURI(_controllerProtocol, _controllerHost, Integer.parseInt(_controllerPort));
schemaURI = new URI(schemaURI + "?override=" + _override + "?force=" + _force);
fileUploadDownloadClient.addSchema(schemaURI,
schema.getSchemaName(), schemaFile, makeAuthHeaders(makeAuthProvider(_authProvider, _authTokenUrl, _authToken,
_user, _password)), Collections.emptyList());
} catch (Exception e) {
Expand Down

0 comments on commit a8b5fe7

Please sign in to comment.