/** * Typically a WindowFunction is the same as a UDAF. The only exceptions are Lead & Lag UDAFs. These * are not registered as regular UDAFs because * - we plan to support Lead & Lag as UDFs (usable only within argument expressions * of UDAFs when windowing is involved). Since mFunctions holds both UDFs and UDAFs we cannot * add both FunctionInfos to mFunctions. * * @param name * @param wFn */ void registerWindowFunction(String name, GenericUDAFResolver wFn) { FunctionType functionType = isNative ? FunctionType.BUILTIN : FunctionType.TEMPORARY; addFunction(WINDOW_FUNC_PREFIX + name, new WindowFunctionInfo(functionType, name, wFn, null)); }
public GenericUDAFEvaluator getGenericWindowingEvaluator(String functionName, List<ObjectInspector> argumentOIs, boolean isDistinct, boolean isAllColumns) throws SemanticException { functionName = functionName.toLowerCase(); WindowFunctionInfo info = getWindowFunctionInfo(functionName); if (info == null) { return null; } if (!functionName.equals(FunctionRegistry.LEAD_FUNC_NAME) && !functionName.equals(FunctionRegistry.LAG_FUNC_NAME)) { return getGenericUDAFEvaluator(functionName, argumentOIs, true, isDistinct, isAllColumns); } // this must be lead/lag UDAF ObjectInspector args[] = new ObjectInspector[argumentOIs.size()]; GenericUDAFResolver udafResolver = info.getGenericUDAFResolver(); GenericUDAFParameterInfo paramInfo = new SimpleGenericUDAFParameterInfo( argumentOIs.toArray(args), true, isDistinct, isAllColumns); return ((GenericUDAFResolver2) udafResolver).getEvaluator(paramInfo); }
public static boolean pivotResult(String functionName) throws SemanticException { WindowFunctionInfo windowInfo = getWindowFunctionInfo(functionName); if (windowInfo != null) { return windowInfo.isPivotResult(); } return false; }
def.setExpressionTreeString(spec.getExpression().toStringTree()); def.setStar(spec.isStar()); def.setPivotResult(wFnInfo.isPivotResult()); ShapeDetails inpShape = wdwTFnDef.getRawInputShape(); if (!wFnInfo.isSupportsWindow())
private void initializeWindowingFunctionInfoHelpers() throws SemanticException { // getWindowFunctionInfo() cannot be called during map/reduce tasks. So cache necessary // values during query compilation, and rely on plan serialization to bring this info // to the object during the map/reduce tasks. if (windowingFunctionHelpers != null) { return; } windowingFunctionHelpers = new HashMap<String, WindowingFunctionInfoHelper>(); WindowTableFunctionDef tabDef = (WindowTableFunctionDef) getTableDef(); for (int i = 0; i < tabDef.getWindowFunctions().size(); i++) { WindowFunctionDef wFn = tabDef.getWindowFunctions().get(i); WindowFunctionInfo wFnInfo = FunctionRegistry.getWindowFunctionInfo(wFn.getName()); boolean supportsWindow = wFnInfo.isSupportsWindow(); windowingFunctionHelpers.put(wFn.getName(), new WindowingFunctionInfoHelper(supportsWindow)); } }
/** * 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; }
def.setExpressionTreeString(spec.getExpression().toStringTree()); def.setStar(spec.isStar()); def.setPivotResult(wFnInfo.isPivotResult()); ShapeDetails inpShape = wdwTFnDef.getRawInputShape(); if (!wFnInfo.isSupportsWindow())
private void initializeWindowingFunctionInfoHelpers() throws SemanticException { // getWindowFunctionInfo() cannot be called during map/reduce tasks. So cache necessary // values during query compilation, and rely on plan serialization to bring this info // to the object during the map/reduce tasks. if (windowingFunctionHelpers != null) { return; } windowingFunctionHelpers = new HashMap<String, WindowingFunctionInfoHelper>(); WindowTableFunctionDef tabDef = (WindowTableFunctionDef) getTableDef(); for (int i = 0; i < tabDef.getWindowFunctions().size(); i++) { WindowFunctionDef wFn = tabDef.getWindowFunctions().get(i); WindowFunctionInfo wFnInfo = FunctionRegistry.getWindowFunctionInfo(wFn.getName()); boolean supportsWindow = wFnInfo.isSupportsWindow(); windowingFunctionHelpers.put(wFn.getName(), new WindowingFunctionInfoHelper(supportsWindow)); } }
/** * 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; }
def.setExpressionTreeString(spec.getExpression().toStringTree()); def.setStar(spec.isStar()); def.setPivotResult(wFnInfo.isPivotResult()); ShapeDetails inpShape = wdwTFnDef.getRawInputShape(); if (!wFnInfo.isSupportsWindow())
/** * Typically a WindowFunction is the same as a UDAF. The only exceptions are Lead & Lag UDAFs. These * are not registered as regular UDAFs because * - we plan to support Lead & Lag as UDFs (usable only within argument expressions * of UDAFs when windowing is involved). Since mFunctions holds both UDFs and UDAFs we cannot * add both FunctionInfos to mFunctions. * * @param name * @param wFn */ void registerWindowFunction(String name, GenericUDAFResolver wFn) { FunctionType functionType = isNative ? FunctionType.BUILTIN : FunctionType.TEMPORARY; addFunction(WINDOW_FUNC_PREFIX + name, new WindowFunctionInfo(functionType, name, wFn, null)); }
WindowSpec wdwSpec = wFn.getWindowSpec(); WindowFunctionInfo wFnInfo = FunctionRegistry.getWindowFunctionInfo(wFn.getName()); boolean supportsWindowing = wFnInfo == null ? true : wFnInfo.isSupportsWindow(); WindowFrameSpec wFrame = wdwSpec.getWindowFrame(); OrderSpec orderSpec = wdwSpec.getOrder();
public static boolean pivotResult(String functionName) throws SemanticException { WindowFunctionInfo windowInfo = getWindowFunctionInfo(functionName); if (windowInfo != null) { return windowInfo.isPivotResult(); } return false; }
public GenericUDAFEvaluator getGenericWindowingEvaluator(String functionName, List<ObjectInspector> argumentOIs, boolean isDistinct, boolean isAllColumns) throws SemanticException { functionName = functionName.toLowerCase(); WindowFunctionInfo info = getWindowFunctionInfo(functionName); if (info == null) { return null; } if (!functionName.equals(FunctionRegistry.LEAD_FUNC_NAME) && !functionName.equals(FunctionRegistry.LAG_FUNC_NAME)) { return getGenericUDAFEvaluator(functionName, argumentOIs, true, isDistinct, isAllColumns); } // this must be lead/lag UDAF ObjectInspector args[] = new ObjectInspector[argumentOIs.size()]; GenericUDAFResolver udafResolver = info.getGenericUDAFResolver(); GenericUDAFParameterInfo paramInfo = new SimpleGenericUDAFParameterInfo( argumentOIs.toArray(args), true, isDistinct, isAllColumns); return ((GenericUDAFResolver2) udafResolver).getEvaluator(paramInfo); }
/** * 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; }
private FunctionInfo registerGenericUDAF(String functionName, FunctionType functionType, GenericUDAFResolver genericUDAFResolver, FunctionResource... resources) { FunctionInfo function = new WindowFunctionInfo(functionType, functionName, genericUDAFResolver, resources); addFunction(functionName, function); addFunction(WINDOW_FUNC_PREFIX + functionName, function); return function; }
WindowSpec wdwSpec = wFn.getWindowSpec(); WindowFunctionInfo wFnInfo = FunctionRegistry.getWindowFunctionInfo(wFn.getName()); boolean supportsWindowing = wFnInfo == null ? true : wFnInfo.isSupportsWindow(); WindowFrameSpec wFrame = wdwSpec.getWindowFrame(); OrderSpec orderSpec = wdwSpec.getOrder();
public static boolean pivotResult(String functionName) throws SemanticException { WindowFunctionInfo windowInfo = getWindowFunctionInfo(functionName); if (windowInfo != null) { return windowInfo.isPivotResult(); } return false; }
public GenericUDAFEvaluator getGenericWindowingEvaluator(String functionName, List<ObjectInspector> argumentOIs, boolean isDistinct, boolean isAllColumns) throws SemanticException { functionName = functionName.toLowerCase(); WindowFunctionInfo info = getWindowFunctionInfo(functionName); if (info == null) { return null; } if (!functionName.equals(FunctionRegistry.LEAD_FUNC_NAME) && !functionName.equals(FunctionRegistry.LAG_FUNC_NAME)) { return getGenericUDAFEvaluator(functionName, argumentOIs, isDistinct, isAllColumns); } // this must be lead/lag UDAF ObjectInspector args[] = new ObjectInspector[argumentOIs.size()]; GenericUDAFResolver udafResolver = info.getGenericUDAFResolver(); GenericUDAFParameterInfo paramInfo = new SimpleGenericUDAFParameterInfo( argumentOIs.toArray(args), isDistinct, isAllColumns); return ((GenericUDAFResolver2) udafResolver).getEvaluator(paramInfo); }
private FunctionInfo registerGenericUDAF(String functionName, FunctionType functionType, GenericUDAFResolver genericUDAFResolver, FunctionResource... resources) { FunctionInfo function = new WindowFunctionInfo(functionType, functionName, genericUDAFResolver, resources); addFunction(functionName, function); addFunction(WINDOW_FUNC_PREFIX + functionName, function); return function; }