class BasicSubstringOp(BasicSubstringOp_): def to_es_script(self, schema, not_null=False, boolean=False, many=True): v = StringOp(self.value).partial_eval().to_es_script(schema).expr start = IntegerOp(self.start).partial_eval().to_es_script(schema).expr end = IntegerOp(self.end).partial_eval().to_es_script(schema).expr return EsScript( miss=FALSE, type=STRING, expr="(" + v + ").substring(" + start + ", " + end + ")", frum=self, schema=schema, ) Painless = define_language("Painless", vars()) _count_template = ( "long count=0; for(v in {{expr}}) if (v!=null) count+=1; return count;") _painless_operators = { "add": (" + ", "0"), # (operator, zero-array default value) PAIR "sum": (" + ", "0"), "mul": (" * ", "1"), "basic.add": (" + ", "0"), "basic.mul": (" * ", "1"), "sub": ("-", None), "div": ("/", None), "exp": ("**", None), "mod": ("%", None), "gt": (">", None),
return ("(" + Python[self.then].to_python() + ") if (" + Python[self.when].to_python(boolean=True) + ") else (" + Python[self.els_].to_python() + ")") def assign_and_eval(var, expression, eval): """ :param var: NAME GIVEN TO expression :param expression: THE EXPRESSION TO COMPUTE FIRST :param eval: THE EXPRESSION TO COMPUTE SECOND, WITH var ASSIGNED :return: PYTHON EXPRESSION """ return "[(" + eval + ") for " + var + " in [" + expression + "]][0]" Python = define_language("Python", vars()) _python_operators = { "add": (" + ", "0"), # (operator, zero-array default value) PAIR "sum": (" + ", "0"), "mul": (" * ", "1"), "sub": (" - ", None), "div": (" / ", None), "exp": (" ** ", None), "mod": (" % ", None), "gt": (" > ", None), "gte": (" >= ", None), "lte": (" <= ", None), "lt": (" < ", None), }
class WhenOp(WhenOp_): def to_python(self, not_null=False, boolean=False, many=False): return ( "(" + Python[self.then].to_python() + ") if (" + Python[self.when].to_python(boolean=True) + ") else (" + Python[self.els_].to_python() + ")" ) Python = define_language("Python", vars()) _python_operators = { "add": (" + ", "0"), # (operator, zero-array default value) PAIR "sum": (" + ", "0"), "mul": (" * ", "1"), "sub": (" - ", None), "div": (" / ", None), "exp": (" ** ", None), "mod": (" % ", None), "gt": (" > ", None), "gte": (" >= ", None), "lte": (" <= ", None), "lt": (" < ", None), }
if "%" in prefix or "_" in prefix: for r in "\\_%": prefix = prefix.replaceAll(r, "\\" + r) sql = ConcatSQL( (value, SQL_LIKE, prefix, SQL_ESCAPE, SQL("\\"))) else: sql = ConcatSQL((value, SQL_LIKE, prefix)) return wrap([{"name": ".", "sql": {"b": sql}}]) else: return (SqlEqOp( [SqlSubstrOp([self.value, ONE, LengthOp(prefix)]), prefix]).partial_eval().to_sql()) SQLang = define_language("SQLang", vars()) _sql_operators = { # (operator, zero-array default value) PAIR "add": (SQL_PLUS, SQL_ZERO), "sum": (SQL_PLUS, SQL_ZERO), "mul": (SQL_STAR, SQL_ONE), "sub": (SQL(" - "), None), "div": (SQL(" / "), None), "exp": (SQL(" ** "), None), "mod": (SQL(" % "), None), "gt": (SQL(" > "), None), "gte": (SQL(" >= "), None), "lte": (SQL(" <= "), None), "lt": (SQL_LT, None), }
class BasicSubstringOp(BasicSubstringOp_): def to_es_script(self, schema, not_null=False, boolean=False, many=True): v = StringOp(self.value).partial_eval().to_es_script(schema).expr start = IntegerOp(self.start).partial_eval().to_es_script(schema).expr end = IntegerOp(self.end).partial_eval().to_es_script(schema).expr return EsScript( miss=FALSE, type=STRING, expr="(" + v + ").substring(" + start + ", " + end + ")", frum=self, schema=schema, ) Painless = define_language("Painless", vars()) _count_template = ( "long count=0; for(v in {{expr}}) if (v!=null) count+=1; return count;" ) _painless_operators = { "add": (" + ", "0"), # (operator, zero-array default value) PAIR "sum": (" + ", "0"), "mul": (" * ", "1"), "basic.add": (" + ", "0"), "basic.mul": (" * ", "1"), "sub": ("-", None), "div": ("/", None), "exp": ("**", None),