def invert(self, lang): this = self.partial_eval(lang) if is_op(this, BasicInOp): inv = NotOp(this) inv.simplified = True return inv else: return this.invert(lang)
def invert(self, lang): this = self.partial_eval(lang) if is_op(this, InOp): inv = NotOp(BasicInOp([this.value, this.superset])) inv.simplified = True return OrOp([MissingOp(this.value), inv]) else: return this.invert(lang)
def invert(self, lang): output = self.expr.missing(lang) if is_op(output, MissingOp): # break call cycle return (NotOp(output)) else: return (output.invert(lang))
def partial_eval(self): when = self.lang[BooleanOp(self.when)].partial_eval() if when is TRUE: return self.lang[self.then].partial_eval() elif when in [FALSE, NULL]: return self.lang[self.els_].partial_eval() elif is_op(when, Literal): Log.error("Expecting `when` clause to return a Boolean, or `null`") then = self.lang[self.then].partial_eval() els_ = self.lang[self.els_].partial_eval() if then is TRUE: if els_ is FALSE: return when elif els_ is TRUE: return TRUE elif then is FALSE: if els_ is FALSE: return FALSE elif els_ is TRUE: return self.lang[NotOp(when)].partial_eval() return self.lang[WhenOp(when, **{"then": then, "else": els_})]
def partial_eval(self, lang): if self.type == BOOLEAN: nots = [] ors = [] for w in self.whens[:-1]: ors.append(AndOp(nots + [w.when, w.then])) nots.append(NotOp(w.when)) ors.append(AndOp(nots + [self.whens[-1]])) return (OrOp(ors)).partial_eval(lang) whens = [] for w in self.whens[:-1]: when = (w.when).partial_eval(lang) if when is TRUE: whens.append((w.then).partial_eval(lang)) break elif when is FALSE: pass else: whens.append( WhenOp(when, **{"then": w.then.partial_eval(lang)})) else: whens.append((self.whens[-1]).partial_eval(lang)) if len(whens) == 1: return whens[0] elif len(whens) == 2: return WhenOp(whens[0].when, **{ "then": whens[0].then, "else": whens[1] }) else: return CaseOp(whens)
def missing(self): return OrOp([ NotOp(self.where), # self.path.missing(), ASSUME PATH TO TABLES, WHICH ASSUMED TO HAVE DATA (EXISTS) # self.select.missing(), EqOp([self.limit, ZERO]) ]).partial_eval()
def invert(self): output = self.expr.missing() if is_op(output, MissingOp): # break call cycle return self.lang[NotOp(output)] else: return self.lang[output.invert()]
def partial_eval(self): if self.type == BOOLEAN: nots = [] ors = [] for w in self.whens[:-1]: ors.append(AndOp(nots + [w.when, w.then])) nots.append(NotOp(w.when)) ors.append(AndOp(nots + [self.whens[-1]])) return self.lang[OrOp(ors)].partial_eval() whens = [] for w in self.whens[:-1]: when = self.lang[w.when].partial_eval() if when is TRUE: whens.append(self.lang[w.then].partial_eval()) break elif when is FALSE: pass else: whens.append(self.lang[WhenOp( when, **{"then": w.then.partial_eval()})]) else: whens.append(self.lang[self.whens[-1]].partial_eval()) if len(whens) == 1: return whens[0] elif len(whens) == 2: return self.lang[WhenOp( whens[0].when, **{ "then": whens[0].then, "else": whens[1] })] else: return self.lang[CaseOp(whens)]
def partial_eval(self, lang): when = (BooleanOp(self.when)).partial_eval(lang) if when is TRUE: return (self.then).partial_eval(lang) elif when in [FALSE, NULL]: return (self.els_).partial_eval(lang) elif is_op(when, Literal): Log.error("Expecting `when` clause to return a Boolean, or `null`") then = (self.then).partial_eval(lang) els_ = (self.els_).partial_eval(lang) if then is TRUE: if els_ is FALSE: return when elif els_ is TRUE: return TRUE elif then is FALSE: if els_ is FALSE: return FALSE elif els_ is TRUE: return (NotOp(when)).partial_eval(lang) return (WhenOp(when, **{"then": then, "else": els_}))
def invert(self): return self.lang[ OrOp( [ AndOp([self.when, self.then.invert()]), AndOp([NotOp(self.when), self.els_.invert()]), ] ) ].partial_eval()
def missing(self): return self.lang[ OrOp( [ AndOp([self.when, self.then.missing()]), AndOp([NotOp(self.when), self.els_.missing()]), ] ) ].partial_eval()
def partial_eval(self, lang): lhs = (self.lhs).partial_eval(lang) rhs = (self.rhs).partial_eval(lang) if is_op(lhs, NestedOp): return NestedOp( path=lhs.path.partial_eval(lang), select=IDENTITY, where=AndOp([lhs.where, NeOp([lhs.select, rhs])]).partial_eval(lang), sort=lhs.sort.partial_eval(lang), limit=lhs.limit.partial_eval(lang), ).partial_eval(lang) output =AndOp([ lhs.exists(), rhs.exists(), NotOp(BasicEqOp([lhs, rhs])), ]).partial_eval(lang) return output
def partial_eval(self): lhs = self.lang[self.lhs].partial_eval() rhs = self.lang[self.rhs].partial_eval() if is_op(lhs, NestedOp): return self.lang[NestedOp( path=lhs.frum.partial_eval(), select=IDENTITY, where=AndOp([lhs.where, NeOp([lhs.select, rhs])]).partial_eval(), sort=lhs.sort.partial_eval(), limit=lhs.limit.partial_eval() )].partial_eval() output = self.lang[AndOp([ lhs.exists(), rhs.exists(), NotOp(BasicEqOp([lhs, rhs])) ])].partial_eval() return output
def partial_eval(self): output = self.lang[NotOp(EqOp([self.lhs, self.rhs]))].partial_eval() return output
def invert(self, lang): return OrOp([ AndOp([self.when, self.then.invert(lang)]), AndOp([NotOp(self.when), self.els_.invert(lang)]), ]).partial_eval(lang)
def missing(self, lang): return OrOp([ AndOp([self.when, self.then.missing(lang)]), AndOp([NotOp(self.when), self.els_.missing(lang)]), ]).partial_eval(lang)