def run(query, frum=Null): """ THIS FUNCTION IS SIMPLY SWITCHING BASED ON THE query["from"] CONTAINER, BUT IT IS ALSO PROCESSING A list CONTAINER; SEPARATE TO A ListContainer """ if frum == None: query_op = QueryOp.wrap(query) frum = query_op.frum else: query_op = QueryOp.wrap(query, frum.schema) if isinstance(frum, Container): return frum.query(query_op) elif isinstance(frum, (list, set, GeneratorType)): frum = wrap(list(frum)) elif isinstance(frum, Cube): if is_aggs(query_op): return cube_aggs(frum, query_op) elif isinstance(frum, QueryOp): frum = run(frum) else: Log.error("Do not know how to handle {{type}}", type=frum.__class__.__name__) if is_aggs(query_op): frum = list_aggs(frum, query_op) else: # SETOP # try: # if query.filter != None or query.esfilter != None: # Log.error("use 'where' clause") # except AttributeError: # pass if query_op.where is not TRUE_FILTER: frum = filter(frum, query_op.where) if query_op.sort: frum = sort(frum, query_op.sort, already_normalized=True) if query_op.select: frum = select(frum, query_op.select) if query_op.window: if isinstance(frum, Cube): frum = list(frum.values()) for param in query_op.window: window(frum, param) # AT THIS POINT frum IS IN LIST FORMAT, NOW PACKAGE RESULT if query_op.format == "cube": frum = convert.list2cube(frum) elif query_op.format == "table": frum = convert.list2table(frum) frum.meta.format = "table" else: frum = wrap({"meta": {"format": "list"}, "data": frum}) return frum
def run(query, frum=None): """ THIS FUNCTION IS SIMPLY SWITCHING BASED ON THE query["from"] CONTAINER, BUT IT IS ALSO PROCESSING A list CONTAINER; SEPARATE TO A ListContainer """ query = QueryOp.wrap(query, frum.schema) frum = coalesce(frum, query["from"]) if isinstance(frum, Container): return frum.query(query) elif isinstance(frum, (list, set, GeneratorType)): frum = wrap(list(frum)) elif isinstance(frum, Cube): if is_aggs(query): return cube_aggs(frum, query) elif isinstance(frum, QueryOp): frum = run(frum) else: Log.error("Do not know how to handle {{type}}", type=frum.__class__.__name__) if is_aggs(query): frum = list_aggs(frum, query) else: # SETOP # try: # if query.filter != None or query.esfilter != None: # Log.error("use 'where' clause") # except AttributeError: # pass if query.where is not TRUE_FILTER: frum = filter(frum, query.where) if query.sort: frum = sort(frum, query.sort, already_normalized=True) if query.select: frum = select(frum, query.select) if query.window: if isinstance(frum, Cube): frum = list(frum.values()) for param in query.window: window(frum, param) # AT THIS POINT frum IS IN LIST FORMAT, NOW PACKAGE RESULT if query.format == "cube": frum = convert.list2cube(frum) elif query.format == "table": frum = convert.list2table(frum) frum.meta.format = "table" else: frum = wrap({ "meta": {"format": "list"}, "data": frum }) return frum
def query(self, q): frum = self if is_aggs(q): return cube_aggs(frum, q) columns = wrap({s.name: s for s in self.select + self.edges}) # DEFER TO ListContainer from pyLibrary.queries.containers.list_usingPythonList import ListContainer frum = ListContainer(name="", data=frum.values(), schema=columns) return frum.query(q)
def query(self, q): frum = self if is_aggs(q): frum = list_aggs(frum.data, q) else: # SETOP try: if q.filter != None or q.esfilter != None: Log.error("use 'where' clause") except AttributeError, e: pass if q.where is not TRUE_FILTER and not isinstance(q.where, TrueOp): frum = frum.filter(q.where) if q.sort: frum = frum.sort(q.sort) if q.select: frum = frum.select(q.select)