Class CellsetService
A cellset lives on the server until it's deleted, or the session ends; one that isn't
deleted holds the server's memory. The 1:1 methods (execute(String, ODataQuery), cells(String, ODataQuery),
partition(String, long, long, ODataQuery), delete(String)) leave that to the caller. stream(String, ODataQuery, int, BiFunction) does it
all: runs the query, pages the cells in order, and deletes the cellset when the result
completes, fails or is cancelled.
Read the cells of an MDX query, placing each by its ordinal on the axes:
String mdx = """
SELECT {[Month].[Month].[Jan], [Month].[Month].[Feb], [Month].[Month].[Mar]} ON 0,
{TM1FILTERBYLEVEL({TM1SUBSETALL([Region].[Region])}, 0)} ON 1
FROM [Sales]
WHERE ([Version].[Version].[Actual], [Measure].[Measure].[Revenue])""";
return tm1.cellsets()
.stream(mdx, ODataQuery.none().select(CellsetCell.ORDINAL, CellsetCell.VALUE), 10_000, (cellset, cells) -> {
// Axis 0 is the columns, axis 1 the rows; ordinals run along a row
List<CellsetAxisTuple> columns = cellset.axes().get(0).tuples();
List<CellsetAxisTuple> rows = cellset.axes().get(1).tuples();
return cells.map(cell -> {
CellsetAxisTuple row = rows.get((int) (cell.ordinal() / columns.size()));
CellsetAxisTuple column = columns.get((int) (cell.ordinal() % columns.size()));
return row.members().get(0).name() + ", " + column.members().get(0).name() + ": " + cell.value();
});
});
Write into the cells of a query by ordinal, deleting its cellset after:
// Write by ordinal into the cells of a query, then delete its cellset; the cells
// must be leaves, as TM1 doesn't spread to a consolidation
CellsetService cellsets = tm1.cellsets();
String mdx = "SELECT {[Month].[Month].[Jan], [Month].[Month].[Feb]} ON 0, {[Region].[Region].[North]} ON 1"
+ " FROM [Sales] WHERE ([Version].[Version].[Budget], [Measure].[Measure].[Revenue])";
return Mono.usingWhen(cellsets.execute(mdx, ODataQuery.none()),
cellset -> cellsets.updateCells(cellset.id(),
List.of(CellsetUpdatePatch.builder().ordinal(0L).value(1200).build(),
CellsetUpdatePatch.builder().ordinal(1L).value(1350).build())),
cellset -> cellsets.delete(cellset.id()));
Read the values of a saved view:
// The values of a saved view, read in the same round trip as its cellset
CellsetService cellsets = tm1.cellsets();
return Flux.usingWhen(
cellsets.executeView("Sales", ViewScope.PUBLIC, "Revenue by Region",
ODataQuery.none().expand(Cellset.CELLS, c -> c.select(CellsetCell.VALUE))),
cellset -> Flux.fromIterable(cellset.cells()).map(CellsetCell::value),
cellset -> cellsets.delete(cellset.id()));
-
Constructor Summary
ConstructorsConstructorDescriptionCellsetService(Tm1Session session) A service sending its requests throughsession. -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Flux<CellsetAxis> axes(String id, ODataQuery query) GET Cellsets('id')/Axes, streamed: columns (0), rows (1), and so on, then the slicer.reactor.core.publisher.Flux<Member> cellMembers(String id, long ordinal, ODataQuery query) GET Cellsets('id')/Cells(n)/Members, streamed: the members that place a cell, one per hierarchy of the cube.reactor.core.publisher.Flux<CellsetCell> cells(String id, ODataQuery query) GET Cellsets('id')/Cells, streamed, in ordinal order.reactor.core.publisher.Mono<Cube> cube(String id, ODataQuery query) GET Cellsets('id')/Cube.reactor.core.publisher.Mono<Void> DELETE Cellsets('id'): frees the cellset's memory on the server.reactor.core.publisher.Mono<Cellset> execute(String mdx, ODataQuery query) ExecuteMDX: runs an MDX query, leaving its cellset on the server untildelete(String).reactor.core.publisher.Mono<Void> executeStatement(String mdx) ExecuteMDXStatement: runs an MDX statement for its effect, keeping no cellset.reactor.core.publisher.Mono<Cellset> executeView(String cube, ViewScope scope, String view, ODataQuery query) tm1.Executeon a native or MDX view: its cellset, left on the server untildelete(String).reactor.core.publisher.Mono<Cellset> get(String id, ODataQuery query) GET Cellsets('id').reactor.core.publisher.Flux<Hierarchy> hierarchies(String id, int axis, ODataQuery query) GET Cellsets('id')/Axes(n)/Hierarchies, streamed.reactor.core.publisher.Flux<Cellset> list(ODataQuery query) GET Cellsets, streamed.reactor.core.publisher.Flux<CellsetCell> partition(String id, long begin, long end, ODataQuery query) tm1.GetPartition(Begin=b,End=e): a rectangle of cells, streamed.reactor.core.publisher.Mono<View> saveViewAs(String id, String name) tm1.SaveViewAs: saves the cellset's query as a public view of its cube, failing if one has the name.reactor.core.publisher.Mono<View> saveViewAs(String id, String name, boolean overwrite, boolean makePrivate) tm1.SaveViewAs: saves the cellset's query as a view of its cube.<R> reactor.core.publisher.Flux<R> stream(String mdx, ODataQuery cellQuery, int pageSize, BiFunction<Cellset, reactor.core.publisher.Flux<CellsetCell>, org.reactivestreams.Publisher<R>> handler) Runs an MDX query and streams its cells tohandler, then deletes the cellset: when the result completes, fails, or is cancelled.reactor.core.publisher.Flux<Member> tupleMembers(String id, int axis, int tuple, ODataQuery query) GET Cellsets('id')/Axes(n)/Tuples(t)/Members, streamed: one member per hierarchy on the axis.reactor.core.publisher.Flux<CellsetAxisTuple> tuples(String id, int axis, ODataQuery query) GET Cellsets('id')/Axes(n)/Tuples, streamed, in order: an axis can be large.reactor.core.publisher.Mono<Void> tm1.Update: writes one value to a cell of the cellset, by ordinal.reactor.core.publisher.Mono<Void> updateCells(String id, List<CellsetUpdatePatch> updates) tm1.UpdateCells: writes many of the cellset's cells, each its own value, by ordinal.
-
Constructor Details
-
CellsetService
A service sending its requests throughsession.- Parameters:
session- the session
-
-
Method Details
-
execute
@Tm1Endpoint("ActionImport ExecuteMDX") public reactor.core.publisher.Mono<Cellset> execute(String mdx, ODataQuery query) ExecuteMDX: runs an MDX query, leaving its cellset on the server untildelete(String). ExpandAxesandCells(with$topand$select) to get them in the same round trip.- Parameters:
mdx- the queryquery- what to expand of the cellset- Returns:
- the cellset, with its
ID
-
executeStatement
@Tm1Endpoint("ActionImport ExecuteMDXStatement") public reactor.core.publisher.Mono<Void> executeStatement(String mdx) ExecuteMDXStatement: runs an MDX statement for its effect, keeping no cellset. Needs schema 11.8.20. TM1 (11.8) runs aSELECTand returns nothing, and rejectsCREATE SETas a syntax error (code 501).- Parameters:
mdx- the statement- Returns:
- completes when it's run
-
executeView
@Tm1Endpoint("Action NativeView/Execute") @Tm1Endpoint("Action MDXView/Execute") public reactor.core.publisher.Mono<Cellset> executeView(String cube, ViewScope scope, String view, ODataQuery query) tm1.Executeon a native or MDX view: its cellset, left on the server untildelete(String).- Parameters:
cube- the cube's namescope- where the view isview- the view's namequery- what to expand of the cellset- Returns:
- the cellset, with its
ID
-
list
@Tm1Endpoint("EntitySet Cellsets") public reactor.core.publisher.Flux<Cellset> list(ODataQuery query) GET Cellsets, streamed. TM1 (11.8) lists none, though each cellset reads by its ID withget(String, ODataQuery): keep the IDs of the cellsets you create.- Parameters:
query- what to select and expand- Returns:
- the cellsets
-
get
@Tm1Endpoint("EntitySet Cellsets") public reactor.core.publisher.Mono<Cellset> get(String id, ODataQuery query) GET Cellsets('id').- Parameters:
id- the cellset's IDquery- what to expand- Returns:
- the cellset, or a
Tm1NotFoundExceptionif it's gone
-
delete
DELETE Cellsets('id'): frees the cellset's memory on the server.- Parameters:
id- the cellset's ID- Returns:
- completes when it's deleted
-
axes
@Tm1Endpoint("Navigation Cellset/Axes") public reactor.core.publisher.Flux<CellsetAxis> axes(String id, ODataQuery query) GET Cellsets('id')/Axes, streamed: columns (0), rows (1), and so on, then the slicer. TM1 (11.8) adds the slicer even without aWHERE: it holds the cube's other dimensions, such as its virtualSandboxes, with cardinality 1.- Parameters:
id- the cellset's IDquery- what to expand, such asTuples($expand=Members)- Returns:
- the axes
-
hierarchies
@Tm1Endpoint("Navigation CellsetAxis/Hierarchies") public reactor.core.publisher.Flux<Hierarchy> hierarchies(String id, int axis, ODataQuery query) GET Cellsets('id')/Axes(n)/Hierarchies, streamed.- Parameters:
id- the cellset's IDaxis- the axis ordinalquery- what to select- Returns:
- the hierarchies on the axis
-
tuples
@Tm1Endpoint("Navigation CellsetAxis/Tuples") public reactor.core.publisher.Flux<CellsetAxisTuple> tuples(String id, int axis, ODataQuery query) GET Cellsets('id')/Axes(n)/Tuples, streamed, in order: an axis can be large.- Parameters:
id- the cellset's IDaxis- the axis ordinalquery- what to expand, such asMembers($select=Name)- Returns:
- the axis's tuples
-
tupleMembers
@Tm1Endpoint("Navigation CellsetAxisTuple/Members") public reactor.core.publisher.Flux<Member> tupleMembers(String id, int axis, int tuple, ODataQuery query) GET Cellsets('id')/Axes(n)/Tuples(t)/Members, streamed: one member per hierarchy on the axis.- Parameters:
id- the cellset's IDaxis- the axis ordinaltuple- the tuple ordinalquery- what to select- Returns:
- the tuple's members
-
cells
@Tm1Endpoint("Navigation Cellset/Cells") public reactor.core.publisher.Flux<CellsetCell> cells(String id, ODataQuery query) GET Cellsets('id')/Cells, streamed, in ordinal order. Use$topand$skip, orpartition(String, long, long, ODataQuery), for pages.- Parameters:
id- the cellset's IDquery- what to select of each cell (Ordinal,Value, …)- Returns:
- the cells
-
cellMembers
@Tm1Endpoint("Navigation CellsetCell/Members") public reactor.core.publisher.Flux<Member> cellMembers(String id, long ordinal, ODataQuery query) GET Cellsets('id')/Cells(n)/Members, streamed: the members that place a cell, one per hierarchy of the cube. TM1 (11.8) includes the virtualSandboxesdimension's,Base, first.- Parameters:
id- the cellset's IDordinal- the cell's ordinalquery- what to select- Returns:
- the cell's members
-
cube
@Tm1Endpoint("Navigation Cellset/Cube") public reactor.core.publisher.Mono<Cube> cube(String id, ODataQuery query) GET Cellsets('id')/Cube.- Parameters:
id- the cellset's IDquery- what to select and expand- Returns:
- the cube the cellset is from
-
partition
@Tm1Endpoint("Function Cellset/GetPartition") public reactor.core.publisher.Flux<CellsetCell> partition(String id, long begin, long end, ODataQuery query) tm1.GetPartition(Begin=b,End=e): a rectangle of cells, streamed. Needs schema 10.2.2.3.TM1 (11.8) reads
BeginandEndas the top-left and bottom-right cells of a rectangle on the first two axes, not as a range of ordinals: with two columns,partition(id, 2, 4, …)is column 0 of rows 1 and 2, cells 2 and 4, not 3. A run of whole rows, from a row's first cell to a row's last, is a range.- Parameters:
id- the cellset's IDbegin- the ordinal of the rectangle's top-left cellend- the ordinal of its bottom-right cellquery- what to select of each cell; across pages, keep it the same- Returns:
- the cells in the rectangle
-
update
@Tm1Endpoint("Action Cellset/Update") public reactor.core.publisher.Mono<Void> update(String id, long ordinal, @Nullable Object value) tm1.Update: writes one value to a cell of the cellset, by ordinal. The action takes a range (BeginOrdinal,EndOrdinal), but TM1 (11.8) writes only the first cell of it, so this takes one ordinal;updateCells(String, List)writes many.- Parameters:
id- the cellset's IDordinal- the cell's ordinalvalue- the value, ornullto clear the cell- Returns:
- completes when it's written
-
updateCells
@Tm1Endpoint("Action Cellset/UpdateCells") @Tm1Endpoint("Navigation CellsetUpdate/ReferenceCube") @Tm1Endpoint("Navigation CellsetUpdate/ReferenceCell") public reactor.core.publisher.Mono<Void> updateCells(String id, List<CellsetUpdatePatch> updates) tm1.UpdateCells: writes many of the cellset's cells, each its own value, by ordinal. Needs schema 11.0.0.- Parameters:
id- the cellset's IDupdates- the writes:CellsetUpdatePatch.builder().ordinal(n).value(v), or with a reference cube and cell to copy from- Returns:
- completes when they're written
-
saveViewAs
@Tm1Endpoint("Action Cellset/SaveViewAs") public reactor.core.publisher.Mono<View> saveViewAs(String id, String name) tm1.SaveViewAs: saves the cellset's query as a public view of its cube, failing if one has the name. Needs schema 11.0.0.- Parameters:
id- the cellset's IDname- the view's name- Returns:
- the view
-
saveViewAs
@Tm1Endpoint("Action Cellset/SaveViewAs") public reactor.core.publisher.Mono<View> saveViewAs(String id, String name, boolean overwrite, boolean makePrivate) tm1.SaveViewAs: saves the cellset's query as a view of its cube. Needs schema 11.0.0.- Parameters:
id- the cellset's IDname- the view's nameoverwrite- whether to replace a view that has the namemakePrivate- whether the view is private- Returns:
- the view
-
stream
@Tm1Endpoint("ActionImport ExecuteMDX") @Tm1Endpoint("Function Cellset/GetPartition") @Tm1Endpoint("EntitySet Cellsets") public <R> reactor.core.publisher.Flux<R> stream(String mdx, ODataQuery cellQuery, int pageSize, BiFunction<Cellset, reactor.core.publisher.Flux<CellsetCell>, org.reactivestreams.Publisher<R>> handler) Runs an MDX query and streams its cells tohandler, then deletes the cellset: when the result completes, fails, or is cancelled.One round trip brings the axes (hierarchies by name, tuples with their members' names and unique names) and the first
pageSizecells; the rest come in pages ofGetPartition, a few at a time and in ordinal order, so memory stays bounded on both sides however large the cellset.String mdx = """ SELECT {[Month].[Month].[Jan], [Month].[Month].[Feb], [Month].[Month].[Mar]} ON 0, {TM1FILTERBYLEVEL({TM1SUBSETALL([Region].[Region])}, 0)} ON 1 FROM [Sales] WHERE ([Version].[Version].[Actual], [Measure].[Measure].[Revenue])"""; return tm1.cellsets() .stream(mdx, ODataQuery.none().select(CellsetCell.ORDINAL, CellsetCell.VALUE), 10_000, (cellset, cells) -> { // Axis 0 is the columns, axis 1 the rows; ordinals run along a row List<CellsetAxisTuple> columns = cellset.axes().get(0).tuples(); List<CellsetAxisTuple> rows = cellset.axes().get(1).tuples(); return cells.map(cell -> { CellsetAxisTuple row = rows.get((int) (cell.ordinal() / columns.size())); CellsetAxisTuple column = columns.get((int) (cell.ordinal() % columns.size())); return row.members().get(0).name() + ", " + column.members().get(0).name() + ": " + cell.value(); }); });- Type Parameters:
R- what the handler gives- Parameters:
mdx- the querycellQuery- what to select of each cell; includeOrdinalto place thempageSize- how many cells to fetch per requesthandler- given the cellset (itsIDand expandedAxes) and its cells, in ordinal order; its result is this method's- Returns:
- what the handler gives, with the cellset deleted at the end
-