skipcheck

TM1 client · Docs · Reading and writing data

CellsetService

import { CellsetService } from "@skipcheck/tm1-client";

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:

const 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])`;
const values = ODataQuery.none().select(CellsetCell.Fields.Ordinal, CellsetCell.Fields.Value);
return tm1.cellsets.stream(mdx, values, 10_000, (cellset, cells) => {
  // Axis 0 is the columns, axis 1 the rows; ordinals run along a row
  const columns = cellset.Axes?.[0]?.Tuples ?? [];
  const rows = cellset.Axes?.[1]?.Tuples ?? [];
  return cells.map((cell) => {
    const ordinal = cell.Ordinal ?? 0;
    const row = rows[Math.floor(ordinal / columns.length)];
    const column = columns[ordinal % columns.length];
    return `${row?.Members?.[0]?.Name}, ${column?.Members?.[0]?.Name}: ${String(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
const mdx =
  "SELECT {[Month].[Month].[Jan], [Month].[Month].[Feb]} ON 0, {[Region].[Region].[North]} ON 1" +
  " FROM [Sales] WHERE ([Version].[Version].[Budget], [Measure].[Measure].[Revenue])";
const cellset = await tm1.cellsets.execute(mdx);
try {
  await tm1.cellsets.updateCells(cellset.ID!, [
    CellsetUpdatePatch.builder().ordinal(0).value(1200).build(),
    CellsetUpdatePatch.builder().ordinal(1).value(1350).build(),
  ]);
} finally {
  await tm1.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
const withValues = ODataQuery.none().expand(Cellset.Fields.Cells, (cells) => cells.select(CellsetCell.Fields.Value));
const cellset = await tm1.cellsets.executeView("Sales", ViewScope.Public, "Revenue by Region", withValues);
try {
  return (cellset.Cells ?? []).map((cell) => cell.Value);
} finally {
  await tm1.cellsets.delete(cellset.ID!);
}

Members

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.
getThe cellset, or a Tm1NotFoundException if it's gone.
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.
cubeThe cube the cellset is from.
partitionA rectangle of cells, streamed.
updateWrites one value to a cell of the cellset, by ordinal; null clears the cell.
updateCellsWrites many of the cellset's cells, each its own value, by ordinal.
saveViewAsSaves the cellset's query as a view of its cube.
saveViewAstm1.SaveViewAs, choosing whether to replace a view that has the name (overwrite) and whether the view is private (makePrivate).
saveViewAs
streamRuns an MDX query and streams its cells to handler, then deletes the cellset.

execute

execute(mdx: string, query?: ODataQuery | null, options?: Tm1CallOptions): Promise<Cellset>

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. The cellset has its ID.

TM1 REST ActionImport ExecuteMDX

executeStatement

executeStatement(mdx: string, options?: Tm1CallOptions): Promise<void>

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

executeView

executeView(cube: string, scope: ViewScope, view: string, query?: ODataQuery | null, options?: Tm1CallOptions): Promise<Cellset>

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

TM1 REST Action NativeView/Execute Action MDXView/Execute

list

list(query?: ODataQuery | null, options?: Tm1CallOptions): Tm1Stream<Cellset>

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.

TM1 REST EntitySet Cellsets

get

get(id: string, query?: ODataQuery | null, options?: Tm1CallOptions): Promise<Cellset>

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

TM1 REST EntitySet Cellsets

delete

delete(id: string, options?: Tm1CallOptions): Promise<void>

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

TM1 REST EntitySet Cellsets

axes

axes(id: string, query?: ODataQuery | null, options?: Tm1CallOptions): Tm1Stream<CellsetAxis>

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. Expand Tuples($expand=Members) for the members.

TM1 REST Navigation Cellset/Axes

hierarchies

hierarchies(id: string, axis: number, query?: ODataQuery | null, options?: Tm1CallOptions): Tm1Stream<Hierarchy>

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

TM1 REST Navigation CellsetAxis/Hierarchies

tuples

tuples(id: string, axis: number, query?: ODataQuery | null, options?: Tm1CallOptions): Tm1Stream<CellsetAxisTuple>

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

TM1 REST Navigation CellsetAxis/Tuples

tupleMembers

tupleMembers(id: string, axis: number, tuple: number, query?: ODataQuery | null, options?: Tm1CallOptions): Tm1Stream<Member>

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

TM1 REST Navigation CellsetAxisTuple/Members

cells

cells(id: string, query?: ODataQuery | null, options?: Tm1CallOptions): Tm1Stream<CellsetCell>

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

TM1 REST Navigation Cellset/Cells

cellMembers

cellMembers(id: string, ordinal: number, query?: ODataQuery | null, options?: Tm1CallOptions): Tm1Stream<Member>

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

cube

cube(id: string, query?: ODataQuery | null, options?: Tm1CallOptions): Promise<Cube>

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

TM1 REST Navigation Cellset/Cube

partition

partition(id: string, begin: number, end: number, query?: ODataQuery | null, options?: Tm1CallOptions): Tm1Stream<CellsetCell>

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. Across pages, keep query the same.

TM1 REST Function Cellset/GetPartition

update

update(id: string, ordinal: number, value: unknown, options?: Tm1CallOptions): Promise<void>

tm1.Update: writes one value to a cell of the cellset, by ordinal; null clears the cell. 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.

TM1 REST Action Cellset/Update

updateCells

updateCells(id: string, updates: readonly CellsetUpdatePatch[], options?: Tm1CallOptions): Promise<void>

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

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

saveViewAs

saveViewAs(id: string, name: string, options?: Tm1CallOptions): Promise<View>

tm1.SaveViewAs: saves the cellset's query as a view of its cube: public, failing if one has the name; or with overwrite (replacing a view that has the name) and makePrivate. Needs schema 11.0.0.

TM1 REST Action Cellset/SaveViewAs

saveViewAs

saveViewAs(id: string, name: string, overwrite: boolean, makePrivate: boolean, options?: Tm1CallOptions): Promise<View>

tm1.SaveViewAs, choosing whether to replace a view that has the name (overwrite) and whether the view is private (makePrivate).

TM1 REST Action Cellset/SaveViewAs

saveViewAs

saveViewAs(id: string, name: string, overwrite?: boolean | Tm1CallOptions, makePrivate?: boolean, options?: Tm1CallOptions): Promise<View>

TM1 REST Action Cellset/SaveViewAs

stream

stream<R>( mdx: string, query: ODataQuery, pageSize: number, handler: (cellset: Cellset, cells: Tm1Stream<CellsetCell>) => Tm1Work<R>, options?: Tm1CallOptions, ): Tm1Stream<R>

Runs an MDX query and streams its cells to handler, then deletes the cellset: when the iteration completes, fails, or is abandoned (a break, an abort).

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, as the cells are iterated, so memory stays bounded on both sides however large the cellset.

query selects what of each cell (include Ordinal to place them); handler is given the cellset (its ID and expanded Axes) and its cells, in ordinal order, and what it gives (a stream, or a promise of one value) is what this streams. Nothing is sent until it's iterated.

const 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])`;
const values = ODataQuery.none().select(CellsetCell.Fields.Ordinal, CellsetCell.Fields.Value);
return tm1.cellsets.stream(mdx, values, 10_000, (cellset, cells) => {
  // Axis 0 is the columns, axis 1 the rows; ordinals run along a row
  const columns = cellset.Axes?.[0]?.Tuples ?? [];
  const rows = cellset.Axes?.[1]?.Tuples ?? [];
  return cells.map((cell) => {
    const ordinal = cell.Ordinal ?? 0;
    const row = rows[Math.floor(ordinal / columns.length)];
    const column = columns[ordinal % columns.length];
    return `${row?.Members?.[0]?.Name}, ${column?.Members?.[0]?.Name}: ${String(cell.Value)}`;
  });
});

TM1 REST ActionImport ExecuteMDX Function Cellset/GetPartition EntitySet Cellsets