コード例 #1
0
    def aggregate(self,
                  aggregates=None,
                  drilldowns=None,
                  cuts=None,
                  order=None,
                  page=None,
                  page_size=None):
        """ Main aggregation function. This is used to compute a given set of
        aggregates, grouped by a given set of drilldown dimensions (i.e.
        dividers). The query can also be filtered and sorted. """
        q = select()
        cuts, q = Cuts(self).apply(q, cuts)
        aggregates, q = Aggregates(self).apply(q, aggregates)
        summary = first_result(self, q)

        attributes, q = Drilldowns(self).apply(q, drilldowns)
        count = count_results(self, q)

        page, q = Pagination(self).apply(q, page, page_size)
        ordering, q = Ordering(self).apply(q, order)
        return {
            'total_cell_count': count,
            'cells': list(generate_results(self, q)),
            'summary': summary,
            'cell': cuts,
            'aggregates': aggregates,
            'attributes': attributes,
            'order': ordering,
            'page': page['page'],
            'page_size': page['page_size']
        }
コード例 #2
0
    def facts(self,
              fields=None,
              cuts=None,
              order=None,
              page=None,
              page_size=None,
              page_max=None):
        """ List all facts in the cube, returning only the specified references
        if these are specified. """
        def prep(cuts, columns=None):
            q = select(columns=columns).select_from(self.fact_table)
            bindings = []
            _, q, bindings = Cuts(self).apply(q, bindings, cuts)
            q = self.restrict_joins(q, bindings)
            return q, bindings

        # Count
        count = count_results(self, prep(cuts, [1])[0])

        # Facts
        q, bindings = prep(cuts)
        fields, q, bindings = Fields(self).apply(q, bindings, fields)
        ordering, q, bindings = Ordering(self).apply(q, bindings, order)
        page, q = Pagination(self).apply(q, page, page_size, page_max)
        q = self.restrict_joins(q, bindings)
        return {
            'total_fact_count': count,
            'data': list(generate_results(self, q)),
            'cell': cuts,
            'fields': fields,
            'order': ordering,
            'page': page['page'],
            'page_size': page['page_size']
        }
コード例 #3
0
    def aggregate(self,
                  aggregates=None,
                  drilldowns=None,
                  cuts=None,
                  order=None,
                  page=None,
                  page_size=None,
                  page_max=None):
        """ Main aggregation function. This is used to compute a given set of
        aggregates, grouped by a given set of drilldown dimensions (i.e.
        dividers). The query can also be filtered and sorted. """
        def prep(cuts, drilldowns=False, aggregates=False, columns=None):
            q = select(columns)
            bindings = []
            cuts, q, bindings = Cuts(self).apply(q, bindings, cuts)

            attributes = None
            if drilldowns is not False:
                attributes, q, bindings = Drilldowns(self).apply(
                    q, bindings, drilldowns)

            if aggregates is not False:
                aggregates, q, bindings = Aggregates(self).apply(
                    q, bindings, aggregates)

            q = self.restrict_joins(q, bindings)
            return q, bindings, attributes, aggregates, cuts

        # Count
        count = count_results(
            self,
            prep(cuts, drilldowns=drilldowns, columns=[1])[0])

        # Summary
        summary = first_result(self,
                               prep(cuts, aggregates=aggregates)[0].limit(1))

        # Results
        q, bindings, attributes, aggregates, cuts = \
            prep(cuts, drilldowns=drilldowns, aggregates=aggregates)
        page, q = Pagination(self).apply(q, page, page_size, page_max)
        ordering, q, bindings = Ordering(self).apply(q, bindings, order)
        q = self.restrict_joins(q, bindings)

        cells = list(generate_results(self, q))

        return {
            'total_cell_count': count,
            'cells': cells,
            'summary': summary,
            'cell': cuts,
            'aggregates': aggregates,
            'attributes': attributes,
            'order': ordering,
            'page': page['page'],
            'page_size': page['page_size']
        }
コード例 #4
0
 def prep(cuts, ref, order, columns=None):
     q = select(columns=columns)
     bindings = []
     cuts, q, bindings = Cuts(self).apply(q, bindings, cuts)
     fields, q, bindings = \
         Fields(self).apply(q, bindings, ref, distinct=True)
     ordering, q, bindings = \
         Ordering(self).apply(q, bindings, order, distinct=fields[0])
     q = self.restrict_joins(q, bindings)
     return q, bindings, cuts, fields, ordering
コード例 #5
0
    def members(self, ref, cuts=None, order=None, page=None, page_size=None):
        """ List all the distinct members of the given reference, filtered and
        paginated. If the reference describes a dimension, all attributes are
        returned. """
        q = select(distinct=True)
        cuts, q = Cuts(self).apply(q, cuts)
        fields, q = Fields(self).apply(q, ref)
        ordering, q = Ordering(self).apply(q, order)
        count = count_results(self, q)

        page, q = Pagination(self).apply(q, page, page_size)
        return {
            'total_member_count': count,
            'data': list(generate_results(self, q)),
            'cell': cuts,
            'fields': fields,
            'order': ordering,
            'page': page['page'],
            'page_size': page['page_size']
        }
コード例 #6
0
    def facts(self,
              fields=None,
              cuts=None,
              order=None,
              page=None,
              page_size=None):
        """ List all facts in the cube, returning only the specified references
        if these are specified. """
        q = select()
        cuts, q = Cuts(self).apply(q, cuts)
        fields, q = Fields(self).apply(q, fields)
        count = count_results(self, q)

        ordering, q = Ordering(self).apply(q, order)
        page, q = Pagination(self).apply(q, page, page_size)
        return {
            'total_fact_count': count,
            'data': list(generate_results(self, q)),
            'cell': cuts,
            'fields': fields,
            'order': ordering,
            'page': page['page'],
            'page_size': page['page_size']
        }
コード例 #7
0
ファイル: test_parser.py プロジェクト: holgerd77/babbage
 def test_order_invalid(self):
     Ordering(self.cube).parse('fooxx:desc')
コード例 #8
0
ファイル: test_parser.py プロジェクト: holgerd77/babbage
 def test_order(self):
     cuts = Ordering(self.cube).parse('foo:desc,bar')
     assert cuts[0][1] == "desc", cuts
     assert cuts[1][1] == "asc", cuts
コード例 #9
0
 def test_order_invalid(self, cube):
     with pytest.raises(QueryException):
         Ordering(cube).parse('fooxx:desc')
コード例 #10
0
 def test_order(self, cube):
     ordering = Ordering(cube).parse('foo:desc,bar')
     assert ordering[0][1] == "desc", ordering
     assert ordering[1][1] == "asc", ordering