def to_esfilter(self, schema): output = OrOp([ AndOp([self.when, BooleanOp(self.then)]), AndOp([NotOp(self.when), BooleanOp(self.els_)]), ]).partial_eval() return output.to_esfilter(schema)
def to_esfilter(self, schema): if self.type == BOOLEAN: return (OrOp([AndOp([w.when, w.then]) for w in self.whens[:-1]] + self.whens[-1:]).partial_eval().to_esfilter(schema)) else: Log.error("do not know how to handle") return self.to_es_script(schema).script(schema).to_esfilter(schema)
def to_esfilter(self, schema): if is_op(self.lhs, Variable_) and is_literal(self.rhs): rhs = self.rhs.value lhs = self.lhs.var cols = schema.leaves(lhs) if not cols: Log.warning( "{{col}} does not exist while processing {{expr}}", col=lhs, expr=self.__data__(), ) if is_container(rhs): if len(rhs) == 1: rhs = rhs[0] else: types = Data() # MAP JSON TYPE TO LIST OF LITERALS for r in rhs: types[python_type_to_json_type[r.__class__]] += [r] if len(types) == 1: jx_type, values = first(types.items()) for c in cols: if jx_type == c.jx_type or (jx_type in NUMBER_TYPES and c.jx_type in NUMBER_TYPES): return {"terms": {c.es_column: values}} return FALSE.to_esfilter(schema) else: return (OrOp([ EqOp([self.lhs, values]) for t, values in types.items() ]).partial_eval().to_esfilter(schema)) for c in cols: if c.jx_type == BOOLEAN: rhs = pull_functions[c.jx_type](rhs) rhs_type = python_type_to_json_type[rhs.__class__] if rhs_type == c.jx_type or (rhs_type in NUMBER_TYPES and c.jx_type in NUMBER_TYPES): return {"term": {c.es_column: rhs}} return FALSE.to_esfilter(schema) else: return (ES52[CaseOp([ WhenOp(self.lhs.missing(), **{"then": self.rhs.missing()}), WhenOp(self.rhs.missing(), **{"then": FALSE}), BasicEqOp([self.lhs, self.rhs]), ]).partial_eval()].to_esfilter(schema))
def to_es(self, schema): value = self.value if is_op(value, Variable): var = value.var cols = schema.leaves(var) if not cols: return MATCH_NONE col = first(cols) var = col.es_column if is_literal(self.superset): if col.jx_type == BOOLEAN: if is_literal(self.superset) and not is_many( self.superset.value): return { "term": { var: value2boolean(self.superset.value) } } else: return { "terms": { var: list(map(value2boolean, self.superset.value)) } } else: if is_literal(self.superset) and not is_many( self.superset.value): return {"term": {var: self.superset.value}} else: return {"terms": {var: self.superset.value}} elif is_op(self.superset, TupleOp): return (OrOp([EqOp([value, s]) for s in self.superset.terms ]).partial_eval().to_es(schema)) if (is_op(value, NestedOp) and is_literal(self.superset) and is_op(value.select, Variable)): output = (ES52[NestedOp( path=value.path, select=NULL, where=AndOp([value.where, InOp([value.select, self.superset])]), )].exists().partial_eval().to_es(schema)) return output # THE HARD WAY return Painless[self].to_es_script(schema).to_es(schema)
def to_esfilter(self, schema): if is_op(self.value, Variable_): var = self.value.var cols = schema.leaves(var) if not cols: return MATCH_NONE col = first(cols) var = col.es_column if is_literal(self.superset): if col.jx_type == BOOLEAN: if is_literal(self.superset) and not is_many( self.superset.value): return { "term": { var: value2boolean(self.superset.value) } } else: return { "terms": { var: list(map(value2boolean, self.superset.value)) } } else: if is_literal(self.superset) and not is_many( self.superset.value): return {"term": {var: self.superset.value}} else: return {"terms": {var: self.superset.value}} elif is_op(self.superset, TupleOp): return (OrOp([ EqOp([self.value, s]) for s in self.superset.terms ]).partial_eval().to_esfilter(schema)) # THE HARD WAY return Painless[self].to_es_script(schema).to_esfilter(schema)