Model - Cubes meta-data objects and functionality for working with them. Logical Model and Metadata
Note
All model objects: Cube, Dimension, Hierarchy, Level and attribute objects should be considered immutable once created. Any changes to the object attributes might result in unexpected behavior.
See also
Following methods are used to create model objects from a metadata dicitonary.
Create a cube object from metadata dictionary. The cube has no dimensions attached after creation. You should link the dimensions to the cube according to the Cube.dimension_links property using Cube.add_dimension()
Create a dimension from a metadata dictionary. Some rules:
Create a level object from metadata. name can override level name in the metadata.
Makes sure that the obj is an Attribute instance. If obj is a string, then new instance is returned. If it is a dictionary, then the dictionary values are used for Attribute instance initialization.
Create a measure object from metadata.
Create a list of attributes from a list of strings or dictionaries. see cubes.coalesce_attribute() for more information.
Note
The Model class is no longer publicly available and should not be used. For more information, please see cubes.Workspace.
Create a new Cube model object.
Properties:
There are two ways how to assign dimensions to the cube: specify them during cube initialization in dimensions by providing a list of Dimension objects. Alternatively you can set dimension_links list with dimension names and the link the dimension using cubes.Cube.add_dimension().
Physical properties of the cube are described in the following attributes. They are used by the backends:
The dimension links are either dimension names or dictionaries specifying how the dimension will be linked to the cube. The keys of the link dictionary are:
Add dimension to cube. Replace dimension with same name. Raises ModelInconsistencyError when dimension with same name already exists in the receiver.
Get aggregate object. If obj is a string, then aggregate with given name is returned, otherwise aggregate object is returned if it belongs to the cube. Returned object is of MeasureAggregate type.
Raises NoSuchAttributeError when there is no such aggregate or when there are multiple aggregates with the same name (which also means that the model is not valid).
Returns aggregtates for measure with name. Only direct function aggregates are returned. If the measure is specified in an expression, the aggregate is not included in the returned list
All cube’s attributes for aggregation: attributes of dimensions and aggregates.
All cube’s attributes from the fact: attributes of dimensions, details and measures.
Returns an attribute object (dimension attribute, measure or detail).
Get dimension object. If obj is a string, then dimension with given name is returned, otherwise dimension object is returned if it belongs to the cube.
Raises NoSuchDimensionError when there is no such dimension.
Get a list of aggregates with names
Returns a list of cube’s attributes. If aggregated is True then attributes after aggregation are returned, otherwise attributes for a fact are considered.
Aggregated attributes contain: dimension attributes and aggregates. Fact attributes contain: dimension attributes, fact details and fact measures.
If the list attributes is empty, all attributes are returned.
If simplified_references is True then dimension attribute references in attrubutes are considered simplified, otherwise they are considered as full (dim.attribute).
Get a list of measures as Attribute objects. If measures is None then all cube’s measures are returned.
Links dimensions according to cube’s dimension_links. The dimensions should be a dictionary with keys as dimension names and values as Dimension instances.
Get measure object. If obj is a string, then measure with given name is returned, otherwise measure object is returned if it belongs to the cube. Returned object is of Measure type.
Raises NoSuchAttributeError when there is no such measure or when there are multiple measures with the same name (which also means that the model is not valid).
Returns a measure aggregate by name.
Returns non-additive type of aggregate‘s measure. If aggregate has no measure specified or is unknown (backend-specific) then None is returned.
Remove a dimension from receiver. dimension can be either dimension name or dimension object.
Convert to a dictionary. If with_mappings is True (which is default) then joins, mappings, fact and options are included. Should be set to False when returning a dictionary that will be provided in an user interface or through server API.
Validate cube. See Model.validate() for more information.
Create a new dimension
Attributes:
Dimension class is not meant to be mutable. All level attributes will have new dimension assigned.
Note that the dimension will claim ownership of levels and their attributes. You should make sure that you pass a copy of levels if you are cloning another dimension.
Note: The hierarchy will be owned by the dimension.
Get dimension attribute from reference.
Return all dimension attributes regardless of hierarchy. Order is not guaranteed, use cubes.Hierarchy.all_attributes() to get known order. Order of attributes within level is preserved.
Returns a clone of the receiver with some modifications. master of the clone is set to the receiver.
Returns True when each level has only one attribute, usually key.
Get list of dimension hierarchies.
Get hierarchy object either by name or as Hierarchy. If obj is None then default hierarchy is returned.
Is true if dimension has only one level
Return all dimension key attributes, regardless of hierarchy. Order is not guaranteed, use a hierarchy to have known order.
Get level by name or as Level object. This method is used for coalescing value
Get list of level names. Order is not guaranteed, use a hierarchy to have known order.
Get list of all dimension levels. Order is not guaranteed, use a hierarchy to have known order.
Return dictionary representation of the dimension
Validate dimension. See Model.validate() for more information.
Dimension hierarchy - specifies order of dimension levels.
Attributes:
Some collection operations might be used, such as level in hierarchy or hierarchy[index]. String value str(hierarchy) gives the hierarchy name.
Note: The levels should have attributes already owned by a dimension.
Return all dimension attributes as a single list.
Returns True if level is last level of the hierarchy.
Return all dimension key attributes as a single list.
Get order index of level. Can be used for ordering and comparing levels within hierarchy.
Returns levels for given depth. If path is longer than hierarchy levels, cubes.ArgumentError exception is raised
Returns levels for given path. If path is longer than hierarchy levels, cubes.ArgumentError exception is raised
Returns next level in hierarchy after level. If level is last level, returns None. If level is None, then the first level is returned.
Returns True if path is base path for the hierarchy. Base path is a path where there are no more levels to be added - no drill down possible.
Returns previous level in hierarchy after level. If level is first level or None, returns None
Rolls-up the path to the level. If level is None then path is rolled-up only one level.
If level is deeper than last level of path the cubes.HierarchyError exception is raised. If level is the same as path level, nothing happens.
Convert to dictionary. Keys:
Object representing a hierarchy level. Holds all level attributes.
This object is immutable, except localization. You have to set up all attributes in the initialisation process.
Attributes:
Cardinality values:
Note: the attributes are going to be owned by the dimension.
Get attribute by name
Is True when level has more than one attribute, for all levels with only one attribute it is False.
Convert to dictionary
Base class for dimension attributes, measures and measure aggregates.
Attributes:
String representation of the AttributeBase returns its name.
cubes.ArgumentError is raised when unknown ordering type is specified.
Localize the attribute, allow localization of the format.
Dimension attribute object. Also used as fact detail.
Attributes:
String representation of the Attribute returns its name (without dimension prefix).
cubes.ArgumentError is raised when unknown ordering type is specified.
Return full attribute reference. Append locale if it is one of attribute’s locales, otherwise raise cubes.ArgumentError. If simplify is True, then reference to an attribute of flat dimension without details will be just the dimension name.
Fact measure attribute.
Properties in addition to the attribute base properties:
Note that if the formula is specified, it should not refer to any other measure that refers to this one (no circular reference).
The aggregates is an optional property and is used for: * measure aggergate object preparation * optional validation
String representation of a Measure returns its name.
Creates default measure aggregates from a list of receiver’s measures. This is just a convenience function, correct models should contain explicit list of aggregates. If no aggregates are specified, then the only aggregate sum is assumed.
Masure aggregate
Attributes:
Exception raised when there is an error with model and its structure, mostly during model construction.
Raised when there is incosistency in model structure, mostly when model was created programatically in a wrong way by mismatching classes or misonfiguration.
Raised when a dimension is requested that does not exist in the model.
Raised when an unknown attribute, measure or detail requested.