Cubes

class tinyolap.cube.Cube(cub_creation_key, name: str, dimensions=None, measures=None, description: Optional[str] = None)

Represents a multi-dimensional table.

area(*args) tinyolap.area.Area

Returns a new Area fom the Cube.

property caching: bool

Identifies if caching is activated for the current cube. By default, caching is activated for all cubes.

cell(*args) tinyolap.cell.Cell

Returns a new Cell from the Cube.

clear()

Removes all values from the Cube.

property counter_aggregations: int

Returns the number aggregations that have been executed.

property counter_cell_requests: int

Returns the number of cell requests executed.

property counter_rule_requests: int

Returns the number of rules that have been executed.

property default_measure: str

Returns/sets the default measure of the cube. By default, this is always the first measure from the list of measures.

property dimension_names: tuple

Returns the number of dimensions of the cube.

property dimensions: tuple

Returns the dimensions of the cube.

property dimensions_count: int

Returns the number of dimensions of the cube.

from_json(json_string: str)

Initializes the cube from a json string.

Warning

Calling this method for cubes which are already in use (contain data) will very likely corrupt your database! Calling this method is only save before you write any data to a cube. Handle with care.

Parameters

json_string – The json string containing the cube definition.

Raises

TinyOlapFatalError – Raised if an error occurred during the deserialization from json string.

get(address: tuple)

Reads a value from the cube for a given idx_address. If no records exist for the given idx_address, then 0.0 will be returned. :raises TinyOlapInvalidKeyError:

get_dimension(name: str)

Returns the dimension defined for the given dimension index.

get_dimension_by_index(index: int)

Returns a dimension from a cubes list of dimensions at the given index.

get_dimension_ordinal(name: str)

Returns the ordinal position of a dimension with the cube definition. :return The ordinal position of the dimension, if the dimension is contained ones in the cube.

A list of ordinal positions if the dimension is contained multiple times in the cube.

get_measures() list[str]

Returns the list of measures of a cube.

property measures: list[str]

Returns the list of measures of a cube.

property measures_count: int

Returns the number of measures of the cube.

property name: str

Returns the name of the cube.

register_rule(function, trigger: Optional[list[str]] = None, scope: tinyolap.rules.RuleScope = RuleScope.ALL_LEVELS, injection: tinyolap.rules.RuleInjectionStrategy = RuleInjectionStrategy.NO_INJECTION, code: Optional[str] = None)

Registers a rule function for the cube. Rules function either need to be decorated with the @rules(...) decorator or the arguments trigger and scope of the add_rules(...) function must be specified.

Parameters
  • code – (optional)Source code of the function.

  • injection – The injection strategy defined for the function.

  • function – The rules function to be called.

  • trigger – The cell idx_address trigger that should trigger the rule.

  • scope – The scope of the rule.

remove_all_rules()

Removes all rule functions from the cube.

remove_rule(pattern: list[str]) bool

Removes (unregisters) a rule function from the cube.

Parameters

pattern – The trigger of the rule to be removed.

Returns

True, if a function with the given trigger was found and removed, False otherwise.

reset_counters()

Resets the internal counters for cell- and rule-requests and aggregations.

set(address: tuple, value)

Writes a value to the cube for the given bolt (idx_address and measures).

to_json()

Returns the json representation of the cube. Helpful for serialization and deserialization of cubes. The json returned by this function is the same as the one used by storage providers (if available).

Returns

A json string representing the cube.

validate_rules(save_after_sucessfull_validation: bool = True)

Validates all registered rules by calling each with a random cell matching the defined rule trigger and rule scope. Calling this methods (maybe even multiple times) can be usefull for highlevel testing of your rules.

Warning

Calling this method does not replace proper rule testing. Escpecially when your database should be used by other users or for serious purposes you need to ensure that your rule calculations ideally never (or only for explicit purposes) thows an error.

Parameters

save_after_sucessfull_validation – If set to true

Returns

(True, validation_results_json:str) if all rules returned a proper result without causing errors. (False, validation_results_json:str) if at least one rule causes an error. The validation results

will contain information for all rules that have been processed. The validation will not stop on the first error casued by a rule function.

Cells