/** * 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); } }
/** * 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); } }
private void registerFunction(String name, SqlOperator calciteFn, HiveToken hiveToken) { reverseOperatorMap.put(calciteFn, name); FunctionInfo hFn; try { hFn = FunctionRegistry.getFunctionInfo(name); } catch (SemanticException e) { LOG.warn("Failed to load udf " + name, e); hFn = null; } if (hFn != null) { String hFnName = getName(hFn.getGenericUDF()); hiveToCalcite.put(hFnName, calciteFn); if (hiveToken != null) { calciteToHiveToken.put(calciteFn, hiveToken); } } }
private void registerFunction(String name, SqlOperator calciteFn, HiveToken hiveToken) { reverseOperatorMap.put(calciteFn, name); FunctionInfo hFn; try { hFn = FunctionRegistry.getFunctionInfo(name); } catch (SemanticException e) { LOG.warn("Failed to load udf " + name, e); hFn = null; } if (hFn != null) { String hFnName = getName(hFn.getGenericUDF()); hiveToCalcite.put(hFnName, calciteFn); if (hiveToken != null) { calciteToHiveToken.put(calciteFn, hiveToken); } } }
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)); }
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 GenericUDF getUDF(String udfName) throws Exception { return FunctionRegistry.getFunctionInfo(udfName).getGenericUDF(); }
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)); } /**
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; }
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()); }
@Override public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx procCtx, Object... nodeOutputs) throws SemanticException { FilterOperator filterOp = (FilterOperator) nd; ExprNodeDesc predicate = filterOp.getConf().getPredicate(); // Generate the list bucketing pruning predicate as 2 separate IN clauses // containing the partitioning and non-partitioning columns. ExprNodeDesc newPredicate = generateInClauses(predicate); if (newPredicate != null) { // Replace filter in current FIL with new FIL if (LOG.isDebugEnabled()) { LOG.debug("Generated new predicate with IN clause: " + newPredicate); } final List<ExprNodeDesc> subExpr = new ArrayList<ExprNodeDesc>(2); subExpr.add(predicate); subExpr.add(newPredicate); ExprNodeGenericFuncDesc newFilterPredicate = new ExprNodeGenericFuncDesc( TypeInfoFactory.booleanTypeInfo, FunctionRegistry.getFunctionInfo(AND_UDF).getGenericUDF(), subExpr); filterOp.getConf().setPredicate(newFilterPredicate); } return null; }
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()); }
@Override public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx procCtx, Object... nodeOutputs) throws SemanticException { FilterOperator filterOp = (FilterOperator) nd; ExprNodeDesc predicate = filterOp.getConf().getPredicate(); // Generate the list bucketing pruning predicate as 2 separate IN clauses // containing the partitioning and non-partitioning columns. ExprNodeDesc newPredicate = generateInClauses(predicate); if (newPredicate != null) { // Replace filter in current FIL with new FIL if (LOG.isDebugEnabled()) { LOG.debug("Generated new predicate with IN clause: " + newPredicate); } final List<ExprNodeDesc> subExpr = new ArrayList<ExprNodeDesc>(2); subExpr.add(predicate); subExpr.add(newPredicate); ExprNodeGenericFuncDesc newFilterPredicate = new ExprNodeGenericFuncDesc( TypeInfoFactory.booleanTypeInfo, FunctionRegistry.getFunctionInfo(AND_UDF).getGenericUDF(), subExpr); filterOp.getConf().setPredicate(newFilterPredicate); } return null; }
private FilterDesc getTestFilterDesc(String column) throws Exception { ArrayList<ExprNodeDesc> children1 = new ArrayList<ExprNodeDesc>(); children1.add(new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, column, "", false)); ExprNodeDesc lhs = new ExprNodeGenericFuncDesc( TypeInfoFactory.doubleTypeInfo, FunctionRegistry.getFunctionInfo( serdeConstants.DOUBLE_TYPE_NAME).getGenericUDF(), children1); ArrayList<ExprNodeDesc> children2 = new ArrayList<ExprNodeDesc>(); children2.add(new ExprNodeConstantDesc(TypeInfoFactory.longTypeInfo, Long .valueOf(100))); ExprNodeDesc rhs = new ExprNodeGenericFuncDesc( TypeInfoFactory.doubleTypeInfo, FunctionRegistry.getFunctionInfo( serdeConstants.DOUBLE_TYPE_NAME).getGenericUDF(), children2); ArrayList<ExprNodeDesc> children3 = new ArrayList<ExprNodeDesc>(); children3.add(lhs); children3.add(rhs); ExprNodeDesc desc = new ExprNodeGenericFuncDesc( TypeInfoFactory.booleanTypeInfo, FunctionRegistry.getFunctionInfo("<") .getGenericUDF(), children3); return new FilterDesc(desc, false); }
/** * Both UDF and UDAF functions can imply order for analytical functions * * @param functionName * name of function * @return true if a GenericUDF or GenericUDAF exists for this name and implyOrder is true, false * otherwise. * @throws SemanticException */ public static boolean impliesOrder(String functionName) throws SemanticException { FunctionInfo info = getFunctionInfo(functionName); if (info != null && info.isGenericUDF()) { UDFType type = AnnotationUtils.getAnnotation(info.getGenericUDF().getClass(), UDFType.class); if (type != null) { return type.impliesOrder(); } } WindowFunctionInfo windowInfo = getWindowFunctionInfo(functionName); if (windowInfo != null) { return windowInfo.isImpliesOrder(); } return false; }