xplain.QueryConfig

class xplain.QueryConfig(name: str = None)

Bases: object

Factory class to generate the xplain query configuration for the execute_query method of Xsession.

Attributes:

request (dict): The query configuration containing aggregations, groupBys, and selections.

aggregation(object_name: str, dimension_name: str, type: str, aggregation_name: str = None)

Add an aggregation specification to the query.

Args:

object_name (str): The name of the xobject. dimension_name (str): The name of the dimension. type (str): The aggregation type (e.g., SUM, AVG, COUNT). aggregation_name (str, optional): The name of the aggregation.

Raises:

ValueError: If required arguments are missing or invalid.

groupby(attribute_name: str, object_name: str = None, dimension_name: str = None, groupby_level: str = None, groupby_level_number: int = None, groupby_states: list = None)

Add a group-by specification to the query configuration.

Args:

attribute_name (str): The name of the attribute. object_name (str, optional): The name of the xobject. dimension_name (str, optional): The name of the dimension. groupby_level (str, optional): The name of the group-by level. groupby_level_number (int, optional): The number of the group-by level. groupby_states (list, optional): Specific group-by states to apply.

Raises:

ValueError: If attribute_name is not provided.

selection(attribute_name: str, object_name: str = None, dimension_name: str = None, selected_states: list = None)

Add a selection specification to the query configuration.

Args:

attribute_name (str): The name of the attribute. object_name (str, optional): The name of the xobject. dimension_name (str, optional): The name of the dimension. selected_states (list, optional): The set of selected states.

Raises:

ValueError: If attribute_name is not provided.

set_name(request_name: str)

Assign a specific name or ID to the query.

Args:

request_name (str): The name or ID to be assigned.

Raises:

ValueError: If the request_name is not a valid string.

to_json() dict

Return the configuration of this query as JSON.

Returns:

dict: The query configuration.