コード例 #1
0
    def _windowize(x, w):
        if not isinstance(x.op(), ops.WindowOp):
            walked = _walk(x, w)
        else:
            window_arg, window_w = x.op().args
            walked_child = _walk(window_arg, w)

            if walked_child is not window_arg:
                walked = x._factory(ops.WindowOp(walked_child, window_w),
                                    name=x._name)
            else:
                walked = x

        op = walked.op()
        if isinstance(op, ops.AnalyticOp) or getattr(op, '_reduction', False):
            if w is None:
                w = window()
            return walked.over(w)
        elif isinstance(op, ops.WindowOp):
            if w is not None:
                return walked.over(w)
            else:
                return walked
        else:
            return walked
コード例 #2
0
    def _windowize(x, w):
        if not isinstance(x.op(), ops.WindowOp):
            walked = _walk(x, w)
        else:
            window_arg, window_w = x.op().args
            walked_child = _walk(window_arg, w)

            if walked_child is not window_arg:
                op = ops.WindowOp(walked_child, window_w)
                walked = op.to_expr().name(x.get_name())
            else:
                walked = x

        op = walked.op()
        if isinstance(op, ops.AnalyticOp) or getattr(op, '_reduction', False):
            if w is None:
                w = window()
            return walked.over(w)
        elif isinstance(op, ops.WindowOp):
            if w is not None:
                return walked.over(w.combine(op.window))
            else:
                return walked
        else:
            return walked
コード例 #3
0
def over(expr, window):
    """
    Turn an aggregation or full-sample analytic operation into a windowed
    operation. See ibis.window for more details on window configuration

    Parameters
    ----------
    expr : value expression
    window : ibis.Window

    Returns
    -------
    expr : type of input
    """
    prior_op = expr.op()

    if isinstance(prior_op, _ops.WindowOp):
        op = prior_op.over(window)
    else:
        op = _ops.WindowOp(expr, window)

    result = op.to_expr()

    try:
        result = result.name(expr.get_name())
    except:
        pass

    return result
コード例 #4
0
ファイル: generic.py プロジェクト: cpcloud/ibis
    def over(self, window: win.Window) -> ValueExpr:
        """Construct a window expression.

        Parameters
        ----------
        window
            Window specification

        Returns
        -------
        ValueExpr
            A window function expression
        """
        import ibis.expr.operations as ops

        prior_op = self.op()

        # TODO(kszucs): fix this ugly hack
        if isinstance(prior_op, ops.Alias):
            return prior_op.arg.over(window).name(prior_op.name)

        if isinstance(prior_op, ops.WindowOp):
            op = prior_op.over(window)
        else:
            op = ops.WindowOp(self, window)

        result = op.to_expr()

        if self.has_name():
            return result.name(self.get_name())
        return result
コード例 #5
0
ファイル: window.py プロジェクト: martint/ibis
def propagate_down_window(expr, window):
    op = expr.op()

    clean_args = []
    unchanged = True
    for arg in op.args:
        if isinstance(arg, ir.Expr) and not isinstance(op, ops.WindowOp):
            new_arg = propagate_down_window(arg, window)
            if isinstance(new_arg.op(), ops.AnalyticOp):
                new_arg = ops.WindowOp(new_arg, window).to_expr()
            if arg is not new_arg:
                unchanged = False
            arg = new_arg

        clean_args.append(arg)

    if unchanged:
        return expr
    else:
        return type(op)(*clean_args).to_expr()