Model - Cubes meta-data objects and functionality for working with them. Logical Model and Metadata
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.
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.linked_dimensions property using Cube.add_dimension()
Create a dimension from a metadata dictionary.
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.
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.
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 linked_dimensions 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:
Add dimension to cube. Replace dimension with same name. Raises ModelInconsistencyError when dimension with same name already exists in the receiver.
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.
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 Attribute 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.
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
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.
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.
Get dimension attribute from reference.
Returns True when each level has only one attribute, usually key.
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.
Returns a shallow copy of the receiver and limit hierarchies only to those specified in hierarchies. If default hierarchy name is not in the new hierarchy list, then the first hierarchy from the list is used.
Return dictionary representation of the dimension
Validate dimension. See Model.validate() for more information.
Dimension hierarchy - specifies order of dimension levels.
Some collection operations might be used, such as level in hierarchy or hierarchy[index]. String value str(hierarchy) gives the hierarchy name.
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.
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.
String representation of the AttributeBase returns its name.
cubes.ArgumentError is raised when unknown ordering type is specified.
Dimension attribute object. Also used as fact detail.
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.
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.
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.