def to_ruby(self, schema): output = CaseOp("case", [ WhenOp("when", self.lhs.missing(), **{"then": NotOp("not", self.rhs.missing())}), WhenOp("when", self.rhs.missing(), **{"then": NotOp("not", self.lhs.missing())}), NotOp("not", BasicEqOp("eq", [self.lhs, self.rhs])) ]).partial_eval().to_ruby(schema) return output
def to_painless(self, schema): return CaseOp("case", [ WhenOp("when", self.lhs.missing(), ** {"then": NotOp("not", self.rhs.missing())}), WhenOp("when", self.rhs.missing(), ** {"then": NotOp("not", self.lhs.missing())}), NotOp("not", BasicEqOp("eq", [self.lhs, self.rhs])) ]).partial_eval().to_painless(schema)
def partial_eval(self): lhs = self.lhs.partial_eval() rhs = self.rhs.partial_eval() if is_literal(lhs) and is_literal(rhs): return TRUE if builtin_ops["eq"](lhs.value, rhs.value) else FALSE else: rhs_missing = rhs.missing().partial_eval() return CaseOp([ WhenOp(lhs.missing(), **{"then": rhs_missing}), WhenOp(rhs_missing, **{"then": FALSE}), SqlEqOp([lhs, rhs]) ]).partial_eval()
def partial_eval(self): lhs = self.lhs.partial_eval() rhs = self.rhs.partial_eval() if isinstance(lhs, Literal) and isinstance(rhs, Literal): return TRUE if builtin_ops["eq"](lhs.value, rhs.value) else FALSE else: rhs_missing = rhs.missing().partial_eval() return CaseOp("case", [ WhenOp("when", lhs.missing(), **{"then": rhs_missing}), WhenOp("when", rhs_missing, **{"then": FALSE}), SqlEqOp("eq", [lhs, rhs]) ]).partial_eval()
def to_esfilter(self, schema): if isinstance(self.lhs, Variable) and isinstance(self.rhs, Literal): rhs = self.rhs.value lhs = self.lhs.var cols = schema.leaves(lhs) if cols: lhs = cols[0].es_column if isinstance(rhs, list): if len(rhs) == 1: return {"term": {lhs: rhs[0]}} else: return {"terms": {lhs: rhs}} else: return {"term": {lhs: rhs}} else: return CaseOp("case", [ WhenOp("when", self.lhs.missing(), **{"then": self.rhs.missing()}), WhenOp("when", self.rhs.missing(), **{"then": FALSE}), BasicEqOp("eq", [self.lhs, self.rhs]) ]).partial_eval().to_esfilter(schema)
def to_ruby(self, schema): return CaseOp("case", [ WhenOp("when", self.lhs.missing(), **{"then": self.rhs.missing()}), WhenOp("when", self.rhs.missing(), **{"then": FALSE}), BasicEqOp("eq", [self.lhs, self.rhs]) ]).partial_eval().to_ruby(schema)
def to_es14_script(self, schema, not_null=False, boolean=False, many=True): return CaseOp("case", [ WhenOp("when", self.lhs.missing(), **{"then": NotOp("not", self.rhs.missing())}), WhenOp("when", self.rhs.missing(), **{"then": NotOp("not", self.lhs.missing())}), NotOp("not", BasicEqOp("eq", [self.lhs, self.rhs])) ]).partial_eval().to_es14_script(schema)