ViewService
from skipcheck_tm1.services import ViewService Views: a cube's public and private views (ViewScope), native
(NativeView: subsets on columns, rows and titles) or MDX (MDXView).
They're read as View, so each comes back as its own type.
A native view's subsets are in complex properties, reached by expanding through the
tm1.NativeView type: list with tm1.NativeView/Columns/Subset,
or get_native, which reads one view through the type. On TM1 11.8.35 the
type-cast expand works on a list holding MDX views too; an older server was reported to
fail it, and get_native doesn't depend on it.
Create a native view: each axis binds a subset, and every dimension of the cube has to be on one.
# Months across, regions down, and the cube's other dimensions as titles: every
# dimension of the cube must be on an axis. Each axis binds an existing subset.
dimensions = ODataPath.of("Dimensions")
months = dimensions.key("Month").nav("Hierarchies").key("Month").nav("Subsets").key("Quarters")
regions = dimensions.key("Region").nav("Hierarchies").key("Region").nav("Subsets").key("Leaves")
versions = dimensions.key("Version").nav("Hierarchies").key("Version")
measures = dimensions.key("Measure").nav("Hierarchies").key("Measure")
actual = ViewTitlePatch.builder().bind_subset(versions.nav("Subsets").key("All")).bind_selected(versions.nav("Elements").key("Actual")).build()
revenue = ViewTitlePatch.builder().bind_subset(measures.nav("Subsets").key("All")).bind_selected(measures.nav("Elements").key("Revenue")).build()
view = (
NativeViewPatch.builder()
.name("Revenue by Region")
.columns([ViewAxisSelectionPatch.builder().bind_subset(months).build()])
.rows([ViewAxisSelectionPatch.builder().bind_subset(regions).build()])
.titles([actual, revenue])
.suppress_empty_rows(True)
.build()
)
return tm1.views.create("Sales", ViewScope.PUBLIC, view)
Create an MDX view from its query:
# An MDX view is its query
mdx = (
"SELECT {[Month].[Month].[Jan], [Month].[Month].[Feb]} ON 0,"
" {TM1FILTERBYLEVEL({TM1SUBSETALL([Region].[Region])}, 0)} ON 1 FROM [Sales]"
" WHERE ([Version].[Version].[Actual], [Measure].[Measure].[Revenue])"
)
return tm1.views.create("Sales", ViewScope.PRIVATE, MDXViewPatch.builder().name("My Revenue").mdx(mdx).build())
List a cube's views, telling the kinds apart by type:
# Each view comes back as its own type
described = []
for view in tm1.views.list("Sales", ViewScope.PUBLIC):
if isinstance(view, MDXView):
described.append(f"{view.name}: {view.mdx}")
elif isinstance(view, NativeView):
described.append(f"{view.name}: native")
else:
described.append(f"{view.name}: unknown kind")
return described
Read the subsets on a native view's axes:
# A native view's axes are complex properties: expand them by path, through the
# view's type
axes = ODataQuery.none().expand("Columns/Subset").expand("Rows/Subset")
view = tm1.views.get_native("Sales", ViewScope.PUBLIC, "Revenue by Region", axes)
return [axis.subset.unique_name for axis in [*(view.columns or []), *(view.rows or [])] if axis.subset is not None]
The asyncio flavor, skipcheck_tm1.aio, has the same methods to await, on AsyncViewService.
Members
list | GET Cubes('c')/Views (or the private ones). |
get | The view as its own type, or a Tm1NotFoundError. |
get_native | Reads a native view through its type, so its axes can be expanded. |
create | Creates a view; the patch's type says which kind (MDXViewPatch, NativeViewPatch), and a native view's axes bind subsets. |
update | Changes the properties the patch (of the view's kind) sets, such as an MDX view's MDX. |
delete | DELETE Cubes('c')/Views('v'); its subsets stay. |
cube | The view's cube. |
list
list(cube: str, scope: ViewScope, query: ODataQuery | None = None, **options: Any) -> list[View]GET Cubes('c')/Views (or the private ones): the views, each as its own type. A native view's axes expand through its type, as tm1.NativeView/Columns/Subset.
TM1 REST Navigation Cube/Views Navigation Cube/PrivateViews
get
get(cube: str, scope: ViewScope, view: str, query: ODataQuery | None = None, **options: Any) -> ViewGET Cubes('c')/Views('v'): the view as its own type, or a Tm1NotFoundError.
TM1 REST Navigation Cube/Views Navigation Cube/PrivateViews
get_native
get_native(cube: str, scope: ViewScope, view: str, query: ODataQuery | None = None, **options: Any) -> NativeViewGET Cubes('c')/Views('v')/tm1.NativeView: reads a native view through its type, so its axes can be expanded: Columns/Subset, Rows/Subset, Titles/Subset, Titles/Selected. They're complex properties, so TM1 wants paths, not nested options. An MDX view is an error.
TM1 REST Navigation Cube/Views Navigation Cube/PrivateViews Navigation ViewAxisSelection/Subset Navigation ViewTitle/Subset Navigation ViewTitle/Selected
create
create(cube: str, scope: ViewScope, view: Any) -> ViewPOST Cubes('c')/Views: creates a view; the patch's type says which kind (MDXViewPatch, NativeViewPatch), and a native view's axes bind subsets. It needs a name. TM1 (11.8) refuses a native view that leaves any of the cube's dimensions off its columns, rows and titles (400, "All cube dimensions must be placed on an axis").
TM1 REST Navigation Cube/Views Navigation Cube/PrivateViews
update
update(cube: str, scope: ViewScope, view: str, patch: Any, etag: str | None = None) -> NonePATCH Cubes('c')/Views('v'): changes the properties the patch (of the view's kind) sets, such as an MDX view's MDX. With etag, sent as If-Match: a Tm1PreconditionFailedError if the view changed since it was read.
TM1 REST Navigation Cube/Views Navigation Cube/PrivateViews
delete
delete(cube: str, scope: ViewScope, view: str) -> NoneDELETE Cubes('c')/Views('v'); its subsets stay.
TM1 REST Navigation Cube/Views Navigation Cube/PrivateViews
cube
cube(cube: str, scope: ViewScope, view: str, query: ODataQuery | None = None, **options: Any) -> CubeGET Cubes('c')/Views('v')/Cube: the view's cube.
TM1 REST Navigation View/Cube