

def _window(translator, expr):
    op = expr.op()
    (arg, window) = op.args
    window_op = arg.op()
    _require_order_by = (ops.Lag, ops.Lead, ops.DenseRank, ops.MinRank, ops.FirstValue, ops.LastValue)
    _unsupported_reductions = (ops.CMSMedian, ops.GroupConcat, ops.HLLCardinality)
    if isinstance(window_op, _unsupported_reductions):
        raise com.TranslationError('{0!s} is not supported in window functions'.format(type(window_op)))
    if isinstance(window_op, ops.CumulativeOp):
        arg = _cumulative_to_window(translator, arg, window)
        return translator.translate(arg)
    if (isinstance(window_op, _require_order_by) and (len(window._order_by) == 0)):
        window = window.order_by(window_op.args[0])
    window_formatted = _format_window(translator, window)
    arg_formatted = translator.translate(arg)
    result = '{0} {1}'.format(arg_formatted, window_formatted)
    if (type(window_op) in _expr_transforms):
        return _expr_transforms[type(window_op)](result)
    else:
        return result

dataset/ETHPy150Open cloudera/ibis/ibis/impala/compiler.py _window/original