Search in sources :

Example 1 with WindowFunctionSpec

use of com.sap.hadoop.windowing.query2.specification.WindowFunctionSpec in project SQLWindowing by hbutani.

the class WindowFunctionTranslation method setupRankingArgs.

static void setupRankingArgs(QueryDef qDef, TableFuncDef windowTableFnDef, WindowFunctionDef wFnDef, WindowFunctionSpec wSpec) throws WindowingException {
    if (wSpec.getArgs().size() > 0) {
        throw new WindowingException("Ranking Functions can take no arguments");
    }
    QueryInputDef inpDef = windowTableFnDef.getInput();
    InputInfo inpInfo = qDef.getTranslationInfo().getInputInfo(inpDef);
    OrderDef oDef = getTableFuncOrderDef(windowTableFnDef);
    ArrayList<OrderColumnDef> oCols = oDef.getColumns();
    for (OrderColumnDef oCol : oCols) {
        wFnDef.addArg(TranslateUtils.buildArgDef(qDef, inpInfo, oCol.getExpression()));
    }
}
Also used : InputInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo) OrderColumnDef(com.sap.hadoop.windowing.query2.definition.OrderColumnDef) QueryInputDef(com.sap.hadoop.windowing.query2.definition.QueryInputDef) WindowingException(com.sap.hadoop.windowing.WindowingException) OrderDef(com.sap.hadoop.windowing.query2.definition.OrderDef)

Example 2 with WindowFunctionSpec

use of com.sap.hadoop.windowing.query2.specification.WindowFunctionSpec in project SQLWindowing by hbutani.

the class WindowFunctionTranslation method setupEvaluator.

static void setupEvaluator(WindowFunctionDef wFnDef) throws WindowingException {
    try {
        WindowFunctionSpec wSpec = wFnDef.getSpec();
        ArrayList<ArgDef> args = wFnDef.getArgs();
        ArrayList<ObjectInspector> argOIs = getWritableObjectInspector(args);
        GenericUDAFEvaluator wFnEval = org.apache.hadoop.hive.ql.exec.FunctionRegistry.getGenericUDAFEvaluator(wSpec.getName(), argOIs, wSpec.isDistinct(), wSpec.isStar());
        ObjectInspector[] funcArgOIs = null;
        if (args != null) {
            funcArgOIs = new ObjectInspector[args.size()];
            int i = 0;
            for (ArgDef arg : args) {
                funcArgOIs[i++] = arg.getOI();
            }
        }
        ObjectInspector OI = wFnEval.init(GenericUDAFEvaluator.Mode.COMPLETE, funcArgOIs);
        wFnDef.setEvaluator(wFnEval);
        wFnDef.setOI(OI);
    } catch (HiveException he) {
        throw new WindowingException(he);
    }
}
Also used : StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) GenericUDAFEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator) WindowingException(com.sap.hadoop.windowing.WindowingException) WindowFunctionSpec(com.sap.hadoop.windowing.query2.specification.WindowFunctionSpec) ArgDef(com.sap.hadoop.windowing.query2.definition.ArgDef)

Example 3 with WindowFunctionSpec

use of com.sap.hadoop.windowing.query2.specification.WindowFunctionSpec in project SQLWindowing by hbutani.

the class WindowFunctionTranslation method translateWindowSpec.

public static WindowDef translateWindowSpec(QueryDef qDef, InputInfo iInfo, WindowFunctionSpec wFnSpec) throws WindowingException {
    WindowSpec wSpec = wFnSpec.getWindowSpec();
    if (wSpec == null)
        return null;
    WindowFunctionInfo wFnInfo = FunctionRegistry.getWindowFunctionInfo(wFnSpec.getName());
    String desc = wFnSpec.toString();
    if (wSpec != null && !wFnInfo.isSupportsWindow()) {
        throw new WindowingException(sprintf("Function %s doesn't support windowing", desc));
    }
    return WindowSpecTranslation.translateWindowSpecOnInput(qDef, wSpec, iInfo, desc);
}
Also used : WindowFunctionInfo(com.sap.hadoop.windowing.functions2.FunctionRegistry.WindowFunctionInfo) WindowingException(com.sap.hadoop.windowing.WindowingException) WindowSpec(com.sap.hadoop.windowing.query2.specification.WindowSpec)

Example 4 with WindowFunctionSpec

use of com.sap.hadoop.windowing.query2.specification.WindowFunctionSpec in project SQLWindowing by hbutani.

the class WindowFunctionTranslation method translate.

public static WindowFunctionDef translate(QueryDef qDef, TableFuncDef windowTableFnDef, WindowFunctionSpec wFnSpec) throws WindowingException {
    QueryTranslationInfo tInfo = qDef.getTranslationInfo();
    InputInfo iInfo = tInfo.getInputInfo(windowTableFnDef.getInput());
    WindowFunctionDef wFnDef = new WindowFunctionDef();
    wFnDef.setSpec(wFnSpec);
    /*
		 * translate args
		 */
    ArrayList<ASTNode> args = wFnSpec.getArgs();
    if (args != null) {
        for (ASTNode expr : args) {
            ArgDef argDef = translateWindowFunctionArg(qDef, windowTableFnDef, iInfo, expr);
            wFnDef.addArg(argDef);
        }
    }
    if (RANKING_FUNCS.contains(wFnSpec.getName())) {
        setupRankingArgs(qDef, windowTableFnDef, wFnDef, wFnSpec);
    }
    WindowDef wDef = translateWindowSpec(qDef, iInfo, wFnSpec);
    wFnDef.setWindow(wDef);
    validateWindowDefForWFn(windowTableFnDef, wFnDef);
    setupEvaluator(wFnDef);
    return wFnDef;
}
Also used : InputInfo(com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo) WindowDef(com.sap.hadoop.windowing.query2.definition.WindowDef) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) WindowFunctionDef(com.sap.hadoop.windowing.query2.definition.WindowFunctionDef) ArgDef(com.sap.hadoop.windowing.query2.definition.ArgDef)

Aggregations

WindowingException (com.sap.hadoop.windowing.WindowingException)3 ArgDef (com.sap.hadoop.windowing.query2.definition.ArgDef)2 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)2 WindowFunctionInfo (com.sap.hadoop.windowing.functions2.FunctionRegistry.WindowFunctionInfo)1 OrderColumnDef (com.sap.hadoop.windowing.query2.definition.OrderColumnDef)1 OrderDef (com.sap.hadoop.windowing.query2.definition.OrderDef)1 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)1 WindowDef (com.sap.hadoop.windowing.query2.definition.WindowDef)1 WindowFunctionDef (com.sap.hadoop.windowing.query2.definition.WindowFunctionDef)1 WindowFunctionSpec (com.sap.hadoop.windowing.query2.specification.WindowFunctionSpec)1 WindowSpec (com.sap.hadoop.windowing.query2.specification.WindowSpec)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)1 GenericUDAFEvaluator (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator)1 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)1 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)1