Merge source

The merge source provides a mechanism for merging and filtering the data resulting from two or more other “sub-reports”. This can be useful if you need to combine results from two different databases or with two different key ranges into one report.

When building a merged report, you must specify the reports to merge in a report attribute:

  • merged_reports: Specifies the sub-reports you want to merge. Provide the reports as a dict with the keys naming the sub-reports and the values being the sub-report classes themselves. For example:

    merged_reports = {
        'revenue': ProductRevenueReport,
        'awesome': UserAwesomenessReport,
    }
    

All merge columns take the same positional arguments, which are used to specify which columns from sub-reports should be combined into the merge column. You can specify the merge columns as follows:

  • If no argument is provided, the merge report will merge any columns found with the same name from all sub-reports.
  • If you provide a single string as an argument, the merge report will merge any columns from sub-reports that have that name.
  • To merge columns of various names from various sub-reports, you can specify as many as you like as dotted strings. Each string should be in the form of 'report_name.column_name'.

As a merged report is processed, it will actually run the full end-to-end run-report process for each of its sub-reports. It will then aggregate the results together based on the columns and filters in the merge report.

Column types

class blingalytics.sources.merge.Sum(*args, **kwargs)

Merges sub-report columns by summing the values returned by each sub-report. Takes the standard merge column arguments, as described above.

class blingalytics.sources.merge.First(*args, **kwargs)

Merges sub-report columns by keeping the first value returned by any sub-report. Takes the standard merge column arguments, as described above.

class blingalytics.sources.merge.BoolAnd(*args, **kwargs)

Merges sub-report columns by performing a boolean-and operation over the values returned by the sub-reports. This returns True if all the values from sub-reports are truthy; otherwise, it returns False. A None value is considered True here so that they essentially are ignored in determining the result. Takes the standard merge column arguments, as described above.

class blingalytics.sources.merge.BoolOr(*args, **kwargs)

Merges sub-report columns by performing a boolean-or operation over the values returned by the sub-reports. This returns True if any of the values from sub-reports are truthy; otherwise, it returns False. A None value is considered False here so that they essentially are ignored in determining the result. Takes the standard merge column arguments, as described above.

Filter types

class blingalytics.sources.merge.DelegatedFilter(*args, **kwargs)

Allows you to display one widget from the merge report, then supply the user input to each of the sub-reports to process as they normally would using the filters defined on each sub-report.

This filter simply takes the standard widget keyword argument. You also need to ensure that the name of this filter matches the name of any sub-report filters you want to pick up the user input.

class blingalytics.sources.merge.PostFilter(filter_func, **kwargs)

This filter can be used to exclude entire rows from the output, based on the data in the row from the sub-reports.

This takes one positional argument, which should be a filtering function. The function takes the merged row as a dict, and optionally the user input if a widget is specified. If the function returns a truthy value, the row will be included; otherwise, it will be skipped. For example:

merge.PostFilter(
    lambda row, user_input: row['revenue'] >= user_input,
    widget=widgets.Select(choices=MIN_REVENUE_CHOICES))
class blingalytics.sources.merge.ReportFilter(report_name, **kwargs)

This filter allows you to selectively include or exclude specific sub-reports from being processed at all. It takes one positional argument: the name of the sub-report from the merged_reports report attribute from the merge report.

This filter requires a widget (it would be pretty silly to use this one without a widget). It will include the specified sub-report in the merged output only if the user input is truthy. Generally, a Checkbox widget is appropriate for this.

Table Of Contents

Previous topic

Derived source

Next topic

Cache stores

This Page