예제 #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 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
예제 #3
0
        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
예제 #4
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']
        }
예제 #5
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']
        }
예제 #6
0
 def test_cuts_multiple_int_first(self, cube):
     cuts = Cuts(cube).parse('bar:5|foo:bar')
     assert len(cuts) == 2, cuts
     cuts = [(c[0], c[1], list(c[2])) for c in cuts]
     assert ('bar', ':', [5]) in list(cuts), cuts
예제 #7
0
 def test_null_filter(self):
     cuts = Cuts(self.cube).parse(None)
     assert isinstance(cuts, list)
     assert not len(cuts)
예제 #8
0
 def test_cuts_null(self):
     cuts = Cuts(self.cube).parse('foo:')
     assert cuts[0][2] is None, cuts
예제 #9
0
 def test_cuts_invalid(self):
     Cuts(self.cube).parse('f oo:2015-01-04')
예제 #10
0
 def test_cuts_date(self):
     cuts = Cuts(self.cube).parse('foo:2015-01-04')
     assert cuts[0][2] == date(2015, 01, 04), cuts
예제 #11
0
 def test_cuts_date_set(self, cube):
     cuts = Cuts(cube).parse('foo:2015-01-04;2015-01-05')
     assert len(cuts) == 1, cuts
     assert list(cuts[0][2]) == [date(2015, 1, 4), date(2015, 1, 5)], cuts
예제 #12
0
 def test_cuts_int_set(self, cube):
     cuts = Cuts(cube).parse('foo:3;22')
     assert len(cuts) == 1, cuts
     cuts = [(c[0], c[1], list(c[2])) for c in cuts]
     assert ('foo', ':', [3, 22]) in cuts, cuts
예제 #13
0
 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
예제 #14
0
 def test_cuts(self):
     cuts = Cuts(self.cube).parse('foo:bar')
     assert len(cuts) == 1, cuts
예제 #15
0
 def test_cuts_unquoted_string(self, cube):
     cuts = Cuts(cube).parse('foo:bar')
     assert len(cuts) == 1, cuts
     cuts = [(c[0], c[1], list(c[2])) for c in cuts]
     assert ('foo', ':', ['bar']) in cuts, cuts
예제 #16
0
 def test_cuts_invalid(self, cube):
     with pytest.raises(QueryException):
         Cuts(cube).parse('f oo:2015-01-04')
예제 #17
0
 def test_cuts_int_prefixed_string(self, cube):
     cuts = Cuts(cube).parse('foo:2015M01')
     assert list(cuts[0][2]) == ['2015M01'], cuts
예제 #18
0
 def test_cuts_int(self, cube):
     cuts = Cuts(cube).parse('foo:2015')
     assert list(cuts[0][2]) == [2015], cuts
예제 #19
0
 def test_cuts_quotes(self):
     cuts = Cuts(self.cube).parse('foo:"bar|lala"|bar:5')
     assert len(cuts) == 2, cuts
예제 #20
0
 def test_cuts_quoted(self):
     cuts = Cuts(self.cube).parse('foo:"bar lala"')
     assert len(cuts) == 1, cuts
예제 #21
0
 def test_cuts_date(self, cube):
     cuts = Cuts(cube).parse('foo:2015-01-04')
     assert list(cuts[0][2]) == [date(2015, 1, 4)], cuts
예제 #22
0
 def test_cuts_multiple(self):
     cuts = Cuts(self.cube).parse('foo:bar|bar:5')
     assert len(cuts) == 2, cuts
     assert ('bar', ':', 5) in cuts, cuts
예제 #23
0
 def test_cuts_string_set(self, cube):
     cuts = Cuts(cube).parse('foo:"bar";"lala"')
     assert len(cuts) == 1, cuts
     cuts = [(c[0], c[1], list(c[2])) for c in cuts]
     assert ('foo', ':', ['bar', 'lala']) in cuts, cuts