Exemple #1
0
def to_painless(self, schema):
    term = FirstOp("first", self.term).partial_eval()
    value = term.to_painless(schema)

    if isinstance(value.frum, CoalesceOp):
        return CoalesceOp(
            "coalesce",
            [StringOp("string", t).partial_eval()
             for t in value.frum.terms]).to_painless(schema)

    if value.type == BOOLEAN:
        return Painless(miss=self.term.missing().partial_eval(),
                        type=STRING,
                        expr=value.expr + ' ? "T" : "F"',
                        frum=self)
    elif value.type == INTEGER:
        return Painless(miss=self.term.missing().partial_eval(),
                        type=STRING,
                        expr="String.valueOf(" + value.expr + ")",
                        frum=self)
    elif value.type == NUMBER:
        return Painless(miss=self.term.missing().partial_eval(),
                        type=STRING,
                        expr=expand_template(TO_STRING, {"expr": value.expr}),
                        frum=self)
    elif value.type == STRING:
        return value
    else:
        return Painless(miss=self.term.missing().partial_eval(),
                        type=STRING,
                        expr=expand_template(TO_STRING, {"expr": value.expr}),
                        frum=self)
Exemple #2
0
def to_painless(self, schema):
    term = FirstOp("first", self.term).partial_eval()
    value = term.to_painless(schema)

    if isinstance(value.frum, CoalesceOp):
        return CoalesceOp("coalesce", [NumberOp("number", t).partial_eval().to_painless(schema) for t in value.frum.terms]).to_painless(schema)

    if value.type == BOOLEAN:
        return Painless(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr=value.expr + " ? 1 : 0",
            frum=self
        )
    elif value.type == INTEGER:
        return Painless(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr=value.expr,
            frum=self
        )
    elif value.type == NUMBER:
        return Painless(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr=value.expr,
            frum=self
        )
    elif value.type == STRING:
        return Painless(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr="Double.parseDouble(" + value.expr + ")",
            frum=self
        )
    elif value.type == OBJECT:
        return Painless(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr="((" + value.expr + ") instanceof String) ? Double.parseDouble(" + value.expr + ") : (" + value.expr + ")",
            frum=self
        )