def to_esfilter(self, schema): output = OrOp("or", [ AndOp("and", [self.when, BooleanOp("boolean", self.then)]), AndOp("and", [NotOp("not", self.when), BooleanOp("boolean", self.els_)]) ]).partial_eval() return output.to_esfilter(schema)
def to_esfilter(self, schema): if self.type == BOOLEAN: return OrOp("or", [AndOp("and", [w.when, w.then]) for w in self.whens[:-1]] + self.whens[-1:]).partial_eval().to_esfilter(schema) else: Log.error("do not know how to handle") return ScriptOp( "script", self.to_es_script(schema).script(schema)).to_esfilter(schema)
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)
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)
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 )
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
def to_ruby(self, schema): lhs = self.lhs.to_ruby(schema) rhs = self.rhs.to_ruby(schema) script = "(int)Math.floor(((double)(" + lhs + ") / (double)(" + rhs + ")).doubleValue())*(" + rhs + ")" output = WhenOp( "when", OrOp("or", [self.lhs.missing(), self.rhs.missing(), EqOp("eq", [self.rhs, ZERO])]), **{ "then": self.default, "else": ScriptOp("script", script) } ).to_ruby(schema) return output
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
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
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
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)
def to_es_script(self, schema): lhs = self.lhs.partial_eval().to_es_script(schema) rhs = self.rhs.partial_eval().to_es_script(schema) if rhs.frum is ONE: script = "(int)Math.floor(" + lhs.expr + ")" else: script = "Math.floor((" + lhs.expr + ") / (" + rhs.expr + "))*(" + rhs.expr + ")" output = WhenOp( "when", OrOp("or", [lhs.miss, rhs.miss, EqOp("eq", [self.rhs, ZERO])]), **{ "then": self.default, "else": EsScript(type=NUMBER, expr=script, frum=self, miss=FALSE) }).to_es_script(schema) return output
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)
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)