

def _format_window(translator, window):
    components = []
    if (len(window._group_by) > 0):
        partition_args = [translator.translate(x) for x in window._group_by]
        components.append('PARTITION BY {0}'.format(', '.join(partition_args)))
    if (len(window._order_by) > 0):
        order_args = []
        for expr in window._order_by:
            key = expr.op()
            translated = translator.translate(key.expr)
            if (not key.ascending):
                translated += ' DESC'
            order_args.append(translated)
        components.append('ORDER BY {0}'.format(', '.join(order_args)))
    (p, f) = (window.preceding, window.following)

    def _prec(p):
        return ('{0} PRECEDING'.format(p) if (p > 0) else 'CURRENT ROW')

    def _foll(f):
        return ('{0} FOLLOWING'.format(f) if (f > 0) else 'CURRENT ROW')
    if ((p is not None) and (f is not None)):
        frame = 'ROWS BETWEEN {0} AND {1}'.format(_prec(p), _foll(f))
    elif (p is not None):
        if isinstance(p, tuple):
            (start, end) = p
            frame = 'ROWS BETWEEN {0} AND {1}'.format(_prec(start), _prec(end))
        else:
            kind = ('ROWS' if (p > 0) else 'RANGE')
            frame = '{0} BETWEEN {1} AND UNBOUNDED FOLLOWING'.format(kind, _prec(p))
    elif (f is not None):
        if isinstance(f, tuple):
            (start, end) = f
            frame = 'ROWS BETWEEN {0} AND {1}'.format(_foll(start), _foll(end))
        else:
            kind = ('ROWS' if (f > 0) else 'RANGE')
            frame = '{0} BETWEEN UNBOUNDED PRECEDING AND {1}'.format(kind, _foll(f))
    else:
        frame = None
    if (window is not None):
        components.append(frame)
    return 'OVER ({0})'.format(' '.join(components))

dataset/ETHPy150Open cloudera/ibis/ibis/impala/compiler.py _format_window/VarMisuse@434/631 `frame`->`window`