Skip to content

Blob-based cube data transfer (#1515) - #1516

Open
nicolasbisurgi wants to merge 9 commits into
cubewise-code:masterfrom
nicolasbisurgi:1515-blob-data-transfer
Open

nicolasbisurgi wants to merge 9 commits into
cubewise-code:masterfrom
nicolasbisurgi:1515-blob-data-transfer

Conversation

@nicolasbisurgi

@nicolasbisurgi nicolasbisurgi commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1515

Summary

Copy cube data between cubes or instances through the file store, without the cells passing through Python. Three single-purpose functions do the work; the caller chains them.

source.cells.export_to_blob(mdx | mdx string | cube + view)   -> file name
  generated TI builds a temporary view in its prolog, writes one line per cell
  (one column per cube dimension in cube order, then the value)
target.files.transfer_from(source.files, file_name)           -> bytes sent
  streamed in chunks, client memory flat; v11 <-> v12 in any direction
  an expired target session (401) is retried once with a new source stream
target.cells.load_from_blob(file_name, cube_name=... | process_name=...)
  generated TI load, or your own process with the file name in pFileName

For large copies, split_mdx divides a query into even slices by one dimension, so the chain can run per slice in parallel.

export_to_blob and load_from_blob require data admin and ops admin, like the other methods that run unbound TI. Every public function with use_blob takes lean_ti=False, including write_async and write_dataframe_async.

 TM1py/
 ├── Utils/
+│   ├── BlobProcessBuilder.py   # generates export/load TI (legacy and lean modes)
 │   └── Utils.py                # + escape_mdx_name, unescape_mdx_name, build_hierarchy_unique_name,
 │                               #   split_hierarchy_unique_name, is_streamed_body
 ├── Services/
 │   ├── CellService.py          # + export_to_blob, load_from_blob, split_mdx
 │   │                           #   use_blob paths now built by BlobProcessBuilder (legacy mode)
 │   ├── FileService.py          # + get_size, get_stream, transfer_from, ti_file_name
 │   └── RestService.py          # + stream=True on requests
 ├── Objects/
 │   └── NativeView.py           # + from_mdx_builder
 └── Exceptions/
+    ├── TM1pyExportFailureException (also a RuntimeError)
+    └── TM1pyFileTransferException
+CONTEXT.md                      # glossary: blob, lean TI, slice, atomic function, orchestrator

load_from_blob with process_name raises ValueError if a cube-only option is passed (increment, skip_non_updateable, allow_spread, sandbox_name, clear_view, deactivate_transaction_log, dimensions) instead of ignoring it. The generated load expects a file without a header line; a header (include_header=True) is for your own process.

Server behaviour found along the way (all handled):

  • Alternate hierarchies can't be placed in a native view from TI, so those exports fall back to an MDX view.
  • A TI MDX view turns DIMENSION PROPERTIES into extra variables; the generated MDX leaves them out.
  • On v11 a file must exist (created through REST) before TI writes it, or the file API doesn't list it.

Evidence

Live tests run at eaacc28 against a v11 on-prem instance, a v12 SaaS instance and a v11 PAoC instance:

Suite v11 on-prem v12 SaaS v11 PAoC
TI builder, view in prolog, split_mdx (CellService_blob_ti_test) 52 OK 52 OK 52 OK
Streaming (FileService_stream_test) 18 OK 17 OK, 1 skipped (v11 only) 18 OK
Export / load (CellService_blob_transfer_test) 24 OK 23 OK, 1 skipped (v11 only) 24 OK
Existing use_blob tests (Cell, Element, PowerBi services) 66 OK 66 OK 66 OK

Cross-instance round trips (export → transfer → load, both directions) pass for all three pairs. Single-stream, cleared-target, developer-process and parallel-slice chains also pass between each pair.

After the review fixes (a350085, 99c366d), rerun on the v11 instance, with the cross-instance cases against the other two:

  • Blob suites (CellService_blob_ti_test, FileService_stream_test, CellService_blob_transfer_test, NativeView_from_mdx_builder_test): 102 OK. New tests cover no temporary subsets or processes left, an attribute-cube round trip, the process_name option check, and the transfer retry after a 401.
  • Blob tests in the Cell, Element and PowerBi services: 69 OK. Async writers: 31 OK.

Existing use_blob reads are unchanged: the generated TI is compared against snapshots of the previous code (Tests/fixtures/blob_ti_snapshots/).

before: file name -> RuntimeError("Failed writing to blob with TI. ...")
after:  same message, raised as TM1pyExportFailureException (subclass of RuntimeError)

Merge Danger

Door: two-way

New functions are additive; the refactored use_blob paths generate the same TI as before (snapshot tests).

Blast Radius: moderate

  • RestService.request treats an iterable body (not str/bytes/dict/list) as a streamed upload: sent synchronously, uncompressed, not retried.
  • FileService.create/update on v11 without multipart upload raise ValueError for an iterable body with no content_length (v11 rejects chunked uploads).
  • The use_blob read paths check that sandbox_name exists before creating any file, and raise ValueError for an unknown sandbox instead of a failed TI process.
  • Code catching RuntimeError from use_blob still catches the new exception.

Suggested label: release:minor.

🤖 Generated with Claude Code

nicolasbisurgi and others added 4 commits November 17, 2026 11:21
)

Move the TI generation for use_blob reads and writes out of CellService
into TM1py/Utils/BlobProcessBuilder.py. Legacy mode reproduces today's
generated TI exactly (pinned by snapshot tests recorded before the
refactor). Lean mode, opt-in via lean_ti=True, only emits the code a
cube needs: string-measure handling, quote escaping for dimensions with
quoted element names, top/skip counters and alias lookups. UTF-8 output
and the header line are set on the first data record.

lean_ti defaults to False on write, write_dataframe, execute_mdx_csv,
execute_view_csv and the execute_*_dataframe* variants, so default
behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wise-code#1515)

RestService: GET takes stream=True and returns the unread response; a
PUT/POST with an iterable body is detected automatically. Streamed
requests always run in sync mode (async mode only returns a complete
body) and are never compressed or retried (an iterable body can only be
sent once). A 401 still reconnects the session.

FileService: new get_size (from the document metadata, since v11 sends
large downloads without a length), get_stream (context-managed chunked
download), ti_file_name, and transfer_from, called on the target, which
streams a file from another instance, drops a leading UTF-8 BOM,
optionally removes the source and returns the bytes sent. create,
update and update_or_create accept an iterable of bytes: on v11 as one
sized upload (content_length), on v12 through multipart upload fed one
part at a time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ubewise-code#1515)

NativeView.from_mdx_builder describes an MdxBuilder as a native view:
each set on axis 0/1 becomes a column/row anonymous subset (static for a
member list, otherwise the set's MDX expression), single WHERE members
become titles. It raises NotImplementedError for what a native view
built in TI can't express (tuples, calculated members, more than two
axes, non-hierarchy sets, a dimension used twice, alternate
hierarchies), so callers can fall back to an MDX view.

BlobProcessBuilder (lean mode) can build the export's data source view
in the prolog as temporary objects, from a NativeView (one subset per
cube dimension, default member for dimensions the view doesn't mention)
or from an MDX string (ViewCreateByMDX). Long MDX is assigned in
pieces. Nothing is left on the server whether the process succeeds or
fails.

CellService.split_mdx resolves one dimension's set on the server and
returns one MdxBuilder per slice, as even as possible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ubewise-code#1515)

export_to_blob writes the cells of an MdxBuilder, an MDX string or an
existing public view to a file in the file store with a lean TI process
and returns the file name. The view is built inside the process as a
temporary object: a native view for an MdxBuilder when possible,
otherwise an MDX view (written without DIMENSION PROPERTIES). The file
has one column per cube dimension in cube order, WHERE and unmentioned
dimensions included, so a cube-to-cube load always receives every
dimension. Options: skip flags (rule-derived cells skipped by default),
header line, aliases with blank-alias fallback, sandbox. Unknown alias
dimensions or attributes raise ValueError before anything runs; a
failed export removes its file and raises TM1pyExportFailureException.

load_from_blob loads such a file into a cube with a lean generated
process (increment, skip non-updateable, allow spread, sandbox, clear
view, optional transaction log switch-off on v11 restored even when the
load fails) or runs a developer's process with the file name in
pFileName (or another parameter) plus its own parameters. Failures
raise the same exceptions as write_through_blob; the file is removed
after a successful load and kept after a failed one.

TM1pyExportFailureException subclasses TM1pyException and RuntimeError.
The existing use_blob read paths raise it instead of a plain
RuntimeError, with the same message, so existing handlers still catch it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nicolasbisurgi nicolasbisurgi self-assigned this Nov 17, 2026
@nicolasbisurgi nicolasbisurgi added the release:minor Triggers major version bump (e.g.: 1.4.1 → 1.5.0) label Nov 17, 2026
…g helpers (cubewise-code#1515)

- export_to_blob and load_from_blob require ops admin and v11.4, like the other unbound-TI methods
- load_from_blob switches the transaction log with the existing helpers, only when it is on
- transfer_from raises TM1pyFileTransferException instead of a bare RuntimeError
- MDX name escaping and hierarchy unique names live in Utils, used by CellService, BlobProcessBuilder and NativeView
- is_streamed_body is a public Utils function instead of a private RestService method
- sandbox existence is checked once per call, outside the export builder
- BlobProcessBuilder reuses Element.ELEMENT_ATTRIBUTES_PREFIX and drops pass-through helpers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nicolasbisurgi and others added 3 commits November 17, 2026 19:54
…ubewise-code#1515)

- load_from_blob raises ValueError for cube-only options passed with process_name, and passes timeout and
  cancel_at_timeout to the developer process
- load_from_blob documents that the generated load takes no header line
- transfer_from runs the copy once more, with a new source stream, when the target's session expired (401)
- write_async and write_dataframe_async take lean_ti
- tests: no temporary subsets or processes left, attribute-cube round trip, process_name option checks,
  transfer retry after 401
- CONTEXT.md: glossary entries for blob data transfer

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…bewise-code#1515)

- Run sandbox check and cube profile lookup before creating the temporary view
- load_from_blob: add reactivate_transaction_log, deactivate_transaction_log
  no longer restores logging on its own (same as write)
- transfer_from: reject same source and target file, remove incomplete target
  on byte mismatch
- export_to_blob: raise when a dimension is on several axis positions
- Escape the sandbox name in generated TI
- Add numeric-only cube integration tests for the lean load
@MariusWirtz

Copy link
Copy Markdown
Collaborator

This is looking good. We can merge when Integration Tests complete

@github-actions

Copy link
Copy Markdown
Contributor

Tests completed for environment: tm1-11-cloud. Check artifacts for details.

…e#1515)

transfer_from now raises TM1pyFileTransferException while sending, as soon
as the source stream ends short of or runs past its size, and removes the
incomplete target on that error. Before, a short stream (e.g. a dropped
source connection) left a v11 sized upload waiting for bytes that never
came, which with no timeout never returned.

Docs: RestService retry behaviour for streamed requests, CONTEXT.md lean TI
and failure behaviour, NativeView/BlobProcessBuilder/CellService comments,
missing :raises: entries, NON EMPTY note on export_to_blob, kwargs passed
with process_name.

Test: a non-numeric value in a numeric lean load rejects its row and keeps
the existing cell, where legacy writes 0 over it; the test now asserts that
instead of identical results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:minor Triggers major version bump (e.g.: 1.4.1 → 1.5.0)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blob-based cube data transfer between instances

3 participants