skipcheck

TM1 client · Docs · Reading and writing data

CellsetService

using Skipcheck.Tm1.Client.Services;

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 (ExecuteAsync, CellsAsync, PartitionAsync, DeleteAsync) leave that to the caller. StreamAsync 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:

var 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.StreamAsync(mdx, ODataQuery.None().Select(CellsetCell.Fields.Ordinal, CellsetCell.Fields.Value), 10_000, (cellset, cells) =>
{
    // Axis 0 is the columns, axis 1 the rows; ordinals run along a row
    var columns = cellset.Axes![0].Tuples!;
    var rows = cellset.Axes[1].Tuples!;
    return cells.Select(cell =>
    {
        var row = rows[(int)(cell.Ordinal!.Value / columns.Count)];
        var column = columns[(int)(cell.Ordinal.Value % columns.Count)];
        return $"{row.Members![0].Name}, {column.Members![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
var cellsets = tm1.Cellsets;
var mdx =
    "SELECT {[Month].[Month].[Jan], [Month].[Month].[Feb]} ON 0, {[Region].[Region].[North]} ON 1"
    + " FROM [Sales] WHERE ([Version].[Version].[Budget], [Measure].[Measure].[Revenue])";
var cellset = await cellsets.ExecuteAsync(mdx);
try
{
    await cellsets.UpdateCellsAsync(
        cellset.Id!,
        [CellsetUpdatePatch.Builder().Ordinal(0).Value(1200).Build(), CellsetUpdatePatch.Builder().Ordinal(1).Value(1350).Build()]
    );
}
finally
{
    await cellsets.DeleteAsync(cellset.Id!);
}

Read the values of a saved view:

// The values of a saved view, read in the same round trip as its cellset
var cellsets = tm1.Cellsets;
var cellset = await cellsets.ExecuteViewAsync(
    "Sales",
    ViewScope.Public,
    "Revenue by Region",
    ODataQuery.None().Expand(Cellset.Fields.Cells, cells => cells.Select(CellsetCell.Fields.Value))
);
try
{
    return cellset.Cells!.Select(cell => cell.Value).ToList();
}
finally
{
    await cellsets.DeleteAsync(cellset.Id!);
}

Members

CellsetService constructorA service that sends its requests through session.
ExecuteAsyncRuns an MDX query, leaving its cellset on the server until DeleteAsync.
ExecuteStatementAsyncRuns an MDX statement for its effect, keeping no cellset.
ExecuteViewAsynctm1.Execute on a native or MDX view.
ListAsyncGET Cellsets, streamed.
GetAsyncThe cellset, or a Tm1NotFoundException if it's gone.
DeleteAsyncFrees the cellset's memory on the server.
AxesAsyncGET Cellsets('id')/Axes, streamed.
HierarchiesAsyncGET Cellsets('id')/Axes(n)/Hierarchies, streamed.
TuplesAsyncGET Cellsets('id')/Axes(n)/Tuples, streamed, in order.
TupleMembersAsyncGET Cellsets('id')/Axes(n)/Tuples(t)/Members, streamed.
CellsAsyncGET Cellsets('id')/Cells, streamed, in ordinal order.
CellMembersAsyncGET Cellsets('id')/Cells(n)/Members, streamed.
CubeAsyncThe cube the cellset is from.
PartitionAsyncA rectangle of cells, streamed.
UpdateAsyncWrites one value to a cell of the cellset, by ordinal.
UpdateCellsAsyncWrites many of the cellset's cells, each its own value, by ordinal.
SaveViewAsAsyncSaves the cellset's query as a public view of its cube, failing if one has the name.
SaveViewAsAsyncSaves the cellset's query as a view of its cube, replacing one that has the name if overwrite, private if makePrivate.
StreamAsyncRuns an MDX query and streams its cells to handler, then deletes the cellset, however the enumeration ends.

CellsetService

constructor
CellsetService(Tm1Session session)

A service that sends its requests through session.

ExecuteAsync

Task<Cellset> ExecuteAsync(string mdx, ODataQuery? query = null, CancellationToken cancellationToken = default)

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

TM1 REST ActionImport ExecuteMDX

ExecuteStatementAsync

Task ExecuteStatementAsync(string mdx, CancellationToken cancellationToken = default)

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).

TM1 REST ActionImport ExecuteMDXStatement

ExecuteViewAsync

Task<Cellset> ExecuteViewAsync(string cube, ViewScope scope, string view, ODataQuery? query = null, CancellationToken cancellationToken = default)

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

TM1 REST Action NativeView/Execute Action MDXView/Execute

ListAsync

IAsyncEnumerable<Cellset> ListAsync(ODataQuery? query = null, CancellationToken cancellationToken = default)

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

TM1 REST EntitySet Cellsets

GetAsync

Task<Cellset> GetAsync(string id, ODataQuery? query = null, CancellationToken cancellationToken = default)

GET Cellsets('id'): the cellset, or a Tm1NotFoundException if it's gone.

TM1 REST EntitySet Cellsets

DeleteAsync

Task DeleteAsync(string id, CancellationToken cancellationToken = default)

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

TM1 REST EntitySet Cellsets

AxesAsync

IAsyncEnumerable<CellsetAxis> AxesAsync(string id, ODataQuery? query = null, CancellationToken cancellationToken = default)

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.

TM1 REST Navigation Cellset/Axes

HierarchiesAsync

IAsyncEnumerable<Hierarchy> HierarchiesAsync(string id, int axis, ODataQuery? query = null, CancellationToken cancellationToken = default)

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

TM1 REST Navigation CellsetAxis/Hierarchies

TuplesAsync

IAsyncEnumerable<CellsetAxisTuple> TuplesAsync(string id, int axis, ODataQuery? query = null, CancellationToken cancellationToken = default)

GET Cellsets('id')/Axes(n)/Tuples, streamed, in order: an axis can be large.

TM1 REST Navigation CellsetAxis/Tuples

TupleMembersAsync

IAsyncEnumerable<Member> TupleMembersAsync( string id, int axis, int tuple, ODataQuery? query = null, CancellationToken cancellationToken = default )

GET Cellsets('id')/Axes(n)/Tuples(t)/Members, streamed: one member per hierarchy on the axis.

TM1 REST Navigation CellsetAxisTuple/Members

CellsAsync

IAsyncEnumerable<CellsetCell> CellsAsync(string id, ODataQuery? query = null, CancellationToken cancellationToken = default)

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

TM1 REST Navigation Cellset/Cells

CellMembersAsync

IAsyncEnumerable<Member> CellMembersAsync(string id, long ordinal, ODataQuery? query = null, CancellationToken cancellationToken = default)

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.

TM1 REST Navigation CellsetCell/Members

CubeAsync

Task<Cube> CubeAsync(string id, ODataQuery? query = null, CancellationToken cancellationToken = default)

GET Cellsets('id')/Cube: the cube the cellset is from.

TM1 REST Navigation Cellset/Cube

PartitionAsync

IAsyncEnumerable<CellsetCell> PartitionAsync( string id, long begin, long end, ODataQuery? query = null, CancellationToken cancellationToken = default )

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, PartitionAsync(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.

query selects what of each cell; across pages, keep it the same.

TM1 REST Function Cellset/GetPartition

UpdateAsync

Task UpdateAsync(string id, long ordinal, object? value, CancellationToken cancellationToken = default)

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; UpdateCellsAsync writes many. A null value clears the cell.

TM1 REST Action Cellset/Update

UpdateCellsAsync

Task UpdateCellsAsync(string id, IReadOnlyList<CellsetUpdatePatch> updates, CancellationToken cancellationToken = default)

tm1.UpdateCells: writes many of the cellset's cells, each its own value, by ordinal. Needs schema 11.0.0. Each of updates is CellsetUpdatePatch.Builder().Ordinal(n).Value(v), or with a reference cube and cell to copy from.

TM1 REST Action Cellset/UpdateCells Navigation CellsetUpdate/ReferenceCube Navigation CellsetUpdate/ReferenceCell

SaveViewAsAsync

Task<View> SaveViewAsAsync(string id, string name, CancellationToken cancellationToken = default)

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.

TM1 REST Action Cellset/SaveViewAs

SaveViewAsAsync

Task<View> SaveViewAsAsync(string id, string name, bool overwrite, bool makePrivate, CancellationToken cancellationToken = default)

tm1.SaveViewAs: saves the cellset's query as a view of its cube, replacing one that has the name if overwrite, private if makePrivate. Needs schema 11.0.0.

TM1 REST Action Cellset/SaveViewAs

StreamAsync

IAsyncEnumerable<R> StreamAsync<R>( string mdx, ODataQuery cellQuery, int pageSize, Func<Cellset, IAsyncEnumerable<CellsetCell>, IAsyncEnumerable<R>> handler, CancellationToken cancellationToken = default )

Runs an MDX query and streams its cells to handler, then deletes the cellset, however the enumeration ends: completed, failed, cancelled or abandoned.

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.

var 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.StreamAsync(mdx, ODataQuery.None().Select(CellsetCell.Fields.Ordinal, CellsetCell.Fields.Value), 10_000, (cellset, cells) =>
{
    // Axis 0 is the columns, axis 1 the rows; ordinals run along a row
    var columns = cellset.Axes![0].Tuples!;
    var rows = cellset.Axes[1].Tuples!;
    return cells.Select(cell =>
    {
        var row = rows[(int)(cell.Ordinal!.Value / columns.Count)];
        var column = columns[(int)(cell.Ordinal.Value % columns.Count)];
        return $"{row.Members![0].Name}, {column.Members![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.

TM1 REST ActionImport ExecuteMDX Function Cellset/GetPartition EntitySet Cellsets