Example #1
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. """
        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

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

        # Member list
        q, bindings, cuts, fields, ordering = prep(cuts, ref, order)
        page, q = Pagination(self).apply(q, page, page_size)
        q = self.restrict_joins(q, bindings)
        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']
        }
Example #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']
        }
Example #3
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']
        }
Example #4
0
    def aggregate(self, aggregates=None, drilldowns=None, cuts=None,
                  order=None, page=None, page_size=None, page_max=10000):
        """ 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()
        bindings = []
        cuts, q, bindings = Cuts(self).apply(q, bindings, cuts)
        aggregates, q, bindings = Aggregates(self).apply(q, bindings, aggregates)
        q = self.restrict_joins(q, bindings)
        summary = first_result(self, q)

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

        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)
        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']
        }
Example #5
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']
        }
Example #6
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']
        }
Example #7
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']
        }
Example #8
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']
        }
Example #9
0
    def facts(self, fields=None, cuts=None, order=None, page=None,
              page_size=None, page_max=10000):
        """ List all facts in the cube, returning only the specified references
        if these are specified. """
        q = select().select_from(self.fact_table)
        bindings = []
        cuts, q, bindings = Cuts(self).apply(q, bindings, cuts)
        fields, q, bindings = Fields(self).apply(q, bindings, fields)
        q = self.restrict_joins(q, bindings)
        count = count_results(self, q)

        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']
        }
Example #10
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']
        }