Beispiel #1
0
def multiIf(branches, default):
    r = 'multiIf({branches}, {default})'
    b_stmts = []
    for branch in branches:
        b_stmts.append('{}, {}'.format(branch[0], quote_literal(branch[1])))
    return c(
        r.format(branches=', '.join(b_stmts), default=quote_literal(default)))
Beispiel #2
0
 def load(self, parts=None):
     from vulkn.types import c
     dt = SelectQueryDataTable(self._ctx, str(self)).all()
     if parts:
         dt = dt.where(c('_part').in_(parts))
     q = dt._get_query()
     sql = VulknSQLFormatter().format(q, **self._params[0]) if self._params else q
     statements = vulkn.sql.SQLMessage(sql).statements()
     if len(statements) > 1:
         raise Exception('More than one statement is not supported')
     t = self._ctx.session.cache(statements[0].optimize(), engine=vulkn.engines.Memory())
     return BaseTableDataTable(self._ctx, *(t.split('.')))
Beispiel #3
0
def arrayGeneric(func_name, *args):
    lambda_exp = (args[0] if (callable(args[0])
                              or hasattr(args[0], '__call__')) else None)
    params = (None if lambda_exp is None else '({})'.format(', '.join(
        lambda_exp.__code__.co_varnames)))
    arrs = args if lambda_exp is None else args[1:]
    arrs = ', '.join([str(a) for a in arrs])
    r = ('{func_name}({arrs})' if lambda_exp is None else
         '{func_name}({params} -> {lambda_exp}, {arrs})')
    s = ''
    if lambda_exp:
        s = r.format(func_name=func_name,
                     params=params,
                     lambda_exp=lambda_exp(),
                     arrs=arrs)
    else:
        s = r.format(func_name=func_name, arrs=arrs)
    return c(s)
Beispiel #4
0
def arrayJoin(arr):
    return c('arrayJoin({})'.format(str(arr)))
Beispiel #5
0
def if_(condition, then_arg, else_arg):
    return c('if({}, {}, {})'.format(condition, quote_literal(then_arg),
                                     quote_literal(else_arg)))
Beispiel #6
0
def xor_(*args):
    return c('({})'.format(' XOR '.join(map(str, args))))
Beispiel #7
0
def not_(args):
    return c('NOT ({})'.format(str(args)))
Beispiel #8
0
def and_(*args):
    return c('({})'.format(' AND '.join(map(str, args))))
Beispiel #9
0
def coalesce(*args):
    return c('coalesce({})'.format(', '.join(map(str, args))))