skipcheck

TM1 client · Docs · Reading and writing data

CellsetService

import io.skipcheck.tm1.client.service.data.CellsetService;

Used in the walkthroughs Read and write cells, Run a process and read its result.

Cellsets: the server-side results of an MDX query or a view, with their axes and cells.

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, cells, partition, delete) leave that to the caller. stream 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()));

Members

CellsetService constructorA service sending its requests through session.
executeRuns an MDX query, leaving its cellset on the server until delete.
executeStatementRuns an MDX statement for its effect, keeping no cellset.
executeViewtm1.Execute on a native or MDX view.
listGET Cellsets, streamed.
getGET Cellsets('id').
deleteFrees the cellset's memory on the server.
axesGET Cellsets('id')/Axes, streamed.
hierarchiesGET Cellsets('id')/Axes(n)/Hierarchies, streamed.
tuplesGET Cellsets('id')/Axes(n)/Tuples, streamed, in order.
tupleMembersGET Cellsets('id')/Axes(n)/Tuples(t)/Members, streamed.
cellsGET Cellsets('id')/Cells, streamed, in ordinal order.
cellMembersGET Cellsets('id')/Cells(n)/Members, streamed.
cubeGET Cellsets('id')/Cube.
partitionA rectangle of cells, streamed.
updateWrites one value to a cell of the cellset, by ordinal.
updateCellsWrites many of the cellset's cells, each its own value, by ordinal.
saveViewAsSaves the cellset's query as a public view of its cube, failing if one has the name.
saveViewAsSaves the cellset's query as a view of its cube.
streamRuns an MDX query and streams its cells to handler, then deletes the cellset.

CellsetService

constructor
CellsetService(Tm1Session session)

A service sending its requests through session.

Parameters

session
the session

execute

Mono<Cellset> execute(String mdx, ODataQuery query)

ExecuteMDX: runs an MDX query, leaving its cellset on the server until delete. Expand Axes and Cells (with $top and $select) to get them in the same round trip.

Parameters

mdx
the query
query
what to expand of the cellset

Returns

the cellset, with its ID

TM1 REST ActionImport ExecuteMDX

executeStatement

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 a SELECT and returns nothing, and rejects CREATE SET as a syntax error (code 501).

Parameters

mdx
the statement

Returns

completes when it's run

TM1 REST ActionImport ExecuteMDXStatement

executeView

Mono<Cellset> executeView(String cube, ViewScope scope, String view, ODataQuery query)

tm1.Execute on a native or MDX view: its cellset, left on the server until delete.

Parameters

cube
the cube's name
scope
where the view is
view
the view's name
query
what to expand of the cellset

Returns

the cellset, with its ID

list

Flux<Cellset> list(ODataQuery query)

GET Cellsets, streamed. TM1 (11.8) lists none, though each cellset reads by its ID with get: keep the IDs of the cellsets you create.

Parameters

query
what to select and expand

Returns

the cellsets

TM1 REST EntitySet Cellsets

get

Mono<Cellset> get(String id, ODataQuery query)

GET Cellsets('id').

Parameters

id
the cellset's ID
query
what to expand

Returns

the cellset, or a Tm1NotFoundException if it's gone

TM1 REST EntitySet Cellsets

delete

Mono<Void> delete(String id)

DELETE Cellsets('id'): frees the cellset's memory on the server.

Parameters

id
the cellset's ID

Returns

completes when it's deleted

TM1 REST EntitySet Cellsets

axes

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 a WHERE: it holds the cube's other dimensions, such as its virtual Sandboxes, with cardinality 1.

Parameters

id
the cellset's ID
query
what to expand, such as Tuples($expand=Members)

Returns

the axes

TM1 REST Navigation Cellset/Axes

hierarchies

Flux<Hierarchy> hierarchies(String id, int axis, ODataQuery query)

GET Cellsets('id')/Axes(n)/Hierarchies, streamed.

Parameters

id
the cellset's ID
axis
the axis ordinal
query
what to select

Returns

the hierarchies on the axis

TM1 REST Navigation CellsetAxis/Hierarchies

tuples

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 ID
axis
the axis ordinal
query
what to expand, such as Members($select=Name)

Returns

the axis's tuples

TM1 REST Navigation CellsetAxis/Tuples

tupleMembers

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 ID
axis
the axis ordinal
tuple
the tuple ordinal
query
what to select

Returns

the tuple's members

TM1 REST Navigation CellsetAxisTuple/Members

cells

Flux<CellsetCell> cells(String id, ODataQuery query)

GET Cellsets('id')/Cells, streamed, in ordinal order. Use $top and $skip, or partition, for pages.

Parameters

id
the cellset's ID
query
what to select of each cell (Ordinal, Value, …)

Returns

the cells

TM1 REST Navigation Cellset/Cells

cellMembers

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 virtual Sandboxes dimension's, Base, first.

Parameters

id
the cellset's ID
ordinal
the cell's ordinal
query
what to select

Returns

the cell's members

TM1 REST Navigation CellsetCell/Members

cube

Mono<Cube> cube(String id, ODataQuery query)

GET Cellsets('id')/Cube.

Parameters

id
the cellset's ID
query
what to select and expand

Returns

the cube the cellset is from

TM1 REST Navigation Cellset/Cube

partition

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 Begin and End as 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 ID
begin
the ordinal of the rectangle's top-left cell
end
the ordinal of its bottom-right cell
query
what to select of each cell; across pages, keep it the same

Returns

the cells in the rectangle

TM1 REST Function Cellset/GetPartition

update

Mono<Void> update(String id, long ordinal, 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 writes many.

Parameters

id
the cellset's ID
ordinal
the cell's ordinal
value
the value, or null to clear the cell

Returns

completes when it's written

TM1 REST Action Cellset/Update

updateCells

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 ID
updates
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

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 ID
name
the view's name

Returns

the view

TM1 REST Action Cellset/SaveViewAs

saveViewAs

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 ID
name
the view's name
overwrite
whether to replace a view that has the name
makePrivate
whether the view is private

Returns

the view

TM1 REST Action Cellset/SaveViewAs

stream

<R> Flux<R> stream(String mdx, ODataQuery cellQuery, int pageSize, BiFunction<Cellset,Flux<CellsetCell>,Publisher<R>> handler)

Runs an MDX query and streams its cells to handler, 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 pageSize cells; the rest come in pages of GetPartition, 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();
        });
    });

Parameters

mdx
the query
cellQuery
what to select of each cell; include Ordinal to place them
pageSize
how many cells to fetch per request
handler
given the cellset (its ID and expanded Axes) and its cells, in ordinal order; its result is this method's

Returns

what the handler gives, with the cellset deleted at the end

Also in the Javadoc.