use of org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry in project drill by apache.
the class CreateFunctionHandler method getPlan.
/**
* Registers UDFs dynamically. Process consists of several steps:
* <ol>
* <li>Registering jar in jar registry to ensure that several jars with the same name is not registered.</li>
* <li>Binary and source jars validation and back up.</li>
* <li>Validation against local function registry.</li>
* <li>Validation against remote function registry.</li>
* <li>Remote function registry update.</li>
* <li>Copying of jars to registry area and clean up.</li>
* </ol>
*
* UDFs registration is allowed only if dynamic UDFs support is enabled.
*
* @return - Single row indicating list of registered UDFs, or error message otherwise.
*/
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException, IOException {
if (!context.getOption(ExecConstants.DYNAMIC_UDF_SUPPORT_ENABLED).bool_val) {
throw UserException.validationError().message("Dynamic UDFs support is disabled.").build(logger);
}
RemoteFunctionRegistry remoteRegistry = context.getRemoteFunctionRegistry();
JarManager jarManager = new JarManager(sqlNode, remoteRegistry);
boolean inProgress = false;
try {
final String action = remoteRegistry.addToJars(jarManager.getBinaryName(), RemoteFunctionRegistry.Action.REGISTRATION);
if (!(inProgress = action == null)) {
return DirectPlan.createDirectPlan(context, false, String.format("Jar with %s name is used. Action: %s", jarManager.getBinaryName(), action));
}
jarManager.initRemoteBackup();
List<String> functions = validateAgainstLocalRegistry(jarManager, context.getFunctionRegistry());
initRemoteRegistration(functions, jarManager, remoteRegistry);
jarManager.deleteQuietlyFromStagingArea();
return DirectPlan.createDirectPlan(context, true, String.format("The following UDFs in jar %s have been registered:\n%s", jarManager.getBinaryName(), functions));
} catch (Exception e) {
logger.error("Error during UDF registration", e);
return DirectPlan.createDirectPlan(context, false, e.getMessage());
} finally {
if (inProgress) {
remoteRegistry.removeFromJars(jarManager.getBinaryName());
}
jarManager.cleanUp();
}
}
Aggregations