def to_ruby(self, schema): if len(self.terms) == 0: return self.default.to_ruby(schema) acc = [] separator = StringOp("string", self.separator).partial_eval() sep = separator.to_ruby(schema).expr for t in self.terms: val = WhenOp( "when", t.missing(), **{ "then": Literal("literal", ""), "else": Ruby(type=STRING, expr=sep + "+" + StringOp(None, t).partial_eval().to_ruby(schema).expr, frum=t) # "else": ConcatOp("concat", [sep, t]) }) acc.append("(" + val.partial_eval().to_ruby(schema).expr + ")") expr_ = "(" + "+".join(acc) + ").substring(" + LengthOp( "length", separator).to_ruby(schema).expr + ")" if isinstance(self.default, NullOp): return Ruby(miss=self.missing(), type=STRING, expr=expr_, frum=self) else: return Ruby(miss=self.missing(), type=STRING, expr="((" + expr_ + ").length==0) ? (" + self.default.to_ruby(schema).expr + ") : (" + expr_ + ")", frum=self)
def to_ruby(self, schema): v = StringOp("string", self.value).to_ruby(schema).expr find = StringOp("string", self.find).to_ruby(schema).expr start = IntegerOp("integer", self.start).to_ruby(schema).expr return Ruby(miss=FALSE, type=INTEGER, expr="(" + v + ").indexOf(" + find + ", " + start + ")", frum=self)
def to_es14_script(self, schema, not_null=False, boolean=False, many=True): v = StringOp("string", self.value).to_es14_script(schema).expr find = StringOp("string", self.find).to_es14_script(schema).expr start = IntegerOp("integer", self.start).to_es14_script(schema).expr return EsScript( miss=FALSE, type=INTEGER, expr="(" + v + ").indexOf(" + find + ", " + start + ")", frum=self )
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", [StringOp("string", t).partial_eval() for t in value.frum.terms]).to_ruby(schema) if value.type == BOOLEAN: return Ruby(miss=self.term.missing().partial_eval(), type=STRING, expr=value.expr + ' ? "T" : "F"', frum=self) elif value.type == INTEGER: return Ruby(miss=self.term.missing().partial_eval(), type=STRING, expr="String.valueOf(" + value.expr + ")", frum=self) elif value.type == NUMBER: return Ruby(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 Ruby(miss=self.term.missing().partial_eval(), type=STRING, expr=expand_template(TO_STRING, {"expr": value.expr}), frum=self)
def to_ruby(self, schema): value = StringOp("string", self.term).to_ruby(schema) missing = self.term.missing().partial_eval() return Ruby(miss=missing, type=INTEGER, expr="(" + value.expr + ").length()", frum=self)
def to_ruby(self, schema): v = StringOp("string", self.value).partial_eval().to_ruby(schema).expr start = IntegerOp("string", self.start).partial_eval().to_ruby(schema).expr end = IntegerOp("integer", self.end).partial_eval().to_ruby(schema).expr return Ruby(miss=FALSE, type=STRING, expr="(" + v + ").substring(" + start + ", " + end + ")", frum=self)
def to_es14_script(self, schema, not_null=False, boolean=False, many=True): value = StringOp("string", self.term).to_es14_script(schema) missing = self.term.missing().partial_eval() return EsScript( miss=missing, type=INTEGER, expr="(" + value.expr + ").length()", frum=self )
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_es14_script(self, schema, not_null=False, boolean=False, many=True): v = StringOp("string", self.value).partial_eval().to_es14_script(schema).expr start = IntegerOp("string", self.start).partial_eval().to_es14_script(schema).expr end = IntegerOp("integer", self.end).partial_eval().to_es14_script(schema).expr return EsScript( miss=FALSE, type=STRING, expr="(" + v + ").substring(" + start + ", " + end + ")", frum=self )