use of org.apache.hadoop.hive.ql.exec.FunctionInfo.FunctionResource in project hive by apache.
the class DDLTask method describeFunction.
/**
* Shows a description of a function.
* @param db
*
* @param descFunc
* is the function we are describing
* @throws HiveException
*/
private int describeFunction(Hive db, DescFunctionDesc descFunc) throws HiveException, SQLException {
String funcName = descFunc.getName();
// write the results in the file
DataOutputStream outStream = getOutputStream(descFunc.getResFile());
try {
// get the function documentation
Description desc = null;
Class<?> funcClass = null;
FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(funcName);
if (functionInfo != null) {
funcClass = functionInfo.getFunctionClass();
}
if (funcClass != null) {
desc = AnnotationUtils.getAnnotation(funcClass, Description.class);
}
if (desc != null) {
outStream.writeBytes(desc.value().replace("_FUNC_", funcName));
if (descFunc.isExtended()) {
Set<String> synonyms = FunctionRegistry.getFunctionSynonyms(funcName);
if (synonyms.size() > 0) {
outStream.writeBytes("\nSynonyms: " + join(synonyms, ", "));
}
if (desc.extended().length() > 0) {
outStream.writeBytes("\n" + desc.extended().replace("_FUNC_", funcName));
}
}
} else {
if (funcClass != null) {
outStream.writeBytes("There is no documentation for function '" + funcName + "'");
} else {
outStream.writeBytes("Function '" + funcName + "' does not exist.");
}
}
outStream.write(terminator);
if (descFunc.isExtended()) {
if (funcClass != null) {
outStream.writeBytes("Function class:" + funcClass.getName() + "\n");
}
if (functionInfo != null) {
outStream.writeBytes("Function type:" + functionInfo.getFunctionType() + "\n");
FunctionResource[] resources = functionInfo.getResources();
if (resources != null) {
for (FunctionResource resource : resources) {
outStream.writeBytes("Resource:" + resource.getResourceURI() + "\n");
}
}
}
}
} catch (FileNotFoundException e) {
LOG.warn("describe function: ", e);
return 1;
} catch (IOException e) {
LOG.warn("describe function: ", e);
return 1;
} catch (Exception e) {
throw new HiveException(e);
} finally {
IOUtils.closeStream(outStream);
}
return 0;
}
use of org.apache.hadoop.hive.ql.exec.FunctionInfo.FunctionResource in project hive by apache.
the class TestFunctionRegistry method testIsPermanentFunction.
@Test
public void testIsPermanentFunction() throws Exception {
// Setup exprNode
GenericUDF udf = new GenericUDFCurrentTimestamp();
List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>();
ExprNodeGenericFuncDesc fnExpr = new ExprNodeGenericFuncDesc(TypeInfoFactory.timestampTypeInfo, udf, children);
assertFalse("Function not added as permanent yet", FunctionRegistry.isPermanentFunction(fnExpr));
// Now register as permanent function
FunctionResource[] emptyResources = new FunctionResource[] {};
FunctionRegistry.registerPermanentFunction("default.perm_current_timestamp", GenericUDFCurrentTimestamp.class.getName(), true, emptyResources);
assertTrue("Function should now be recognized as permanent function", FunctionRegistry.isPermanentFunction(fnExpr));
}
use of org.apache.hadoop.hive.ql.exec.FunctionInfo.FunctionResource in project hive by apache.
the class CreateFunctionOperation method createTemporaryFunction.
private int createTemporaryFunction() {
try {
// Add any required resources
FunctionResource[] resources = FunctionUtils.toFunctionResource(desc.getResources());
FunctionUtils.addFunctionResources(resources);
Class<?> udfClass = getUdfClass();
FunctionInfo registered = FunctionRegistry.registerTemporaryUDF(desc.getName(), udfClass, resources);
if (registered != null) {
return 0;
} else {
context.getConsole().printError("FAILED: Class " + desc.getClassName() + " does not implement UDF, GenericUDF, or UDAF");
return 1;
}
} catch (HiveException e) {
context.getConsole().printError("FAILED: " + e.toString());
LOG.info("create function: ", e);
return 1;
} catch (ClassNotFoundException e) {
context.getConsole().printError("FAILED: Class " + desc.getClassName() + " not found");
LOG.info("create function: ", e);
return 1;
}
}
Aggregations