Search in sources :

Example 1 with BoundaryDef

use of org.apache.hadoop.hive.ql.plan.ptf.BoundaryDef in project hive by apache.

the class WindowingTableFunction method streamingPossible.

private boolean streamingPossible(Configuration cfg, WindowFunctionDef wFnDef) throws HiveException {
    WindowFrameDef wdwFrame = wFnDef.getWindowFrame();
    WindowingFunctionInfoHelper wFnInfo = getWindowingFunctionInfoHelper(wFnDef.getName());
    if (!wFnInfo.isSupportsWindow()) {
        return true;
    }
    BoundaryDef start = wdwFrame.getStart();
    BoundaryDef end = wdwFrame.getEnd();
    /*
     * Currently we are not handling dynamic sized windows implied by range
     * based windows.
     */
    if (wdwFrame.getWindowType() == WindowType.RANGE) {
        return false;
    }
    /*
     * Windows that are unbounded following don't benefit from Streaming.
     */
    if (end.getAmt() == BoundarySpec.UNBOUNDED_AMOUNT) {
        return false;
    }
    /*
     * let function decide if it can handle this special case.
     */
    if (start.getAmt() == BoundarySpec.UNBOUNDED_AMOUNT) {
        return true;
    }
    int windowLimit = HiveConf.getIntVar(cfg, ConfVars.HIVEJOINCACHESIZE);
    if (windowLimit < (start.getAmt() + end.getAmt() + 1)) {
        return false;
    }
    return true;
}
Also used : BoundaryDef(org.apache.hadoop.hive.ql.plan.ptf.BoundaryDef) WindowFrameDef(org.apache.hadoop.hive.ql.plan.ptf.WindowFrameDef)

Example 2 with BoundaryDef

use of org.apache.hadoop.hive.ql.plan.ptf.BoundaryDef in project hive by apache.

the class BasePartitionEvaluator method getRange.

protected static Range getRange(WindowFrameDef winFrame, int currRow, PTFPartition p) throws HiveException {
    BoundaryDef startB = winFrame.getStart();
    BoundaryDef endB = winFrame.getEnd();
    int start, end;
    if (winFrame.getWindowType() == WindowType.ROWS) {
        start = getRowBoundaryStart(startB, currRow);
        end = getRowBoundaryEnd(endB, currRow, p);
    } else {
        ValueBoundaryScanner vbs = ValueBoundaryScanner.getScanner(winFrame);
        start = vbs.computeStart(currRow, p);
        end = vbs.computeEnd(currRow, p);
    }
    start = start < 0 ? 0 : start;
    end = end > p.size() ? p.size() : end;
    return new Range(start, end, p);
}
Also used : BoundaryDef(org.apache.hadoop.hive.ql.plan.ptf.BoundaryDef)

Example 3 with BoundaryDef

use of org.apache.hadoop.hive.ql.plan.ptf.BoundaryDef in project hive by apache.

the class WindowingTableFunction method setCanAcceptInputAsStream.

/*
   * (non-Javadoc)
   * 
   * @see
   * org.apache.hadoop.hive.ql.udf.ptf.TableFunctionEvaluator#canAcceptInputAsStream
   * ()
   * 
   * WindowTableFunction supports streaming if all functions meet one of these
   * conditions: 1. The Function implements ISupportStreamingModeForWindowing 2.
   * Or returns a non null Object for the getWindowingEvaluator, that implements
   * ISupportStreamingModeForWindowing. 3. Is an invocation on a 'fixed' window.
   * So no Unbounded Preceding or Following.
   */
@SuppressWarnings("resource")
private int[] setCanAcceptInputAsStream(Configuration cfg) throws HiveException {
    canAcceptInputAsStream = false;
    if (ptfDesc.getLlInfo().getLeadLagExprs() != null) {
        return null;
    }
    WindowTableFunctionDef tabDef = (WindowTableFunctionDef) getTableDef();
    int startPos = Integer.MAX_VALUE;
    int endPos = Integer.MIN_VALUE;
    for (int i = 0; i < tabDef.getWindowFunctions().size(); i++) {
        WindowFunctionDef wFnDef = tabDef.getWindowFunctions().get(i);
        WindowFrameDef wdwFrame = wFnDef.getWindowFrame();
        GenericUDAFEvaluator fnEval = wFnDef.getWFnEval();
        boolean streamingPossible = streamingPossible(cfg, wFnDef);
        GenericUDAFEvaluator streamingEval = streamingPossible ? fnEval.getWindowingEvaluator(wdwFrame) : null;
        if (streamingEval != null && streamingEval instanceof ISupportStreamingModeForWindowing) {
            continue;
        }
        BoundaryDef start = wdwFrame.getStart();
        BoundaryDef end = wdwFrame.getEnd();
        if (wdwFrame.getWindowType() == WindowType.ROWS) {
            if (!end.isUnbounded() && !start.isUnbounded()) {
                startPos = Math.min(startPos, wdwFrame.getStart().getRelativeOffset());
                endPos = Math.max(endPos, wdwFrame.getEnd().getRelativeOffset());
                continue;
            }
        }
        return null;
    }
    int windowLimit = HiveConf.getIntVar(cfg, ConfVars.HIVEJOINCACHESIZE);
    if (windowLimit < (endPos - startPos + 1)) {
        return null;
    }
    canAcceptInputAsStream = true;
    return new int[] { startPos, endPos };
}
Also used : ISupportStreamingModeForWindowing(org.apache.hadoop.hive.ql.udf.generic.ISupportStreamingModeForWindowing) BoundaryDef(org.apache.hadoop.hive.ql.plan.ptf.BoundaryDef) WindowFrameDef(org.apache.hadoop.hive.ql.plan.ptf.WindowFrameDef) GenericUDAFEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator) WindowTableFunctionDef(org.apache.hadoop.hive.ql.plan.ptf.WindowTableFunctionDef) WindowFunctionDef(org.apache.hadoop.hive.ql.plan.ptf.WindowFunctionDef)

Example 4 with BoundaryDef

use of org.apache.hadoop.hive.ql.plan.ptf.BoundaryDef in project hive by apache.

the class PTFTranslator method translate.

private WindowFrameDef translate(ShapeDetails inpShape, WindowFrameSpec spec, List<OrderExpression> orderExpressions) throws SemanticException {
    if (spec == null) {
        return null;
    }
    BoundarySpec s = spec.getStart();
    BoundarySpec e = spec.getEnd();
    int cmp = s.compareTo(e);
    if (cmp > 0) {
        throw new SemanticException(String.format("Window range invalid, start boundary is greater than end boundary: %s", spec));
    }
    WindowFrameDef winFrame = new WindowFrameDef(spec.getWindowType(), new BoundaryDef(s.direction, s.getAmt()), new BoundaryDef(e.direction, e.getAmt()));
    if (winFrame.getWindowType() == WindowType.RANGE) {
        winFrame.setOrderDef(buildOrderExpressions(inpShape, orderExpressions));
    }
    return winFrame;
}
Also used : BoundaryDef(org.apache.hadoop.hive.ql.plan.ptf.BoundaryDef) WindowFrameDef(org.apache.hadoop.hive.ql.plan.ptf.WindowFrameDef) BoundarySpec(org.apache.hadoop.hive.ql.parse.WindowingSpec.BoundarySpec)

Aggregations

BoundaryDef (org.apache.hadoop.hive.ql.plan.ptf.BoundaryDef)4 WindowFrameDef (org.apache.hadoop.hive.ql.plan.ptf.WindowFrameDef)3 BoundarySpec (org.apache.hadoop.hive.ql.parse.WindowingSpec.BoundarySpec)1 WindowFunctionDef (org.apache.hadoop.hive.ql.plan.ptf.WindowFunctionDef)1 WindowTableFunctionDef (org.apache.hadoop.hive.ql.plan.ptf.WindowTableFunctionDef)1 GenericUDAFEvaluator (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator)1 ISupportStreamingModeForWindowing (org.apache.hadoop.hive.ql.udf.generic.ISupportStreamingModeForWindowing)1