private static FunctionInfo handleCastForParameterizedType(TypeInfo ti, FunctionInfo fi) { SettableUDF udf = (SettableUDF) fi.getGenericUDF(); try { udf.setTypeInfo(ti); } catch (UDFArgumentException e) { throw new RuntimeException(e); } return new FunctionInfo( fi.getFunctionType(), fi.getDisplayName(), (GenericUDF) udf, fi.getResources()); }
/** * Get the Class of the UDF. */ public Class<?> getFunctionClass() { if (isGenericUDF()) { if (genericUDF instanceof GenericUDFBridge) { return ((GenericUDFBridge) genericUDF).getUdfClass(); } else { return genericUDF.getClass(); } } else if (isGenericUDAF()) { if (genericUDAFResolver instanceof GenericUDAFBridge) { return ((GenericUDAFBridge) genericUDAFResolver).getUDAFClass(); } else { return genericUDAFResolver.getClass(); } } else if (isGenericUDTF()) { return genericUDTF.getClass(); } if(isTableFunction()) { return this.tableFunctionResolver; } return null; }
if ((!isNative && function.isBuiltIn()) || (isNative && !function.isNative())) { throw new RuntimeException("Function " + functionName + " is not for this registry"); FunctionInfo prev = mFunctions.get(functionName); if (prev != null) { if (isBuiltInFunc(prev.getFunctionClass())) { String message = String.format("Function (%s / %s) is hive builtin function, which cannot be overridden.", functionName, prev.getFunctionClass()); LOG.debug(message); throw new RuntimeException(message); prev.discarded(); if (function.isBuiltIn()) { builtIns.add(function.getFunctionClass()); } else if (function.isPersistent() && !isNative) {
public static TableFunctionResolver getTableFunctionResolver(String functionName) throws SemanticException { FunctionInfo tfInfo = getFunctionInfo(functionName); if (tfInfo != null && tfInfo.isTableFunction()) { return (TableFunctionResolver) ReflectionUtils.newInstance(tfInfo.getFunctionClass(), null); } return null; }
private Class<?> getPermanentUdfClass(FunctionInfo function) { Class<?> functionClass = function.getFunctionClass(); if (functionClass == null) { // Expected for permanent UDFs at this point. ClassLoader loader = Utilities.getSessionSpecifiedClassLoader(); try { functionClass = Class.forName(function.getClassName(), true, loader); } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } } return functionClass; }
functionInfo.getDisplayName(), // FUNCTION_NAME "", // REMARKS (functionInfo.isGenericUDTF() ? DatabaseMetaData.functionReturnsTable
private static FunctionInfo handleCastForParameterizedType(TypeInfo ti, FunctionInfo fi) { SettableUDF udf = (SettableUDF) fi.getGenericUDF(); try { udf.setTypeInfo(ti); } catch (UDFArgumentException e) { throw new RuntimeException(e); } return new FunctionInfo( fi.isNative(), fi.getDisplayName(), (GenericUDF) udf, fi.getResources()); }
/** * A shortcut to get the "index" GenericUDF. This is used for getting elements * out of array and getting values out of map. * @throws SemanticException */ public static GenericUDF getGenericUDFForIndex() { try { return FunctionRegistry.getFunctionInfo("index").getGenericUDF(); } catch (SemanticException e) { throw new RuntimeException("hive operator -- never be thrown", e); } }
/** * Verify that UDF not in whitelist can't be accessed * @throws Exception */ @Test (expected=SemanticException.class) public void testUdfNotInWhiteList() throws Exception { Set<String> funcNames = FunctionRegistry.getFunctionNames(); funcNames.remove("reflect"); FunctionRegistry.setupPermissionsForBuiltinUDFs(funcNames.toString(), ""); assertEquals("reflect", FunctionRegistry.getFunctionInfo("reflect").getDisplayName()); }
String funcName = TypeCheckProcFactory.DefaultExprProcessor.getFunctionText(expr, true); FunctionInfo fi = FunctionRegistry.getFunctionInfo(funcName); if (fi != null && fi.getGenericUDTF() != null) { LOG.debug("Find UDTF " + funcName); genericUDTF = fi.getGenericUDTF(); genericUDTFName = funcName; if (!fi.isNative()) { unparseTranslator.addIdentifierTranslation((ASTNode) expr.getChild(0));
GenericUDF genericUDF = fi.getGenericUDF(); if (!fi.isNative()) { ctx.getUnparseTranslator().addIdentifierTranslation( (ASTNode) expr.getChild(0));
if (!fi.isNative()) { ctx.getUnparseTranslator().addIdentifierTranslation( (ASTNode) expr.getChild(0)); if (fi.getGenericUDTF() != null) { throw new SemanticException(ErrorMsg.UDTF_INVALID_LOCATION.getMsg()); desc = ExprNodeGenericFuncDesc.newInstance(fi.getGenericUDF(), children);
private FunctionInfo registerTableFunction(String functionName, FunctionType functionType, Class<? extends TableFunctionResolver> tFnCls, FunctionResource... resources) { validateClass(tFnCls, TableFunctionResolver.class); FunctionInfo function = new FunctionInfo(functionType, functionName, tFnCls, resources); addFunction(functionName, function); return function; }
/** * Get the Class of the UDF. */ public Class<?> getFunctionClass() { if (isGenericUDF()) { if (genericUDF instanceof GenericUDFBridge) { return ((GenericUDFBridge) genericUDF).getUdfClass(); } else { return genericUDF.getClass(); } } else if (isGenericUDAF()) { if (genericUDAFResolver instanceof GenericUDAFBridge) { return ((GenericUDAFBridge) genericUDAFResolver).getUDAFClass(); } else { return genericUDAFResolver.getClass(); } } else if (isGenericUDTF()) { return genericUDTF.getClass(); } return null; }
assertTrue(functionInfo.isPersistent()); assertTrue(functionInfo.isNative()); assertFalse(functionInfo.isBuiltIn()); functionInfo = FunctionRegistry.getFunctionInfo("default.perm_ln"); assertTrue(functionInfo.isPersistent()); assertTrue(functionInfo.isNative()); assertFalse(functionInfo.isBuiltIn()); GenericUDFConcat.class.getName(), true, emptyResources); functionInfo = FunctionRegistry.getFunctionInfo("default.perm_concat"); assertTrue(functionInfo.isPersistent()); assertTrue(functionInfo.isNative()); assertFalse(functionInfo.isBuiltIn()); GenericUDAFMax.class.getName(), true, emptyResources); functionInfo = FunctionRegistry.getFunctionInfo("default.perm_max"); assertTrue(functionInfo.isPersistent()); functionInfo = FunctionRegistry.getWindowFunctionInfo("default.perm_max"); assertTrue(functionInfo.isPersistent()); assertTrue(functionInfo.isNative()); assertFalse(functionInfo.isBuiltIn()); GenericUDTFExplode.class.getName(), true, emptyResources); functionInfo = FunctionRegistry.getFunctionInfo("default.perm_explode"); assertTrue(functionInfo.isPersistent()); assertTrue(functionInfo.isNative()); assertFalse(functionInfo.isBuiltIn());
public void unregisterFunction(String functionName) throws HiveException { lock.lock(); try { functionName = functionName.toLowerCase(); FunctionInfo fi = mFunctions.get(functionName); if (fi != null) { if (fi.isBuiltIn()) { throw new HiveException(ErrorMsg.DROP_NATIVE_FUNCTION.getMsg(functionName)); } mFunctions.remove(functionName); fi.discarded(); if (fi.isPersistent()) { removePersistentFunctionUnderLock(fi); } } } finally { lock.unlock(); } }
FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(funcName); if (functionInfo != null) { funcClass = functionInfo.getFunctionClass(); outStream.writeBytes("Function type:" + functionInfo.getFunctionType() + "\n"); FunctionResource[] resources = functionInfo.getResources(); if (resources != null) { for (FunctionResource resource : resources) {
protected void validateUDF(ASTNode expr, boolean isFunction, TypeCheckCtx ctx, FunctionInfo fi, List<ExprNodeDesc> children, GenericUDF genericUDF) throws SemanticException { // Detect UDTF's in nested SELECT, GROUP BY, etc as they aren't // supported if (fi.getGenericUDTF() != null) { throw new SemanticException(ErrorMsg.UDTF_INVALID_LOCATION.getMsg()); } // UDAF in filter condition, group-by caluse, param of funtion, etc. if (fi.getGenericUDAFResolver() != null) { if (isFunction) { throw new SemanticException(ErrorMsg.UDAF_INVALID_LOCATION.getMsg((ASTNode) expr .getChild(0))); } else { throw new SemanticException(ErrorMsg.UDAF_INVALID_LOCATION.getMsg(expr)); } } if (!ctx.getAllowStatefulFunctions() && (genericUDF != null)) { if (FunctionRegistry.isStateful(genericUDF)) { throw new SemanticException(ErrorMsg.UDF_STATEFUL_INVALID_LOCATION.getMsg()); } } }
private static boolean isCustomUDF(String udfName) { if (udfName == null) { return false; } FunctionInfo funcInfo; try { funcInfo = FunctionRegistry.getFunctionInfo(udfName); } catch (SemanticException e) { LOG.warn("Failed to load " + udfName, e); funcInfo = null; } if (funcInfo == null) { return false; } boolean isNativeFunc = funcInfo.isNative(); return !isNativeFunc; }