Exemple #1
0
def to_es_script(self, schema):
    if not self.terms:
        return TRUE.to_es_script()
    else:
        return EsScript(miss=FALSE,
                        type=BOOLEAN,
                        expr=" && ".join("(" + t.to_es_script(schema).expr +
                                         ")" for t in self.terms),
                        frum=self)
Exemple #2
0
def to_es_script(self, schema):
    value = self.term.to_es_script(schema)
    if value.expr or value.i:
        return TRUE.to_es_script(schema)
    else:
        return EsScript(miss=FALSE,
                        type=BOOLEAN,
                        expr="(" + value.expr +
                        ") instanceof java.lang.Double",
                        frum=self)
Exemple #3
0
def to_es_script(self, schema):
    if not self.terms:
        return TRUE.to_es_script()
    else:
        return EsScript(
            miss=FALSE,
            type=BOOLEAN,
            expr=" && ".join("(" + t.to_es_script(schema).expr + ")" for t in self.terms),
            frum=self
        )
Exemple #4
0
 def to_es_script(self, schema, not_null=False, boolean=False, many=True):
     if not self.terms:
         return TRUE.to_es_script()
     else:
         return EsScript(
             type=BOOLEAN,
             expr=" && ".join("(" + Painless[t].to_es_script(schema).expr +
                              ")" for t in self.terms),
             frum=self,
             schema=schema,
         )
Exemple #5
0
def to_es_script(self, schema):
    value = self.term.to_es_script(schema)
    if value.expr or value.i:
        return TRUE.to_es_script(schema)
    else:
        return EsScript(
            miss=FALSE,
            type=BOOLEAN,
            expr="(" + value.expr + ") instanceof java.lang.Double",
            frum=self
        )
Exemple #6
0
 def to_es_script(self, schema, not_null=False, boolean=False, many=True):
     if not self.terms:
         return TRUE.to_es_script()
     else:
         return EsScript(
             type=BOOLEAN,
             expr=" && ".join(
                 "(" + Painless[t].to_es_script(schema).expr + ")"
                 for t in self.terms
             ),
             frum=self,
             schema=schema,
         )
    def to_es_script(self, schema, not_null=False, boolean=False, many=True):
        simple_rhs = Painless[self.rhs].partial_eval()
        lhs = Painless[self.lhs].partial_eval().to_es_script(schema)
        rhs = simple_rhs.to_es_script(schema)

        if lhs.many:
            if rhs.many:
                return AndOp([
                    EsScript(
                        type=BOOLEAN,
                        expr="(" + lhs.expr + ").size()==(" + rhs.expr +
                        ").size()",
                        frum=self,
                        schema=schema,
                    ),
                    EsScript(
                        type=BOOLEAN,
                        expr="(" + rhs.expr + ").containsAll(" + lhs.expr +
                        ")",
                        frum=self,
                        schema=schema,
                    ),
                ]).to_es_script(schema)
            else:
                if lhs.type == BOOLEAN:
                    if is_literal(simple_rhs) and simple_rhs.value in ("F",
                                                                       False):
                        return EsScript(type=BOOLEAN,
                                        expr="!" + lhs.expr,
                                        frum=self,
                                        schema=schema)
                    elif is_literal(simple_rhs) and simple_rhs.value in ("T",
                                                                         True):
                        return EsScript(type=BOOLEAN,
                                        expr=lhs.expr,
                                        frum=self,
                                        schema=schema)
                    else:
                        return EsScript(
                            type=BOOLEAN,
                            expr="(" + lhs.expr + ")==(" + rhs.expr + ")",
                            frum=self,
                            schema=schema,
                        )
                elif lhs.type == rhs.type:
                    return EsScript(
                        type=BOOLEAN,
                        expr="(" + lhs.expr + ").contains(" + rhs.expr + ")",
                        frum=self,
                        schema=schema,
                    )
                elif lhs.type == NUMBER and rhs.type == INTEGER:
                    return EsScript(
                        type=BOOLEAN,
                        expr="(" + lhs.expr + ").contains((double)" +
                        rhs.expr + ")",
                        frum=self,
                        schema=schema,
                    )
                else:
                    Log.error(
                        "type mismatch not expected while converting to painless"
                    )

        elif rhs.many:
            return EsScript(
                type=BOOLEAN,
                expr="(" + rhs.expr + ").contains(" + lhs.expr + ")",
                frum=self,
                schema=schema,
            )
        else:
            if lhs is null_script:
                if rhs is null_script:
                    return TRUE.to_es_script(schema)
                return FALSE.to_es_script(schema)
            elif lhs.type == BOOLEAN:
                if is_literal(simple_rhs) and simple_rhs.value in ("F", False):
                    return EsScript(type=BOOLEAN,
                                    expr="!" + lhs.expr,
                                    frum=self,
                                    schema=schema)
                elif is_literal(simple_rhs) and simple_rhs.value in ("T",
                                                                     True):
                    return EsScript(type=BOOLEAN,
                                    expr=lhs.expr,
                                    frum=self,
                                    schema=schema)
                else:
                    return EsScript(
                        type=BOOLEAN,
                        expr="(" + lhs.expr + ")==(" + rhs.expr + ")",
                        frum=self,
                        schema=schema,
                    )
            else:
                return EsScript(
                    type=BOOLEAN,
                    expr="(" + lhs.expr + ")==(" + rhs.expr + ")",
                    frum=self,
                    schema=schema,
                )