Пример #1
0
def to_ruby(self, schema):
    if not self.terms:
        return TRUE.to_ruby()
    else:
        return Ruby(miss=FALSE,
                    type=BOOLEAN,
                    expr=" && ".join("(" + t.to_ruby(schema).expr + ")"
                                     for t in self.terms),
                    frum=self)
Пример #2
0
def to_ruby(self, schema):
    value = self.term.to_ruby(schema)
    if value.expr or value.i:
        return TRUE.to_ruby(schema)
    else:
        return Ruby(miss=FALSE,
                    type=BOOLEAN,
                    expr="(" + value.expr + ") instanceof java.lang.Double",
                    frum=self)
Пример #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
        )
def to_es14_script(self, schema, not_null=False, boolean=False, many=True):
    if not self.terms:
        return TRUE.to_es14_script()
    else:
        return EsScript(
            miss=FALSE,
            type=BOOLEAN,
            expr=" && ".join("(" + t.to_es14_script(schema).expr + ")" for t in self.terms),
            frum=self
        )
Пример #5
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,
         )
Пример #6
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
        )
def to_es14_script(self, schema, not_null=False, boolean=False, many=True):
    value = self.term.to_es14_script(schema)
    if value.expr or value.i:
        return TRUE.to_es14_script(schema)
    else:
        return EsScript(
            miss=FALSE,
            type=BOOLEAN,
            expr="(" + value.expr + ") instanceof java.lang.Double",
            frum=self
        )
Пример #8
0
    def to_bq(self, schema, not_null=False, boolean=False):
        if not self.terms:
            return TRUE.to_bq(schema)

        return BQLScript(
            expr=JoinSQL(SQL_AND, [self.lang[t].to_bq(schema) for t in self.terms if t != None]),
            data_type=BOOLEAN,
            frum=self,
            miss=FALSE,
            schema=schema,
        )
Пример #9
0
 def to_bq(self, schema, not_null=False, boolean=False):
     term = BQLang[self.term].partial_eval()
     if term.type == "boolean":
         sql = term.to_bq(schema)
         return sql
     elif is_literal(term) and term.value in ("T", "F"):
         if term.value == "T":
             return TRUE.to_bq(schema)
         else:
             return FALSE.to_bq(schema)
     else:
         sql = term.exists().partial_eval().to_bq(schema)
         return sql
Пример #10
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,
                )