Exemplo n.º 1
0
    def _get_select_query(self):
        # break filters into those that can be used in the inner query and those that
        # need to bubble up to the outer query (aggregates)
        split_filters = self._split_filters(self.helper._filters)
        # a lot of what follows is copy/modified from SqlData._get_data() and corresponding call chain
        # e.g. SimpleQueryMeta._build_query_generic in sqlagg
        query_context = sqlagg.QueryContext(
            self.table.name,
            filters=split_filters['inner'],
            group_by=self.report_data_source.group_by,
            # note: is this necessary to add?
            # order_by=self.order_by,
        )
        for c in self.report_data_source.columns:
            query_context.append_column(c.view)

        if len(query_context.query_meta.values()) > 1:
            raise Exception('Use of this class assumes only one query meta value!')

        query_meta = query_context.query_meta.values()[0]
        # note: sqlagg doesn't expose access to sqlalchemy except through this private method
        query = query_meta._build_query()
        if split_filters['outer']:
            # if there are outer filters we have to do a two-stage query
            # first add a subquery (with alias)
            query = query.alias().select()
            for f in split_filters['outer']:
                # then apply outer filters to the subquery
                query.append_whereclause(f.build_expression())

        return query
Exemplo n.º 2
0
 def query_context(self, start=None, limit=None):
     return sqlagg.QueryContext(self.table_name,
                                self.wrapped_filters,
                                self.group_by,
                                self.order_by,
                                start=start,
                                limit=limit)
Exemplo n.º 3
0
 def query_context(self, start=None, limit=None):
     qc = sqlagg.QueryContext(
         self.table_name, filters=self.wrapped_filters, group_by=self.group_by, distinct_on=self.distinct_on,
         order_by=self.order_by, start=start, limit=limit
     )
     for c in self.columns:
         qc.append_column(c.view)
     return qc
Exemplo n.º 4
0
 def query_context(self):
     return sqlagg.QueryContext(self.table_name, self.filters,
                                self.group_by)