def to_esfilter(self, schema): if isinstance(self.lhs, Variable) and isinstance(self.rhs, Literal): columns = schema.values(self.lhs.var) if len(columns) == 0: return {"match_all": {}} elif len(columns) == 1: return es_not({"term": {columns[0].es_column: self.rhs.value}}) else: Log.error("column split to multiple, not handled") else: lhs = self.lhs.partial_eval().to_es_script(schema) rhs = self.rhs.partial_eval().to_es_script(schema) if lhs.many: if rhs.many: return es_not( ScriptOp( "script", ("(" + lhs.expr + ").size()==(" + rhs.expr + ").size() && " + "(" + rhs.expr + ").containsAll(" + lhs.expr + ")")).to_esfilter(schema)) else: return es_not( ScriptOp("script", "(" + lhs.expr + ").contains(" + rhs.expr + ")").to_esfilter(schema)) else: if rhs.many: return es_not( ScriptOp("script", "(" + rhs.expr + ").contains(" + lhs.expr + ")").to_esfilter(schema)) else: return es_not( ScriptOp("script", "(" + lhs.expr + ") != (" + rhs.expr + ")").to_esfilter(schema))
def to_es14_filter(self, schema): # OR(x) == NOT(AND(NOT(xi) for xi in x)) output = es_not(es_and([ NotOp("not", t).partial_eval().to_es14_filter(schema) for t in self.terms ])) return output
def to_esfilter(self, schema): # OR(x) == NOT(AND(NOT(xi) for xi in x)) output = es_not(es_and([ NotOp("not", t).partial_eval().to_esfilter(schema) for t in self.terms ])) return output
def to_esfilter(self, schema): if isinstance(self.term, MissingOp) and isinstance(self.term.expr, Variable): v = self.term.expr.var cols = schema.leaves(v) if cols: v = cols[0].es_column return {"exists": {"field": v}} else: operand = self.term.to_esfilter(schema) return es_not(operand)
def to_es14_filter(self, schema): if isinstance(self.term, MissingOp) and isinstance(self.term.expr, Variable): v = self.term.expr.var cols = schema.leaves(v) if cols: v = first(cols).es_column return {"exists": {"field": v}} else: operand = self.term.to_es14_filter(schema) return es_not(operand)
def to_esfilter(self, schema): if not isinstance(self.lhs, Variable) or not isinstance(self.rhs, Literal) or self.op in BinaryOp.operators: return self.to_es_script(schema).to_esfilter(schema) if self.op in ["eq", "term"]: return {"term": {self.lhs.var: self.rhs.to_esfilter(schema)}} elif self.op in ["ne", "neq"]: return es_not({"term": {self.lhs.var: self.rhs.to_esfilter(schema)}}) elif self.op in BinaryOp.ineq_ops: return {"range": {self.lhs.var: {self.op: self.rhs.value}}} else: Log.error("Logic error")
def to_es14_filter(self, schema): if not isinstance(self.lhs, Variable) or not isinstance(self.rhs, Literal) or self.op in BinaryOp.operators: return self.to_es14_script(schema).to_es14_filter(schema) if self.op in ["eq", "term"]: return {"term": {self.lhs.var: self.rhs.to_es14_filter(schema)}} elif self.op in ["ne", "neq"]: return es_not({"term": {self.lhs.var: self.rhs.to_es14_filter(schema)}}) elif self.op in BinaryOp.ineq_ops: return {"range": {self.lhs.var: {self.op: self.rhs.value}}} else: Log.error("Logic error")
def to_esfilter(self, schema): if isinstance(self.lhs, Variable) and isinstance(self.rhs, Literal): columns = schema.values(self.lhs.var) if len(columns) == 0: return {"match_all": {}} elif len(columns) == 1: return es_not({"term": {columns[0].es_column: self.rhs.value}}) else: Log.error("column split to multiple, not handled") else: lhs = self.lhs.partial_eval().to_es_script(schema) rhs = self.rhs.partial_eval().to_es_script(schema) if lhs.many: if rhs.many: return es_not( ScriptOp( "script", ( "(" + lhs.expr + ").size()==(" + rhs.expr + ").size() && " + "(" + rhs.expr + ").containsAll(" + lhs.expr + ")" ) ).to_esfilter(schema) ) else: return es_not( ScriptOp("script", "(" + lhs.expr + ").contains(" + rhs.expr + ")").to_esfilter(schema) ) else: if rhs.many: return es_not( ScriptOp("script", "(" + rhs.expr + ").contains(" + lhs.expr + ")").to_esfilter(schema) ) else: return es_not( ScriptOp("script", "(" + lhs.expr + ") != (" + rhs.expr + ")").to_esfilter(schema) )
def to_esfilter(self, schema): return es_not({"match_all": {}})
@extend(BasicSubstringOp) def to_es_script(self, schema): v = StringOp("string", self.value).partial_eval().to_es_script(schema).expr start = IntegerOp("string", self.start).partial_eval().to_es_script(schema).expr end = IntegerOp("integer", self.end).partial_eval().to_es_script(schema).expr return EsScript(miss=FALSE, type=STRING, expr="(" + v + ").substring(" + start + ", " + end + ")", frum=self) MATCH_ALL = wrap({"match_all": {}}) MATCH_NONE = es_not({"match_all": {}}) def simplify_esfilter(esfilter): try: output = wrap(_normalize(wrap(esfilter))) output.isNormal = None return output except Exception as e: from mo_logs import Log Log.unexpected("programmer error", cause=e) def _normalize(esfilter): """
def to_es_script(self, schema): v = StringOp("string", self.value).partial_eval().to_es_script(schema).expr start = IntegerOp("string", self.start).partial_eval().to_es_script(schema).expr end = IntegerOp("integer", self.end).partial_eval().to_es_script(schema).expr return EsScript( miss=FALSE, type=STRING, expr="(" + v + ").substring(" + start + ", " + end + ")", frum=self ) MATCH_ALL = wrap({"match_all": {}}) MATCH_NONE = es_not({"match_all": {}}) def simplify_esfilter(esfilter): try: output = wrap(_normalize(wrap(esfilter))) output.isNormal = None return output except Exception as e: from mo_logs import Log Log.unexpected("programmer error", cause=e) def _normalize(esfilter): """