atoti.mapping_lookup(*, check)
Create a context customizing the behavior ofMapping lookups.
A mapping lookup is calling the Mapping._getitem_() method by doing mapping[key].
The mappings affected by this context are:
-
Clusters. -
Cubes. -
Hierarchies. -
Levels. -
Measures. -
QueryCubes. -
Table’s columns. -
Tables. -
Parameters:
check (bool) –
-
If
True, passing a key that does have a corresponding value in the mapping will raise a KeyError. This is the default behavior outside of this context. -
If
False, keys will not be checked, saving a roundtrip with the server. This mode is less safe since incorrect keys will not be caught immediately. Besides, the errors that will be raised down the chain may have less explicit messages. The main use cases for this mode are:-
To get a reference to an object before it is actually defined in the data model.
For instance, it can be used to define
restrictionsbefore tables are created. -
To improve performance when defining the data model or inside a
data_transaction()by reducing roundtrips to the server when the looked up keys are known to be correct. This is especially impactful when usingatoti.Session.connect()with a remote url since latency will not be negligible.__debug__is a good argument to pass for this use case since it will most likely be:Trueduring prototyping and testing where good developer experience is important.Falsein production where performance matters more.
- For
Levels, this means that the syntaxl[level_name]cannot be used since multiple dimensions or hierarchies could have a level namedlevel_nameand the server cannot be used to ensure unicity and to return the corresponding dimension and hierarchy names. For the same reason,l[hierarchy_name, level_name]cannot be used either. Onlyl[dimension_name, hierarchy_name, level_name]is accepted. - For
Hierarchies, onlyh[dimension_name, hierarchy_name]is accepted.
-
To get a reference to an object before it is actually defined in the data model.
For instance, it can be used to define
-
If
- Return type: Generator[ _Report, None, None]
Iteration, the
in operator, and the get() method are not impacted by this context: