コード例 #1
0
def to_ruby(self, schema):
    acc = NumberOp("number", self.terms[-1]).partial_eval().to_ruby(schema).expr
    for t in reversed(self.terms[0:-1]):
        acc = "Math.min(" + NumberOp("number", t).partial_eval().to_ruby(schema).expr + " , " + acc + ")"
    return Ruby(
        miss=AndOp("or", [t.missing() for t in self.terms]),
        type=NUMBER,
        expr=acc,
        frum=self
    )
コード例 #2
0
def to_es14_script(self, schema, not_null=False, boolean=False, many=True):
    acc = NumberOp("number", self.terms[-1]).partial_eval().to_es14_script(schema).expr
    for t in reversed(self.terms[0:-1]):
        acc = "Math.min(" + NumberOp("number", t).partial_eval().to_es14_script(schema).expr + " , " + acc + ")"
    return EsScript(
        miss=AndOp("or", [t.missing() for t in self.terms]),
        type=NUMBER,
        expr=acc,
        frum=self
    )
コード例 #3
0
def to_ruby(self, schema):
    lhs = NumberOp("number", self.lhs).partial_eval().to_ruby(schema).expr
    rhs = NumberOp("number", self.rhs).partial_eval().to_ruby(schema).expr
    script = "(" + lhs + ") " + BinaryOp.operators[self.op] + " (" + rhs + ")"
    missing = OrOp("or", [self.lhs.missing(), self.rhs.missing()])

    return WhenOp(
        "when", missing, **{
            "then": self.default,
            "else": Ruby(type=NUMBER, expr=script, frum=self)
        }).partial_eval().to_ruby(schema)
コード例 #4
0
def to_ruby(self, schema):
    lhs = NumberOp("number", self.lhs).partial_eval().to_ruby(schema).expr
    rhs = NumberOp("number", self.rhs).partial_eval().to_ruby(schema).expr
    script = "(" + lhs + ") " + InequalityOp.operators[
        self.op] + " (" + rhs + ")"

    output = WhenOp(
        "when",
        OrOp("or", [self.lhs.missing(), self.rhs.missing()]), **{
            "then": FALSE,
            "else": Ruby(type=BOOLEAN, expr=script, frum=self)
        }).partial_eval().to_ruby(schema)
    return output
コード例 #5
0
ファイル: expressions.py プロジェクト: rv404674/TUID
def to_es_script(self, schema):
    lhs = NumberOp("number", self.lhs).partial_eval()
    rhs = NumberOp("number", self.rhs).partial_eval()
    script = "(" + lhs.to_es_script(schema).expr + ") / (" + rhs.to_es_script(schema).expr + ")"

    output = WhenOp(
        "when",
        OrOp("or", [self.lhs.missing(), self.rhs.missing(), EqOp("eq", [self.rhs, ZERO])]),
        **{
            "then": self.default,
            "else": EsScript(type=NUMBER, expr=script, frum=self)
        }
    ).partial_eval().to_es_script(schema)

    return output
コード例 #6
0
def to_es14_script(self, schema, not_null=False, boolean=False, many=True):
    lhs = NumberOp("number", self.lhs).partial_eval().to_es14_script(schema).expr
    rhs = NumberOp("number", self.rhs).partial_eval().to_es14_script(schema).expr
    script = "(" + lhs + ") " + InequalityOp.operators[self.op] + " (" + rhs + ")"

    output = WhenOp(
        "when",
        OrOp("or", [self.lhs.missing(), self.rhs.missing()]),
        **{
            "then": FALSE,
            "else":
                EsScript(type=BOOLEAN, expr=script, frum=self)
        }
    ).partial_eval().to_es14_script(schema)
    return output
コード例 #7
0
def to_es14_script(self, schema, not_null=False, boolean=False, many=True):
    lhs = NumberOp("number", self.lhs).partial_eval().to_es14_script(schema).expr
    rhs = NumberOp("number", self.rhs).partial_eval().to_es14_script(schema).expr
    script = "(" + lhs + ") " + BinaryOp.operators[self.op] + " (" + rhs + ")"
    missing = OrOp("or", [self.lhs.missing(), self.rhs.missing()])

    return WhenOp(
        "when",
        missing,
        **{
            "then": self.default,
            "else":
                EsScript(type=NUMBER, expr=script, frum=self)
        }
    ).partial_eval().to_es14_script(schema)
コード例 #8
0
def to_ruby(self, schema):
    op, unit = MultiOp.operators[self.op]
    if self.nulls:
        calc = op.join(
            "((" + t.missing().to_ruby(schema).expr + ") ? " + unit + " : (" +
            NumberOp("number", t).partial_eval().to_ruby(schema).expr + "))"
            for t in self.terms)
        return WhenOp(
            "when", AndOp("and", [t.missing() for t in self.terms]), **{
                "then": self.default,
                "else": Ruby(type=NUMBER, expr=calc, frum=self)
            }).partial_eval().to_ruby(schema)
    else:
        calc = op.join("(" + NumberOp("number", t).to_ruby(schema).expr + ")"
                       for t in self.terms)
        return WhenOp(
            "when", OrOp("or", [t.missing() for t in self.terms]), **{
                "then": self.default,
                "else": Ruby(type=NUMBER, expr=calc, frum=self)
            }).partial_eval().to_ruby(schema)
コード例 #9
0
def to_ruby(self, schema):
    v = StringOp("string", self.value).partial_eval().to_ruby(schema).expr
    l = NumberOp("number", self.length).partial_eval().to_ruby(schema).expr

    expr = "(" + v + ").substring((int)Math.max(0, (int)Math.min(" + v + ".length(), " + l + ")))"
    return Ruby(miss=OrOp(
        "or",
        [self.value.missing(), self.length.missing()]),
                type=STRING,
                expr=expr,
                frum=self)
コード例 #10
0
def to_es14_script(self, schema, not_null=False, boolean=False, many=True):
    v = StringOp("string", self.value).partial_eval().to_es14_script(schema).expr
    l = NumberOp("number", self.length).partial_eval().to_es14_script(schema).expr

    expr = "(" + v + ").substring((int)Math.max(0, (int)Math.min(" + v + ".length(), " + l + ")))"
    return EsScript(
        miss=OrOp("or", [self.value.missing(), self.length.missing()]),
        type=STRING,
        expr=expr,
        frum=self
    )
コード例 #11
0
def to_ruby(self, schema):
    term = FirstOp("first", self.term).partial_eval()
    value = term.to_ruby(schema)

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

    if value.type == BOOLEAN:
        return Ruby(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr=value.expr + " ? 1 : 0",
            frum=self
        )
    elif value.type == INTEGER:
        return Ruby(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr=value.expr,
            frum=self
        )
    elif value.type == NUMBER:
        return Ruby(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr=value.expr,
            frum=self
        )
    elif value.type == STRING:
        return Ruby(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr="Double.parseDouble(" + value.expr + ")",
            frum=self
        )
    elif value.type == OBJECT:
        return Ruby(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr="((" + value.expr + ") instanceof String) ? Double.parseDouble(" + value.expr + ") : (" + value.expr + ")",
            frum=self
        )
コード例 #12
0
def to_ruby(self, schema):
    lhs = NumberOp("number", self.lhs).partial_eval()
    rhs = NumberOp("number", self.rhs).partial_eval()
    script = "(" + lhs.to_ruby(schema).expr + ") / (" + rhs.to_ruby(schema).expr + ")"

    output = WhenOp(
        "when",
        OrOp("or", [self.lhs.missing(), self.rhs.missing(), EqOp("eq", [self.rhs, ZERO])]),
        **{
            "then": self.default,
            "else": Ruby(type=NUMBER, expr=script, frum=self)
        }
    ).partial_eval().to_ruby(schema)

    return output
コード例 #13
0
def to_es14_script(self, schema, not_null=False, boolean=False, many=True):
    lhs = NumberOp("number", self.lhs).partial_eval()
    rhs = NumberOp("number", self.rhs).partial_eval()
    script = "(" + lhs.to_es14_script(schema).expr + ") / (" + rhs.to_es14_script(schema).expr + ")"

    output = WhenOp(
        "when",
        OrOp("or", [self.lhs.missing(), self.rhs.missing(), EqOp("eq", [self.rhs, ZERO])]),
        **{
            "then": self.default,
            "else": EsScript(type=NUMBER, expr=script, frum=self)
        }
    ).partial_eval().to_es14_script(schema)

    return output
コード例 #14
0
def to_es14_script(self, schema, not_null=False, boolean=False, many=True):
    op, unit = _painless_operators[self.op]
    if self.nulls:
        calc = op.join(
            "((" + t.missing().to_es14_script(schema).expr + ") ? " + unit + " : (" + NumberOp("number", t).partial_eval().to_es14_script(schema).expr + "))"
            for t in self.terms
        )
        return WhenOp(
            "when",
            AndOp("and", [t.missing() for t in self.terms]),
            **{"then": self.default, "else": EsScript(type=NUMBER, expr=calc, frum=self)}
        ).partial_eval().to_es14_script(schema)
    else:
        calc = op.join(
            "(" + NumberOp("number", t).to_es14_script(schema).expr + ")"
            for t in self.terms
        )
        return WhenOp(
            "when",
            OrOp("or", [t.missing() for t in self.terms]),
            **{"then": self.default, "else": EsScript(type=NUMBER, expr=calc, frum=self)}
        ).partial_eval().to_es14_script(schema)