Example #1
0
def make_comp(comparator):
    if isinstance(comparator, ttypes.EqComparison):
        return ttypes.Comparison(eqcomp=comparator)
    elif isinstance(comparator, ttypes.NullComparison):
        return ttypes.Comparison(nullcomp=comparator)
    elif isinstance(comparator, ttypes.InComparison):
        return ttypes.comparator(incomp=comparator)
    assert_not_reached('make_comp invalid comparator: %r' % (comparator,))
Example #2
0
def render_target(targ):
    if targ.col:
        return render_column(targ.col)
    elif targ.ival:
        return '%d' % (targ.ival,)
    elif targ.fval:
        return '%s' % (targ.fval,)
    elif targ.sval:
        return '%s' % (targ.sval,)
    elif targ.nullity is not None:
        return 'NULL'
    assert_not_reached('invalid target: %r' % (targ,))
Example #3
0
def make_target(t):
    if isinstance(t, ttypes.Target):
        return t
    elif hasattr(t, 'make_target'):
        return t.make_target()
    elif isinstance(t, ttypes.Column):
        return ttypes.Target(col=t)
    elif isinstance(t, (int, long)):
        return ttypes.Target(ival=t)
    elif isinstance(t, float):
        return ttypes.Target(fval=t)
    elif isinstance(t, basestring):
        return ttypes.Target(sval=t)
    elif t is None:
        return ttypes.Target(nullity=True)
    assert_not_reached('make_comp invalid arg: %r' % (t,))
Example #4
0
def render_comparison(comp):
    if comp.eqcomp:
        c = comp.eqcomp
        return '%s %s %s' % (render_target(c.lhs), render_eq(c.eq), render_target(c.rhs))
    elif comp.nullcomp:
        c = comp.nullcomp
        if c.isnull:
            return '%s IS NULL' % (render_column(c.col),)
        else:
            return '%s IS NOT NULL' % (render_column(c.col),)
    elif comp.incomp:
        c = comp.incomp
        if len(c.targets) == 0:
            return '1' if c.notin else '0'
        else:
            in_text = 'NOT IN' if c.notin else 'IN'
            return '%s %s (%s)' % (render_target(c.lhs), in_text, ', '.join(render_target(targ) for targ in c.targets))
    assert_not_reached('invalid render_comparison: %r' % (comp,))
Example #5
0
def render_order(order):
    if order == types.Order.ASC:
        return 'ASC'
    elif order == types.Order.DESC:
        return 'DESC'
    assert_not_reached('invalid order: %r' % (order,))