def missing(self, lang): m = self.whens[-1].missing(lang) for w in reversed(self.whens[0:-1]): when = w.when.partial_eval(lang) if when is FALSE: pass elif when is TRUE: m = w.then.partial_eval(lang).missing(lang) else: m = OrOp([ AndOp([when, w.then.partial_eval(lang).missing(lang)]), m, ]) return m.partial_eval(lang)
def missing(self): if not self.nests: return TRUE return OrOp( [self.frum.missing()] + [n.missing() for n in self.nests] ).partial_eval()
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 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 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 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 missing(self): if self.default.exists(): return FALSE else: return self.lang[OrOp([ self.lhs.missing(), self.rhs.missing(), EqOp([self.rhs, ZERO]) ])]
def missing(self, lang): return AndOp([ self.default.missing(lang), OrOp([ self.lhs.missing(lang), self.rhs.missing(lang), EqOp([self.rhs, ZERO]), ]), ]).partial_eval(lang)
def missing(self, lang): if self.default.exists(): return FALSE else: return OrOp([ self.lhs.missing(lang), self.rhs.missing(lang), EqOp([self.rhs, ZERO]), ])
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[AndOp([ self.default.missing(), OrOp([ self.lhs.missing(), self.rhs.missing(), EqOp([self.rhs, ZERO]) ]), ])].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 missing(self, lang): if self.nulls: if self.default is NULL: return AndOp([t.missing(lang) for t in self.terms]) else: return TRUE else: if self.default is NULL: return OrOp([t.missing(lang) for t in self.terms]) else: return FALSE
def missing(self): if self.nulls: if self.default is NULL: return self.lang[AndOp([t.missing() for t in self.terms])] else: return TRUE else: if self.default is NULL: return self.lang[OrOp([t.missing() for t in self.terms])] else: return FALSE
def partial_eval(self): acc = None terms = [] for t in self.terms: simple = t.partial_eval() if simple is NULL: pass elif is_literal(simple): if acc is None: acc = simple.value else: acc = builtin_ops[self.op](acc, simple.value) else: terms.append(simple) lang = self.lang if len(terms) == 0: if acc == None: return self.default.partial_eval() else: return lang[Literal(acc)] elif self.nulls: # DECISIVE if acc is not None: terms.append(Literal(acc)) output = lang[ WhenOp( AndOp([t.missing() for t in terms]), **{ "then": self.default, "else": operators["basic." + self.op]( [CoalesceOp([t, _jx_identity[self.op]]) for t in terms] ), } ) ].partial_eval() else: # CONSERVATIVE if acc is not None: terms.append(lang[Literal(acc)]) output = lang[ WhenOp( lang[OrOp([t.missing() for t in terms])], **{ "then": self.default, "else": operators["basic." + self.op](terms), } ) ].partial_eval() return output
def missing(self): m = self.whens[-1].missing() for w in reversed(self.whens[0:-1]): when = w.when.partial_eval() if when is FALSE: pass elif when is TRUE: m = w.then.partial_eval().missing() else: m = self.lang[OrOp( [AndOp([when, w.then.partial_eval().missing()]), m])] return m.partial_eval()
def missing(self): v = self.value.to_es_script(not_null=True) find = self.find.to_es_script(not_null=True) index = v + ".indexOf(" + find + ", " + self.start.to_es_script() + ")" return self.lang[AndOp([ self.default.missing(), OrOp([ self.value.missing(), self.find.missing(), EqOp([ScriptOp(index), Literal(-1)]), ]), ])]
def inverse(term): if term is TRUE: return FALSE elif term is FALSE: return TRUE elif term is NULL: return TRUE elif is_literal(term): Log.error("`not` operator expects a Boolean term") elif is_op(term, WhenOp): output = self.lang[ WhenOp( term.when, **{"then": inverse(term.then), "else": inverse(term.els_)} ) ].partial_eval() elif is_op(term, CaseOp): # REWRITING output = self.lang[ CaseOp( [ WhenOp(w.when, **{"then": inverse(w.then)}) if is_op(w, WhenOp) else inverse(w) for w in term.whens ] ) ].partial_eval() elif is_op(term, AndOp): output = self.lang[ OrOp([inverse(t) for t in term.terms]) ].partial_eval() elif is_op(term, OrOp): output = self.lang[ AndOp([inverse(t) for t in term.terms]) ].partial_eval() elif is_op(term, MissingOp): output = self.lang[NotOp(term.expr.missing())] elif is_op(term, ExistsOp): output = term.field.missing().partial_eval() elif is_op(term, NotOp): output = self.lang[term.term].partial_eval() elif is_op(term, NeOp): output = self.lang[EqOp([term.lhs, term.rhs])].partial_eval() elif is_op(term, BasicIndexOfOp) or is_op(term, BasicSubstringOp): return FALSE else: output = self.lang[NotOp(term)] return output
def invert(self): return self.lang[OrOp([ self.lhs.missing(), self.rhs.missing(), BasicEqOp([self.lhs, self.rhs]) ])].partial_eval()
def missing(self, lang): return OrOp([ self.value.missing(lang), self.length.missing(lang), ]).partial_eval(lang)
def missing(self): return OrOp([self.frum.missing()] + [self.nests[-1].missing()]).partial_eval()
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 exists(self): if self.nulls: return OrOp([t.exists() for t in self.terms]) else: return AndOp([t.exists() for t in self.terms])
def invert(self, lang): return OrOp([ self.lhs.missing(lang), self.rhs.missing(lang), BasicEqOp([self.lhs, self.rhs]), ]).partial_eval(lang)
def exists(self): if self.nulls: return self.lang[OrOp([t.exists() for t in self.terms])] else: return self.lang[AndOp([t.exists() for t in self.terms])]
def missing(self, lang): return OrOp([self.value.missing(lang), self.length.missing(lang)])
def missing(self): return self.lang[OrOp([self.value.missing(), self.length.missing()])].partial_eval()
def missing(self, lang): return OrOp([ AndOp([self.when, self.then.missing(lang)]), AndOp([NotOp(self.when), self.els_.missing(lang)]), ]).partial_eval(lang)