SubsetService
from skipcheck_tm1.services import SubsetService Subsets: a hierarchy's public, private and session subsets (SubsetScope), their
elements, and the operations bound to a subset or creating a session subset.
A static subset lists its elements; a dynamic one has an MDX Expression.
Binding Elements in a subset PATCH appends to them, so update
refuses it: add_elements appends by name and clear_elements empties the
list.
Create a static subset, binding its elements:
# A static subset lists its elements, bound by their paths
elements = ODataPath.of("Dimensions").key("Region").nav("Hierarchies").key("Region").nav("Elements")
key_regions = SubsetPatch.builder().name("Key Regions").bind_elements(elements.key("North"), elements.key("South")).build()
return tm1.subsets.create("Region", "Region", SubsetScope.PUBLIC, key_regions)
Create a dynamic subset from an MDX expression:
# A dynamic subset has an MDX expression, evaluated each time it's read
leaves = SubsetPatch.builder().name("All Leaves").expression("{TM1FILTERBYLEVEL({TM1SUBSETALL([Region].[Region])}, 0)}").build()
return tm1.subsets.create("Region", "Region", SubsetScope.PUBLIC, leaves)
Replace a static subset's elements:
# A PATCH appends elements, so empty the list, then add the new ones in order
tm1.subsets.clear_elements("Region", "Region", SubsetScope.PUBLIC, "Key Regions")
tm1.subsets.add_elements("Region", "Region", SubsetScope.PUBLIC, "Key Regions", ["East", "West"])
Create a session subset and read its elements by the name TM1 gave it:
# TM1 names a session subset itself, ignoring the name sent: read it by the name
# it gives back
regions = SubsetPatch.builder().name("Regions").expression("{[Region].[Region].[Total].Children}").build()
subset = tm1.subsets.create_session_subset("Region", "Region", regions)
assert subset.name is not None
elements = tm1.subsets.elements("Region", "Region", SubsetScope.SESSION, subset.name, ODataQuery.none().select(Element.NAME))
return [element.name for element in elements]
The asyncio flavor, skipcheck_tm1.aio, has the same methods to await, on AsyncSubsetService.
Members
list | GET …/Hierarchies('h')/Subsets (or the private or session ones). |
get | GET …/Subsets('s'). |
create | Creates a subset. |
update | Changes the properties the patch sets, such as a dynamic subset's expression; with etag, only if it hasn't changed since it was read.Raises ValueError if the patch sets or binds Elements, which TM1 appends. |
add_elements | PATCH …/Subsets('s') binding Elements. |
clear_elements | Removes every element from a static subset; the elements stay in the hierarchy. |
delete | DELETE …/Subsets('s'). |
elements | A static subset's elements in order, or what a dynamic one's expression gives now. |
hierarchy | GET …/Subsets('s')/Hierarchy. |
save_as | Copies a subset under a new name. |
set_element | Adds an element to a static subset, or moves it if it's there. |
set_element_before | tm1.SetElement with Before. |
set_element_after | tm1.SetElement with After. |
create_session_subset | tm1.CreateSessionSubset with a definition. |
create_session_subset_from | tm1.CreateSessionSubset with a reference. |
list
list(dimension: str, hierarchy: str, scope: SubsetScope, query: ODataQuery | None = None, **options: Any) -> list[Subset]GET …/Hierarchies('h')/Subsets (or the private or session ones). TM1 (11.8) lists no session subsets, though each reads by the name create_session_subset returned.
get
get(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, query: ODataQuery | None = None, **options: Any) -> SubsetGET …/Subsets('s').
create
create(dimension: str, hierarchy: str, scope: SubsetScope, subset: Any) -> SubsetPOST …/Subsets: creates a subset: static with Elements@odata.bind (SubsetPatch.Builder.bind_elements), dynamic with an Expression.
update
update(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, patch: Any, etag: str | None = None) -> NonePATCH …/Subsets('s'): changes the properties the patch sets, such as a dynamic subset's expression; with etag, only if it hasn't changed since it was read.
Raises ValueError if the patch sets or binds Elements, which TM1 appends: use add_elements or clear_elements.
add_elements
add_elements(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, elements: Sequence[str]) -> NonePATCH …/Subsets('s') binding Elements: appends elements to a static subset, in order.
clear_elements
clear_elements(dimension: str, hierarchy: str, scope: SubsetScope, subset: str) -> NoneDELETE …/Subsets('s')/Elements/$ref: removes every element from a static subset; the elements stay in the hierarchy.
TM1 REST Navigation Subset/Elements
delete
delete(dimension: str, hierarchy: str, scope: SubsetScope, subset: str) -> NoneDELETE …/Subsets('s').
elements
elements(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, query: ODataQuery | None = None, **options: Any) -> list[Element]GET …/Subsets('s')/Elements: a static subset's elements in order, or what a dynamic one's expression gives now.
TM1 REST Navigation Subset/Elements
hierarchy
hierarchy(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, query: ODataQuery | None = None, **options: Any) -> HierarchyGET …/Subsets('s')/Hierarchy.
TM1 REST Navigation Subset/Hierarchy
save_as
save_as(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, new_name: str, make_private: bool | None = None, make_static: bool | None = None) -> Subsettm1.SaveAs: copies a subset under a new name: by default as public and keeping whether it's static or dynamic; make_private and make_static change that (a static copy holds the elements a dynamic one gives now).
TM1 REST Action Subset/SaveAs
set_element
set_element(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, element: str) -> Nonetm1.SetElement: adds an element to a static subset, or moves it if it's there. TM1 (11.8) appends it when no position is given.
TM1 REST Action Subset/SetElement
set_element_before
set_element_before(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, element: str, before: str) -> Nonetm1.SetElement with Before: places an element just before another in a static subset.
TM1 REST Action Subset/SetElement
set_element_after
set_element_after(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, element: str, after: str) -> Nonetm1.SetElement with After: places an element just after another in a static subset.
TM1 REST Action Subset/SetElement
create_session_subset
create_session_subset(dimension: str, hierarchy: str, definition: Any) -> Subsettm1.CreateSessionSubset with a definition: creates a subset visible only to this session. TM1 (11.8) ignores the definition's Name and names it itself (like an ID, yExesF4AAIABAAAQ); the result has the name to use.
TM1 REST Action Hierarchy/CreateSessionSubset
create_session_subset_from
create_session_subset_from(dimension: str, hierarchy: str, scope: SubsetScope, subset: str) -> Subsettm1.CreateSessionSubset with a reference: copies a subset into one visible only to this session.
TM1 REST Action Hierarchy/CreateSessionSubset