fireant.slicer.queries package

Submodules

fireant.slicer.queries.builder module

class fireant.slicer.queries.builder.DimensionChoicesQueryBuilder(slicer, dimension)[source]

Bases: fireant.slicer.queries.builder.QueryBuilder

This builder is used for building slicer queries for fetching the choices for a dimension given a set of filters.

fetch(hint=None, force_include=()) → pandas.core.series.Series[source]

Fetch the data for this query and transform it into the widgets.

Parameters:
  • hint – For database vendors that support it, add a query hint to collect analytics on the queries triggerd by fireant.
  • force_include – A list of dimension values to include in the result set. This can be used to avoid having necessary results cut off due to the pagination. These results will be returned at the head of the results.
Returns:

A list of dict (JSON) objects containing the widget configurations.

queries

Serializes this query builder as a set of SQL queries. This method will always return a list of one query since only one query is required to retrieve dimension choices.

This function only handles dimensions (select+group by) and filtering (where/having), which is everything needed for the query to fetch choices for dimensions.

The slicer query extends this with metrics, references, and totals.

class fireant.slicer.queries.builder.DimensionLatestQueryBuilder(slicer)[source]

Bases: fireant.slicer.queries.builder.QueryBuilder

fetch(hint=None)[source]

Fetches the data for this query instance and returns it in an instance of pd.DataFrame

Parameters:hint – For database vendors that support it, add a query hint to collect analytics on the queries triggerd by fireant.
queries

Serializes this query builder as a set of SQL queries. This method will always return a list of one query since only one query is required to retrieve dimension choices.

This function only handles dimensions (select+group by) and filtering (where/having), which is everything needed for the query to fetch choices for dimensions.

The slicer query extends this with metrics, references, and totals.

class fireant.slicer.queries.builder.QueryBuilder(slicer, table)[source]

Bases: object

This is the base class for building slicer queries. This class provides an interface for building slicer queries via a set of functions which can be chained together.

fetch(hint=None)[source]

Fetches the data for this query instance and returns it in an instance of pd.DataFrame

Parameters:hint – For database vendors that support it, add a query hint to collect analytics on the queries triggerd by fireant.
filter(*args, mutate=False, **kwargs)
Parameters:mutate – When True, overrides the immutable behavior of this decorator.
limit(*args, mutate=False, **kwargs)
Parameters:mutate – When True, overrides the immutable behavior of this decorator.
offset(*args, mutate=False, **kwargs)
Parameters:mutate – When True, overrides the immutable behavior of this decorator.
queries

Serialize this query builder object to a set of Pypika/SQL queries.

This is the base implementation shared by two implementations: the query to fetch data for a slicer request and the query to fetch choices for dimensions.

This function only handles dimensions (select+group by) and filtering (where/having), which is everything needed for the query to fetch choices for dimensions.

The slicer query extends this with metrics, references, and totals.

class fireant.slicer.queries.builder.SlicerQueryBuilder(slicer)[source]

Bases: fireant.slicer.queries.builder.QueryBuilder

Slicer queries consist of widgets, dimensions, filters, and references. At least one or more widgets is required. All others are optional.

dimension(*args, mutate=False, **kwargs)
Parameters:mutate – When True, overrides the immutable behavior of this decorator.
fetch(hint=None) → Iterable[Dict][source]

Fetch the data for this query and transform it into the widgets.

Parameters:hint – A query hint label used with database vendors which support it. Adds a label comment to the query.
Returns:A list of dict (JSON) objects containing the widget configurations.
orderby(*args, mutate=False, **kwargs)
Parameters:mutate – When True, overrides the immutable behavior of this decorator.
queries

Serialize this query builder to a list of Pypika/SQL queries. This function will return one query for every combination of reference and rolled up dimension (including null options).

This collects all of the metrics in each widget, dimensions, and filters and builds a corresponding pypika query to fetch the data. When references are used, the base query normally produced is wrapped in an outer query and a query for each reference is joined based on the referenced dimension shifted.

reference(*args, mutate=False, **kwargs)
Parameters:mutate – When True, overrides the immutable behavior of this decorator.
reference_groups
widget(*args, mutate=False, **kwargs)
Parameters:mutate – When True, overrides the immutable behavior of this decorator.
fireant.slicer.queries.builder.add_hints(queries, hint=None)[source]

fireant.slicer.queries.database module

fireant.slicer.queries.finders module

class fireant.slicer.queries.finders.ReferenceGroup(dimension, time_unit, intervals)

Bases: tuple

dimension

Alias for field number 0

intervals

Alias for field number 2

time_unit

Alias for field number 1

fireant.slicer.queries.finders.find_and_group_references_for_dimensions(references)[source]

Finds all of the references for dimensions and groups them by dimension, interval unit, number of intervals.

This structure reflects how the references need to be joined to the slicer query. References of the same type (WoW, WoW.delta, WoW.delta_percent) can share a join query.

Parameters:references
Returns:An OrderedDict where the keys are 3-item tuples consisting of “Dimension, interval unit, # of intervals.
Example
{
    (Dimension(date_1), 'weeks', 1): [WoW, WoW.delta],
    (Dimension(date_1), 'years', 1): [YoY],
    (Dimension(date_7), 'days', 1): [DoD, DoD.delta_percent],
}
fireant.slicer.queries.finders.find_and_replace_reference_dimensions(references, dimensions)[source]

Finds the dimension for a reference in the query if there is one and replaces it. This is to force the reference to use the same modifiers with a dimension if it is selected in the query.

Parameters:
  • references
  • dimensions
Returns:

fireant.slicer.queries.finders.find_joins_for_tables(joins, base_table, required_tables)[source]

Given a set of tables required for a slicer query, this function finds the joins required for the query and sorts them topologically.

Returns:A list of joins in the order that they must be joined to the query.
Raises:MissingTableJoinException - If a table is required but there is no join for that table CircularJoinsException - If there is a circular dependency between two or more joins
fireant.slicer.queries.finders.find_metrics_for_widgets(widgets)[source]
Returns:an ordered, distinct list of metrics used in all widgets as part of this query.
fireant.slicer.queries.finders.find_operations_for_widgets(widgets)[source]
Returns:an ordered, distinct list of metrics used in all widgets as part of this query.
fireant.slicer.queries.finders.find_required_tables_to_join(elements, base_table)[source]

Collect all the tables required for a given list of slicer elements. This looks through the definition and display_definition attributes of all elements and

This looks through the metrics, dimensions, and filter included in this slicer query. It also checks both the definition field of each element as well as the display definition for Unique Dimensions.

Returns:A collection of tables required to execute a query,
fireant.slicer.queries.finders.find_share_dimensions(dimensions, operations)[source]

Returns a subset list of dimensions from the list of dimensions that are used as the over-dimension in share operations.

Parameters:
  • dimensions
  • operations
Returns:

fireant.slicer.queries.finders.find_totals_dimensions(dimensions, share_dimensions)[source]

WRITEME

Parameters:
  • dimensions
  • share_dimensions
Returns:

fireant.slicer.queries.logger module

fireant.slicer.queries.makers module

fireant.slicer.queries.references module

fireant.slicer.queries.special_cases module

fireant.slicer.queries.special_cases.adjust_dataframe_for_rolling_window(operations, data_frame)[source]

This function adjusts the resulting data frame after executing a slicer query with a rolling operation. If there is a date dimension in the first level of the data frame’s index and a rolling operation is applied, it will slice the dates following the max window to remove it. This way, the adjustment of date filters applied in #adjust_daterange_filter_for_rolling_window are removed from the data frame but also in case there are no filters, the first few date data points will be removed where the rolling window cannot be calculated.

Parameters:
  • operations
  • data_frame
Returns:

fireant.slicer.queries.special_cases.adjust_daterange_filter_for_rolling_window(dimensions, operations, filters)[source]

This function adjusts date filters for a rolling operation in order to select enough date to compute the values for within the original range.

It only applies when using a date dimension in the first position and a RangeFilter is used on that dimension. It is meant to be applied to a slicer query.

Parameters:
  • dimensions – The dimensions applied to a slicer query
  • operations – The dimensions used in widgets in a slicer query
  • filters – The filters applied to a slicer query
Returns:

fireant.slicer.queries.special_cases.apply_operations_to_data_frame(operations, data_frame)[source]
fireant.slicer.queries.special_cases.apply_special_cases(f)[source]
fireant.slicer.queries.special_cases.apply_to_query_args(database, table, joins, dimensions, metrics, operations, filters, references, orders)[source]

Module contents