atoti.cube module¶
-
class
atoti.cube.
Cube
(java_api, name, base_store, session)¶ Bases:
atoti._local_cube.LocalCube
[atoti.hierarchies.Hierarchies
,atoti.levels.Levels
,atoti.measures.Measures
]Cube of a Session.
-
property
aggregates_cache
¶ Aggregates cache of the cube.
- Return type
-
create_static_parameter_hierarchy
(name, members, *, data_type=None, index_measure=None, indices=None, store_name=None)¶ Create an arbitrary single-level static hierarchy with the given members.
It can be used as a parameter hierarchy in advanced analyses.
- Parameters
name (
str
) – The name of hierarchy and its single level.data_type (
Optional
[DataType
]) – The type with which the members will be stored. Automatically inferred by default.index_measure (
Optional
[str
]) – The name of the indexing measure to create for this hierarchy, if any.indices (
Optional
[Sequence
[int
]]) – The custom indices for each member in the new hierarchy. They are used when accessing a member through theindex_measure
. Defaults torange(len(members))
.store_name (
Optional
[str
]) – The name of the store backing the parameter hierarchy. Defaults to the passedname
argument.
-
create_store_column_parameter_hierarchy
(name, column)¶ Create a single level static hierarchy which takes its members from a column.
-
explain_query
(*measures, condition=None, include_totals=False, levels=None, scenario='Base', timeout=30)¶ Run the query but return an explanation of the query instead of the result.
The explanation contains a summary, global timings and the query plan with all the retrievals.
- Parameters
measures (
Union
[NamedMeasure
,QueryMeasure
]) – The measures to query. IfNone
, all the measures are queried.condition (
Union
[LevelCondition
,MultiCondition
,LevelIsInCondition
,HierarchyIsInCondition
,None
]) –The filtering condition. Only conditions on level equality with a string are supported. For instance:
lvl["Country"] == "France"
(lvl["Country"] == "USA") & (lvl["Currency"] == "USD")
h["Geography"].isin(("Asia",), ("Europe", "France"))
include_totals (
bool
) – Whether the returned DataFrame should include the grand total and subtotals. Totals can be useful but they make the DataFrame harder to work with since its index will have some empty values.levels (
Union
[~_Level,Sequence
[~_Level],None
]) – The levels to split on. IfNone
, the value of the measures at the top of the cube is returned.scenario (
str
) – The scenario to query.timeout (
int
) – The query timeout in seconds.
- Return type
QueryAnalysis
-
property
hierarchies
¶ Hierarchies of the cube.
- Return type
~_LocalHierarchies
-
property
levels
¶ Levels of the cube.
- Return type
~_Levels
-
property
measures
¶ Measures of the cube.
- Return type
~_LocalMeasures
-
query
(*measures, condition=None, include_totals=False, levels=None, mode='pretty', scenario='Base', timeout=30)¶ Query the cube to retrieve the value of the passed measures on the given levels.
In JupyterLab with the
atoti-jupyterlab
plugin installed, query results can be converted to interactive widgets with the Convert to Widget Below action available in the command palette or by right clicking on the representation of the returned Dataframe.- Parameters
measures (
Union
[NamedMeasure
,QueryMeasure
]) – The measures to query. IfNone
, all the measures are queried.condition (
Union
[LevelCondition
,MultiCondition
,LevelIsInCondition
,HierarchyIsInCondition
,None
]) –The filtering condition. Only conditions on level equality with a string are supported. For instance:
lvl["Country"] == "France"
(lvl["Country"] == "USA") & (lvl["Currency"] == "USD")
h["Geography"].isin(("Asia",), ("Europe", "France"))
include_totals (
bool
) – Whether the returned DataFrame should include the grand total and subtotals. Totals can be useful but they make the DataFrame harder to work with since its index will have some empty values.levels (
Union
[~_Level,Sequence
[~_Level],None
]) – The levels to split on. IfNone
, the value of the measures at the top of the cube is returned.scenario (
str
) – The scenario to query.timeout (
int
) – The query timeout in seconds.mode (
Literal
[‘pretty’, ‘raw’]) –The query mode.
"pretty"
is best for queries returning small results:A
QueryResult
will be returned and its rows will be sorted according to the level comparators.
"raw"
is best for benchmarks or large exports:
A faster and more efficient endpoint reducing the data transfer from Java to Python will be used.
A classic
pandas.DataFrame
will be returned.include_totals="True"
will not be allowed.The Convert to Widget Below action provided by the
atoti-jupyterlab
plugin will not be available.
- Return type
Union
[QueryResult
,DataFrame
]
-
property
schema
¶ Schema of the cube’s stores as an SVG graph.
Note
Graphviz is required to display the graph. It can be installed with Conda:
conda install graphviz
or by following the download instructions.- Return type
- Returns
An SVG image in IPython and a Path to the SVG file otherwise.
-
setup_simulation
(name, *, base_scenario='Base', levels=None, multiply=None, replace=None, add=None)¶ Create a simulation store for the given measures.
Simulations can have as many scenarios as desired.
The same measure cannot be passed in several methods.
- Parameters
name (
str
) – The name of the simulation.base_scenario (
str
) – The name of the base scenario.levels (
Optional
[Sequence
[Level
]]) – The levels to simulate on.multiply (
Optional
[Collection
[Measure
]]) – Measures whose values will be multiplied.replace (
Optional
[Collection
[Measure
]]) – Measures whose values will be replaced.add (
Optional
[Collection
[Measure
]]) – Measures whose values will be added (incremented).
- Return type
- Returns
The simulation on which scenarios can be made.
Context values shared by all the users.
Context values can also be set at query time, and per user, directly from the UI. The values in the shared context are the default ones for all the users.
queriesTimeLimit
The number of seconds after which a running query is cancelled and its resources reclaimed. Set to
-1
to remove the limit. Defaults to 30s.queriesResultLimit.intermediateSize
The limit number of point locations for a single intermediate result. This works as a safe-guard to prevent queries from consuming too much memory, which is especially useful when going to production with several simulatenous users on the same server. Set to
-1
to use the maximum limit. In atoti, the maximum limit is the default while in Atoti+ it defaults to1000000
.queriesResultLimit.tansientResultSize
Similar to
intermediateSize
but across all the intermediate results of the same query. Set to-1
to use the maximum limit. In atoti, the maximum limit is the default while in Atoti+ it defaults to10000000
.
Example
>>> df = pd.DataFrame( ... columns=["City", "Price"], ... data=[ ... ("London", 240.0), ... ("New York", 270.0), ... ("Paris", 200.0), ... ], ... ) >>> store = session.read_pandas( ... df, keys=["City"], store_name="shared_context example" ... ) >>> cube = session.create_cube(store) >>> cube.shared_context["queriesTimeLimit"] = 60 >>> cube.shared_context["queriesResultLimit.intermediateSize"] = 1000000 >>> cube.shared_context["queriesResultLimit.transientSize"] = 10000000 >>> cube.shared_context {'queriesTimeLimit': '60', 'queriesResultLimit.intermediateSize': '1000000', 'queriesResultLimit.transientSize': '10000000'}
- Return type
-
property
simulations
¶ Simulations of the cube.
- Return type
-
property
-
class
atoti.cube.
CubeContext
(_java_api, _cube)¶ Bases:
MutableMapping
[str
,str
],atoti._repr_utils.ReprJsonable
-
clear
() → None. Remove all items from D.¶
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
items
() → a set-like object providing a view on D’s items¶
-
keys
() → a set-like object providing a view on D’s keys¶
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem
() → (k, v), remove and return some (key, value) pair¶ as a 2-tuple; but raise KeyError if D is empty.
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
update
([E, ]**F) → None. Update D from mapping/iterable E and F.¶ If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
-
values
() → an object providing a view on D’s values¶
-