def partial_eval(self): term = self.lang[FirstOp(self.term)].partial_eval() if is_literal(term): if term is NULL: return NULL elif term is FALSE: return ZERO elif term is TRUE: return ONE v = term.value if isinstance(v, (text, Date)): return self.lang[Literal(float(v))] elif isinstance(v, (int, float)): return term else: Log.error("can not convert {{value|json}} to number", value=term.value) elif is_op(term, CaseOp): # REWRITING return self.lang[CaseOp([ WhenOp(t.when, **{"then": NumberOp(t.then)}) for t in term.whens[:-1] ] + [NumberOp(term.whens[-1])])].partial_eval() elif is_op(term, WhenOp): # REWRITING return self.lang[WhenOp( term.when, **{ "then": NumberOp(term.then), "else": NumberOp(term.els_) })].partial_eval() elif is_op(term, CoalesceOp): return self.lang[CoalesceOp([NumberOp(t) for t in term.terms])] return self.lang[NumberOp(term)]
def partial_eval(self): term = self.lang[FirstOp(self.term)].partial_eval() if is_op(term, CoalesceOp): return self.lang[CoalesceOp([IntegerOp(t) for t in term.terms])] if term.type == INTEGER: return term return self.lang[IntegerOp(term)]
def partial_eval(self, lang): term = FirstOp(self.term).partial_eval(lang) if is_op(term, CoalesceOp): return (CoalesceOp([IntegerOp(t) for t in term.terms])) if term.type == INTEGER: return term return (IntegerOp(term))
def partial_eval(self): term = self.term if term.type is IS_NULL: return NULL term = self.lang[FirstOp(term)].partial_eval() if is_op(term, StringOp): return term.term.partial_eval() elif is_op(term, CoalesceOp): return self.lang[CoalesceOp( [self.lang[StringOp(t)].partial_eval() for t in term.terms])] elif is_literal(term): if term.type == STRING: return term else: return self.lang[Literal(mo_json.value2json(term.value))] return self
def partial_eval(self, lang): term = self.term if term.type is IS_NULL: return NULL term = (FirstOp(term)).partial_eval(lang) if is_op(term, StringOp): return term.term.partial_eval(lang) elif is_op(term, CoalesceOp): return CoalesceOp([ (StringOp(t)).partial_eval(lang) for t in term.terms ]) elif is_literal(term): if term.type == STRING: return term else: return (Literal(mo_json.value2json(term.value))) return self
def partial_eval(self): terms = [] for t in self.terms: simple = self.lang[FirstOp(t)].partial_eval() if simple is NULL: pass elif is_literal(simple): terms.append(simple) break else: terms.append(simple) if len(terms) == 0: return NULL elif len(terms) == 1: return terms[0] else: return self.lang[CoalesceOp(terms)]