Example #1
0
 def __new__(cls, term, *args):
     Expression.__new__(cls, *args)
     field, comparisons = term  # comparisons IS A Literal()
     return cls.lang[AndOp([
         getattr(cls.lang, operators[op])([field, Literal(value)])
         for op, value in comparisons.value.items()
     ])]
Example #2
0
 def __init__(self, script, data_type=OBJECT):
     Expression.__init__(self, None)
     if not is_text(script):
         Log.error("expecting text of a script")
     self.simplified = True
     self.script = script
     self.data_type = data_type
 def __init__(self,
              frum,
              select=None,
              edges=None,
              groupby=None,
              window=None,
              where=None,
              sort=None,
              limit=None,
              format=None,
              chunk_size=None,
              destination=None):
     if isinstance(frum, Table):
         pass
     else:
         Expression.__init__(self, frum)
     self.frum = frum
     self.select = select
     self.edges = edges
     self.groupby = groupby
     self.window = window
     self.where = where
     self.sort = sort
     self.limit = limit
     self.format = format
     self.chunk_size = chunk_size
     self.destination = destination
Example #4
0
 def __init__(self, terms, **clauses):
     Expression.__init__(self, terms)
     if is_many(terms):
         # SHORTCUT: ASSUME AN ARRAY OF IS A TUPLE
         self.terms = self.lang[TupleOp(terms)]
     else:
         self.terms = terms
Example #5
0
 def __init__(self, term, **kwargs):
     Expression.__init__(self, term)
     self.value, self.find = term
     self.default = kwargs.get("default", NULL)
     self.start = kwargs.get("start", ZERO).partial_eval()
     if self.start is NULL:
         self.start = ZERO
Example #6
0
 def __init__(self, terms, **clauses):
     Expression.__init__(self, terms)
     self.terms = terms
     self.default = coalesce(clauses.get("default"), NULL)
     self.nulls = coalesce(
         clauses.get("nulls"), FALSE
     )  # nulls==True WILL HAVE OP RETURN null ONLY IF ALL OPERANDS ARE null
Example #7
0
 def __init__(self, path, select=select_nothing, where=TRUE, sort=Null, limit=NULL):
     Expression.__init__(self, [path, select, where])
     self.path = path
     self.select = select
     self.where = where
     self.sort = sort
     self.limit = limit
Example #8
0
 def __init__(self, terms, default=NULL):
     Expression.__init__(self, terms)
     if len(terms) == 1:
         self.lhs = terms[0]
         self.rhs = ONE
     else:
         self.lhs, self.rhs = terms
     self.default = default
Example #9
0
 def __init__(self, term):
     Expression.__init__(self, term)
     if not term:
         self.expr = self.suffix = None
     elif is_data(term):
         self.expr, self.suffix = term.items()[0]
     else:
         self.expr, self.suffix = term
 def __init__(self, terms):
     Expression.__init__(self, terms)
     if terms == None:
         self.terms = []
     elif is_many(terms):
         self.terms = terms
     else:
         self.terms = [terms]
Example #11
0
 def __init__(self, terms):
     Expression.__init__(self, terms)
     if is_sequence(terms):
         self.lhs, self.rhs = terms
     elif is_data(terms):
         self.rhs, self.lhs = terms.items()[0]
     else:
         Log.error("logic error")
Example #12
0
 def __init__(self, terms, separator=Literal(""), default=NULL):
     if not is_many(terms):
         Log.error("Expecting many terms")
     if not is_literal(separator):
         Log.error("Expecting a literal separator")
     Expression.__init__(self, terms + [separator, default])
     self.terms = terms
     self.separator = separator
     self.default = default
Example #13
0
 def __init__(self, term):
     Expression.__init__(self, term)
     if not term:
         self.expr = NULL
         self.prefix = NULL
     elif is_data(term):
         self.expr, self.prefix = term.items()[0]
     else:
         self.expr, self.prefix = term
Example #14
0
    def __init__(self, term):
        Expression.__init__(self, term)
        if is_data(term):
            self.value, self.length = term.items()[0]
        else:
            self.value, self.length = term

        if is_literal(self.value):
            Log.note("")
 def __init__(self, frum, nests):
     Expression.__init__(self, nests)
     self.frum = frum
     self.nests = nests
     last = "."
     for n in reversed(nests):
         path = n.path.var
         if not startswith_field(path, last):
             Log.error("Expecting nests to be reverse nested order")
         last = path
Example #16
0
 def __init__(self, terms, **clauses):
     Expression.__init__(self, terms)
     if is_data(terms):
         self.terms = first(terms.items())
     else:
         self.terms = terms
     self.separator = clauses.get(str("separator"), Literal(""))
     self.default = clauses.get(str("default"), NULL)
     if not is_literal(self.separator):
         Log.error("Expecting a literal separator")
Example #17
0
 def __init__(self, value, prefix, suffix, default=NULL, start=NULL):
     Expression.__init__(self, [])
     self.value = value
     self.prefix = prefix
     self.suffix = suffix
     self.default = default
     self.start = start
     if is_literal(self.prefix) and is_literal(self.suffix):
         pass
     else:
         Log.error("Expecting literal prefix and suffix only")
Example #18
0
 def __init__(self, value, prefix, suffix, default=NULL, start=NULL):
     Expression.__init__(self, [])
     self.value = value
     self.prefix = coalesce(prefix, NULL)
     self.suffix = coalesce(suffix, NULL)
     self.default = coalesce(default, NULL)
     self.start = coalesce(start, NULL)
     if is_literal(self.prefix) and is_literal(self.suffix):
         pass
     else:
         Log.error("Expecting literal prefix and suffix only")
Example #19
0
 def __init__(self, term):
     Expression.__init__(self, term)
     self.var, self.offset = term
     if is_op(self.var, Variable):
         if is_op(self.var, Variable) and not any(
             self.var.var.startswith(p) for p in ["row.", "rows.", "rownum"]
         ):  # VARIABLES ARE INTERPRETED LITERALLY
             self.var = Literal(self.var.var)
         else:
             Log.error("can not handle")
     else:
         Log.error("can not handle")
Example #20
0
    def __init__(self, terms, **clauses):
        if not is_sequence(terms):
            Log.error("case expression requires a list of `when` sub-clauses")
        Expression.__init__(self, terms)
        if len(terms) == 0:
            Log.error("Expecting at least one clause")

        for w in terms[:-1]:
            if not is_op(w, WhenOp) or w.els_ is not NULL:
                Log.error(
                    "case expression does not allow `else` clause in `when` sub-clause"
                )
        self.whens = terms
    def __init__(self, var):
        """
        :param var:  DOT DELIMITED PATH INTO A DOCUMENT

        """
        Expression.__init__(self, None)

        # if self.lang != self.__class_.lang:
        #     pass
        self.var = get_property_name(var)
        jx_type = inserter_type_to_json_type.get(last(split_field(var)))
        if jx_type:
            self.data_type = jx_type
    def __init__(self, term, **clauses):
        Expression.__init__(self, [term])

        self.when = term
        self.then = coalesce(clauses.get("then"), NULL)
        self.els_ = coalesce(clauses.get("else"), NULL)

        if self.then is NULL:
            self.data_type = self.els_.type
        elif self.els_ is NULL:
            self.data_type = self.then.type
        elif same_json_type(self.then.type, self.els_.type):
            self.data_type = merge_json_type(self.then.type, self.els_.type)
        else:
            self.data_type = OBJECT
Example #23
0
 def __init__(self, frum, nests):
     """
     A SEQUENCE OF NESTED (INNER) JOINS FOR A QUERY
     :param frum: THE TABLE OF DOCUMENTS
     :param nests: LIST OF INNER JOINS (deepest first)
     """
     Expression.__init__(self, nests)
     self.frum = frum
     self.nests = nests
     last = "."
     for n in reversed(nests):
         path = n.path.var
         if not startswith_field(path, last):
             Log.error("Expecting nests to be reverse nested order")
         last = path
Example #24
0
    def __init__(self, term, **clauses):
        Expression.__init__(self, [term])

        self.when = term
        self.then = coalesce(clauses.get("then"), NULL)
        self.els_ = coalesce(clauses.get("else"), NULL)

        if self.then is NULL:
            self.data_type = self.els_.type
        elif self.els_ is NULL:
            self.data_type = self.then.type
        elif self.then.type == self.els_.type:
            self.data_type = self.then.type
        elif self.then.type in NUMBER_TYPES and self.els_.type in NUMBER_TYPES:
            self.data_type = NUMBER
        else:
            self.data_type = OBJECT
Example #25
0
    def __init__(self, var, type=None, multi=None):
        """

        :param var:   DOT DELIMITED PATH INTO A DOCUMENT
        :param type:  JSON TYPE, IF KNOWN
        :param multi: NUMBER OF DISTINCT VALUES IN A SLOT
        """
        Expression.__init__(self, None)

        # if self.lang != self.__class_.lang:
        #     pass
        self.var = get_property_name(var)

        if type == None:
            jx_type = inserter_type_to_json_type.get(last(split_field(var)))
            if jx_type:
                self.data_type = jx_type
        else:
            self.data_type = type

        self._many = False
        if multi and multi > 1:
            self._many = True
Example #26
0
 def __init__(self, term):
     Expression.__init__(self, term)
     self.value = term
Example #27
0
 def __init__(self, term):
     Expression.__init__(self, [term])
     self.term = term
Example #28
0
 def __init__(self, term):
     Expression.__init__(self, term)
     self.expr = term
Example #29
0
 def __init__(self, terms):
     Expression.__init__(self, terms)
     self.value, self.start, self.end = terms
Example #30
0
 def __init__(self, terms):
     Expression.__init__(self, terms)
     self.terms = terms