public static GenericUDAFResolver getGenericUDAFResolver(String functionName) throws SemanticException { if (LOG.isDebugEnabled()) { LOG.debug("Looking up GenericUDAF: " + functionName); } FunctionInfo finfo = getFunctionInfo(functionName); if (finfo == null) { return null; } GenericUDAFResolver result = finfo.getGenericUDAFResolver(); return result; }
/** * 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); } }
/** * A shortcut to get the "and" GenericUDF. * @throws SemanticException */ public static GenericUDF getGenericUDFForAnd() { try { return FunctionRegistry.getFunctionInfo("and").getGenericUDF(); } catch (SemanticException e) { throw new RuntimeException("hive operator -- never be thrown", e); } }
public static ExprNodeGenericFuncDesc makeBinaryPredicate( String fn, ExprNodeDesc left, ExprNodeDesc right) throws SemanticException { return new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo, FunctionRegistry.getFunctionInfo(fn).getGenericUDF(), Lists.newArrayList(left, right)); } public static ExprNodeGenericFuncDesc makeUnaryPredicate(
public static ExprNodeGenericFuncDesc makeUnaryPredicate( String fn, ExprNodeDesc arg) throws SemanticException { return new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo, FunctionRegistry.getFunctionInfo(fn).getGenericUDF(), Lists.newArrayList(arg)); } /**
public ExprNodeGenericFuncDesc binaryPredicate(String function, ExprNodeDesc lhs, ExprNodeDesc rhs) throws SemanticException { return new ExprNodeGenericFuncDesc(TypeInfoFactory.booleanTypeInfo, FunctionRegistry.getFunctionInfo(function).getGenericUDF(), Lists.newArrayList(lhs, rhs)); }
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; }
public static boolean isTableFunction(String functionName) throws SemanticException { FunctionInfo tFInfo = getFunctionInfo(functionName); return tFInfo != null && !tFInfo.isInternalTableFunction() && tFInfo.isTableFunction(); }
public static String getNormalizedFunctionName(String fn) throws SemanticException { // Does the same thing as getFunctionInfo, except for getting the function info. fn = fn.toLowerCase(); return (FunctionUtils.isQualifiedFunctionName(fn) || getFunctionInfo(fn) != null) ? fn : FunctionUtils.qualifyFunctionName( fn, SessionState.get().getCurrentDatabase().toLowerCase()); }
private void addParentReduceSink(final List<ExprNodeDesc> andArgs, final ReduceSinkOperator rsOp, final int keyIndex, final ExprNodeDesc sourceKey) throws SemanticException { ExprNodeDynamicListDesc dynamicExpr = new ExprNodeDynamicListDesc(rsOp.getConf().getKeyCols().get(keyIndex).getTypeInfo(), rsOp, keyIndex); // Create synthetic IN expression List<ExprNodeDesc> inArgs = new ArrayList<>(); inArgs.add(sourceKey); inArgs.add(dynamicExpr); ExprNodeDesc newNode = ExprNodeGenericFuncDesc.newInstance( FunctionRegistry.getFunctionInfo("in").getGenericUDF(), inArgs); andArgs.add(newNode); } }
private boolean checkAggregator(AggregationDesc agg) throws SemanticException { if (LOG.isDebugEnabled()) { LOG.debug(String.format("Checking '%s'", agg.getExprString())); } boolean result = checkExpressions(agg.getParameters()); FunctionInfo fi = FunctionRegistry.getFunctionInfo(agg.getGenericUDAFName()); result = result && (fi != null) && fi.isNative(); if (!result) { LOG.info("Aggregator is not native: " + agg.getExprString()); } return result; }
private GenericUDF getUDF(String udfName) throws Exception { return FunctionRegistry.getFunctionInfo(udfName).getGenericUDF(); }
private ExprBuilder fn(String name, TypeInfo ti, int args) throws Exception { List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>(); for (int i = 0; i < args; ++i) { children.add(stack.pop()); } stack.push(new ExprNodeGenericFuncDesc(ti, FunctionRegistry.getFunctionInfo(name).getGenericUDF(), children)); return this; }
/** * 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()); }
/** * Verify that UDF in the whitelist can be access * @throws Exception */ @Test public void testUdfInWhiteList() throws Exception { Set<String> funcNames = FunctionRegistry.getFunctionNames(); funcNames.remove("reflect"); FunctionRegistry.setupPermissionsForBuiltinUDFs(funcNames.toString(), ""); assertEquals("substr", FunctionRegistry.getFunctionInfo("substr").getDisplayName()); }
/** * Verify that UDF in blacklist can't be accessed * @throws Exception */ @Test (expected=SemanticException.class) public void testUdfInBlackList() throws Exception { FunctionRegistry.setupPermissionsForBuiltinUDFs("", "reflect"); assertEquals("reflect", FunctionRegistry.getFunctionInfo("reflect").getDisplayName()); }
/** * Verify that UDF in whitelist and blacklist can't be accessed * @throws Exception */ @Test (expected=SemanticException.class) public void testUdfInBlackAndWhiteList() throws Exception { FunctionRegistry.setupPermissionsForBuiltinUDFs("reflect", "reflect"); assertEquals("reflect", FunctionRegistry.getFunctionInfo("reflect").getDisplayName()); }
public void testBuiltInFunction() throws Exception { FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo("ln"); assertTrue(functionInfo.isBuiltIn()); assertTrue(functionInfo.isNative()); }
/** * Test malformatted udf list setting */ @Test (expected=SemanticException.class) public void testMalformattedListProperty() throws Exception { FunctionRegistry.setupPermissionsForBuiltinUDFs(",,", " ,reflect,"); assertEquals("reflect", FunctionRegistry.getFunctionInfo("reflect").getDisplayName()); }
/** * Verify that UDF in the whitelist can be access * @throws Exception */ @Test public void testDefaultWhiteList() throws Exception { assertEquals("", new HiveConf().getVar(ConfVars.HIVE_SERVER2_BUILTIN_UDF_WHITELIST)); assertEquals("", new HiveConf().getVar(ConfVars.HIVE_SERVER2_BUILTIN_UDF_BLACKLIST)); FunctionRegistry.setupPermissionsForBuiltinUDFs("", ""); assertEquals("substr", FunctionRegistry.getFunctionInfo("substr").getDisplayName()); }