예제 #1
0
def create_pipe_call(source, *args, **kwargs):
    first, *rest = args
    return Pipeable(
        Call("__call__", strip_symbolic(source), strip_symbolic(first),
             *(Lazy(strip_symbolic(x)) for x in rest),
             **{k: Lazy(strip_symbolic(v))
                for k, v in kwargs.items()}))
예제 #2
0
def _case_when(__data, cases):
    if not isinstance(cases, dict):
        raise Exception("Cases must be a dictionary")
    dict_entries = dict(
        (strip_symbolic(k), strip_symbolic(v)) for k, v in cases.items())
    cases_arg = Lazy(DictCall("__call__", dict, dict_entries))
    return create_sym_call(case_when, __data, cases_arg)
예제 #3
0
파일: verbs.py 프로젝트: yassermustfa/siuba
    def shape_call(
            self,
            call, window = True, str_accessors = False,
            verb_name = None, arg_name = None,
            ):
        # TODO: error if mutate receives a literal value?
        # TODO: dispatch_cls currently unused
        if str_accessors and isinstance(call, str):
            # verbs that can use strings as accessors, like group_by, or
            # arrange, need to convert those strings into a getitem call
            return str_to_get_item_call(call)
        elif isinstance(call, sql.elements.ColumnClause):
            return Lazy(call)
        elif not isinstance(call, Call):
            # verbs that use literal strings, need to convert them to a call
            # that returns a sqlalchemy "literal" object
            return Lazy(sql.literal(call))

        # set up locals funcs dict
        f_dict1 = self.funcs['scalar']
        f_dict2 = self.funcs['window' if window else 'aggregate']

        funcs = {**f_dict1, **f_dict2}

        # determine dispatch class
        cls_name = 'window' if window else 'aggregate'
        dispatch_cls = self.dispatch_cls[cls_name]

        call_shaper = CallTreeLocal(
                funcs,
                call_sub_attr = self.call_sub_attr,
                dispatch_cls = dispatch_cls,
                result_cls = self.result_cls
                )

        # raise informative error message if missing translation
        try:
            return call_shaper.enter(call)
        except FunctionLookupError as err:
            raise SqlFunctionLookupError.from_verb(
                    verb_name or "Unknown",
                    arg_name or "Unknown",
                    err,
                    short = True
                    )
예제 #4
0
    def shape_call(self, call, window=True, str_accessors=False):
        # TODO: error if mutate receives a literal value?
        if str_accessors and isinstance(call, str):
            # verbs that can use strings as accessors, like group_by, or
            # arrange, need to convert those strings into a getitem call
            return str_to_get_item_call(call)
        elif not isinstance(call, Call):
            # verbs that use literal strings, need to convert them to a call
            # that returns a sqlalchemy "literal" object
            return Lazy(sql.literal(call))

        f_dict1 = self.funcs['scalar']
        f_dict2 = self.funcs['window' if window else 'aggregate']

        funcs = {**f_dict1, **f_dict2}
        call_shaper = CallTreeLocal(funcs,
                                    rm_attr=self.rm_attr,
                                    call_sub_attr=self.call_sub_attr)

        return call_shaper.enter(call)