Exemplo n.º 1
0
    def to_esfilter(self, schema):
        if is_op(self.value, Variable_):
            var = self.value.var
            cols = schema.leaves(var)
            if not cols:
                Log.error("expecting {{var}} to be a column", var=var)
            col = first(cols)
            var = col.es_column

            if col.jx_type == BOOLEAN:
                if is_literal(self.superset) and not is_sequence(
                        self.superset.value):
                    return {"term": {var: value2boolean(self.superset.value)}}
                else:
                    return {
                        "terms": {
                            var: map(value2boolean, self.superset.value)
                        }
                    }
            else:
                if is_literal(self.superset) and not is_sequence(
                        self.superset.value):
                    return {"term": {var: self.superset.value}}
                else:
                    return {"terms": {var: self.superset.value}}
        else:
            return Painless[self].to_es_script(schema).to_esfilter(schema)
Exemplo n.º 2
0
    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 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: 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}}
        else:
            return Painless[self].to_es_script(schema).to_esfilter(schema)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)