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 { "bool": { "must_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_painless(schema) rhs = self.rhs.partial_eval().to_painless(schema) if lhs.many: if rhs.many: return wrap({ "bool": { "must_not": ScriptOp("script", ("(" + lhs.expr + ").size()==(" + rhs.expr + ").size() && " + "(" + rhs.expr + ").containsAll(" + lhs.expr + ")")).to_esfilter(schema) } }) else: return wrap({ "bool": { "must_not": ScriptOp( "script", "(" + lhs.expr + ").contains(" + rhs.expr + ")").to_esfilter(schema) } }) else: if rhs.many: return wrap({ "bool": { "must_not": ScriptOp( "script", "(" + rhs.expr + ").contains(" + lhs.expr + ")").to_esfilter(schema) } }) else: return wrap({ "bool": { "must": ScriptOp("script", "(" + lhs.expr + ") != (" + rhs.expr + ")").to_esfilter(schema) } })
def to_esfilter(self, schema): if isinstance(self.expr, Variable): cols = schema.leaves(self.expr.var) if not cols: return {"match_all": {}} elif len(cols) == 1: return { "bool": { "must_not": { "exists": { "field": cols[0].es_column } } } } else: return { "bool": { "must": [{ "bool": { "must_not": { "exists": { "field": c.es_column } } } } for c in cols] } } else: return ScriptOp( "script", self.to_painless(schema).script(schema)).to_esfilter(schema)
def to_esfilter(self, schema): if not self.field: return {"match_all": {}} elif isinstance(self.field, Variable) and isinstance(self.prefix, Literal): var = schema.leaves(self.field.var)[0].es_column return {"regexp": {var: ".*"+string2regexp(self.prefix.value)}} else: return ScriptOp("script", self.to_painless(schema).script(schema)).to_esfilter(schema)
def to_esfilter(self, schema): if not self.field: return {"match_all": {}} elif isinstance(self.field, Variable) and isinstance(self.prefix, Literal): var = schema.leaves(self.field.var)[0].es_column return {"prefix": {var: self.prefix.value}} else: return ScriptOp("script", self.to_ruby(schema).script(schema)).to_esfilter(schema)
def to_es14_filter(self, schema): if not self.expr: return {"match_all": {}} elif isinstance(self.expr, Variable) and isinstance(self.prefix, Literal): var = first(schema.leaves(self.expr.var)).es_column return {"prefix": {var: self.prefix.value}} else: return ScriptOp("script", self.to_es14_script(schema).script(schema)).to_es14_filter(schema)
def to_es14_filter(self, schema): if not self.suffix: return {"match_all": {}} elif isinstance(self.expr, Variable) and isinstance(self.suffix, Literal): var = first(schema.leaves(self.expr.var)).es_column return {"regexp": {var: ".*"+string2regexp(self.suffix.value)}} else: return ScriptOp("script", self.to_es14_script(schema).script(schema)).to_es14_filter(schema)
def to_esfilter(self, schema): if isinstance(self.value, Variable): var = self.value.var cols = schema.leaves(var) if cols: var = cols[0].es_column return {"terms": {var: self.superset.value}} else: return ScriptOp("script", self.to_ruby(schema).script(schema)).to_esfilter(schema)
def to_esfilter(self, schema): if self.type == BOOLEAN: return OrOp("or", [AndOp("and", [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 ScriptOp( "script", self.to_es_script(schema).script(schema)).to_esfilter(schema)
def to_esfilter(self, schema): if isinstance(self.value, Variable) and isinstance(self.find, Literal): return { "regexp": { self.value.var: ".*" + string2regexp(self.find.value) + ".*" } } else: return ScriptOp( "script", self.to_ruby(schema).script(schema)).to_esfilter(schema)
def to_esfilter(self, schema): if isinstance(self.expr, Variable): cols = schema.leaves(self.expr.var) if not cols: return {"match_all": {}} elif len(cols) == 1: return {"missing": {"field": cols[0].es_column}} else: return {"and": [{"missing": {"field": c.es_column}} for c in cols]} else: return ScriptOp( "script", self.to_ruby(schema).script(schema)).to_esfilter(schema)
def to_esfilter(self, schema): if isinstance(self.expr, Variable): cols = schema.leaves(self.expr.var) if not cols: return {"match_all": {}} elif len(cols) == 1: return es_missing(cols[0].es_column) else: return es_and([es_missing(c.es_column) for c in cols]) else: return ScriptOp( "script", self.to_es_script(schema).script(schema)).to_esfilter(schema)
def to_ruby(self, schema): lhs = self.lhs.to_ruby(schema) rhs = self.rhs.to_ruby(schema) script = "(int)Math.floor(((double)(" + lhs + ") / (double)(" + rhs + ")).doubleValue())*(" + rhs + ")" output = WhenOp( "when", OrOp("or", [self.lhs.missing(), self.rhs.missing(), EqOp("eq", [self.rhs, ZERO])]), **{ "then": self.default, "else": ScriptOp("script", script) } ).to_ruby(schema) return output
def _normalize_window(window, schema=None): v = window.value try: expr = jx_expression(v, schema=schema) except Exception: expr = ScriptOp("script", v) return Data(name=coalesce(window.name, window.value), value=expr, edges=[ n for e in listwrap(window.edges) for n in _normalize_edge(e, schema) ], sort=_normalize_sort(window.sort), aggregate=window.aggregate, range=_normalize_range(window.range), where=_normalize_where(window.where, schema=schema))
def _normalize_window(window, schema=None): v = window.value try: expr = jx_expression(v, schema=schema) except Exception: if hasattr(v, "__call__"): expr = v else: expr = ScriptOp(v) return Data( name=coalesce(window.name, window.value), value=expr, edges=[n for i, e in enumerate(listwrap(window.edges)) for n in _normalize_edge(e, i, limit=None, schema=schema)], sort=_normalize_sort(window.sort), aggregate=window.aggregate, range=_normalize_range(window.range), where=_normalize_where(window.where, schema=schema) )
def to_esfilter(self, schema): return ScriptOp("script", self.to_ruby(schema).script(schema)).to_esfilter(schema)
def to_esfilter(self, schema): return ScriptOp( "", self.to_es_script(schema).script(schema)).to_esfilter(schema)
def to_esfilter(self, schema): return ScriptOp( "script", self.to_painless(schema).script(schema)).to_esfilter(schema)