Skip to content

Add blob-based add_elements / add_edges for symmetric dimension blob support#1423

Merged
MariusWirtz merged 2 commits into
cubewise-code:masterfrom
skido-cw:feature/blob-add-elements-edges
Jun 22, 2026
Merged

Add blob-based add_elements / add_edges for symmetric dimension blob support#1423
MariusWirtz merged 2 commits into
cubewise-code:masterfrom
skido-cw:feature/blob-add-elements-edges

Conversation

@skido-cw

Copy link
Copy Markdown
Contributor

Summary

Blob loading (CSV upload + unbound TI process) was previously only available for deleting edges (delete_edges_use_blob), while adding elements and edges was REST-only. This PR makes the support symmetric and scales bulk dimension builds — which is where blob actually pays off (lots of elements + multiple consolidations).

Changes

ElementService

  • Cleanup / DRY: extracted the shared blob plumbing into _build_blob_datasource_process (the ASCII-datasource Process skeleton, incl. v11 .blb handling + UTF-8 prolog) and _run_blob_process (CSV serialize → upload → execute → cleanup). Refactored delete_edges_use_blob / _build_unwind_hierarchy_edges_from_blob_process onto them.
  • New: add_elements_use_blob (TI HierarchyElementInsert) and add_edges_use_blob (TI HierarchyElementComponentAdd), dispatched from a new use_blob / remove_blob kwarg on add_elements / add_edges. Both gated by @require_data_admin / @require_ops_admin, matching the existing delete path.

HierarchyService

  • update_or_create_hierarchy_from_dataframe now adds elements and edges via blob for admins (use_blob=self.is_admin), mirroring the edge-delete calls already there — so a large hierarchy build is blob-based end to end.

Behavior / compatibility

  • Fully backward compatible: use_blob defaults to False, so the default path is the unchanged REST behavior (still returns the Response). With use_blob=True the methods return None, consistent with delete_edges_use_blob.
  • Recommended usage for building consolidations: add elements first (incl. the C elements), then add the edges.

Testing

  • Offline unit tests (no server): the generated TI processes (variables/types, the exact HierarchyElementInsert / HierarchyElementComponentAdd / ...ComponentDelete statements, UTF-8 prolog, v11 .blb suffixing) and the use_blob dispatch wiring.
  • Live integration tests: new add_elements_use_blob / add_edges_use_blob tests (incl. consolidations) and a bulk update_or_create_hierarchy_from_dataframe build with many consolidations.
  • Live-tested end to end against TM1 v11 (11.8) and v12 (PA Engine), including the v11 .blb path. The full from_dataframe suite (30 tests) passes on v12.
  • black --check . and ruff check . pass.

🤖 Generated with Claude Code

…b support

Previously blob (CSV upload + unbound TI process) was only available for
deleting edges, while adding elements and edges was REST-only. This makes
the support symmetric and scales bulk dimension builds.

- ElementService: extract shared blob plumbing (_build_blob_datasource_process,
  _run_blob_process) and refactor delete_edges_use_blob onto it.
- ElementService: add add_elements_use_blob (HierarchyElementInsert) and
  add_edges_use_blob (HierarchyElementComponentAdd), dispatched from a new
  use_blob/remove_blob kwarg on add_elements/add_edges. Both admin-gated.
- HierarchyService.update_or_create_hierarchy_from_dataframe now adds elements
  and edges via blob for admins (use_blob=self.is_admin), matching the existing
  edge-delete path, so the whole bulk build is blob-based for large sets.
- Tests: offline process-builder/dispatch unit tests, plus live tests for the
  new methods and a bulk hierarchy build with many consolidations.

Live-tested end to end against TM1 v11 (11.8) and v12 (PA Engine).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends TM1py’s blob (CSV upload + unbound TI process) bulk-update workflow beyond edge deletion to also support adding elements and adding edges, enabling end-to-end blob-based hierarchy builds for large consolidations (especially when running as admin).

Changes:

  • Refactors shared blob plumbing in ElementService into reusable helpers and wires delete_edges_use_blob onto them.
  • Adds add_elements_use_blob / add_edges_use_blob and dispatches via new use_blob / remove_blob kwargs on add_elements / add_edges.
  • Updates HierarchyService.update_or_create_hierarchy_from_dataframe to use blob-based add paths for admins; adds unit + integration tests for the new blob functionality.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
TM1py/Services/HierarchyService.py Switches dataframe-driven hierarchy builds to use blob-based element/edge adds for admins.
TM1py/Services/ElementService.py Introduces shared blob helpers, adds blob-based element/edge add APIs, and refactors blob delete-edge flow.
Tests/HierarchyService_test.py Adds a bulk consolidation build test intended to exercise end-to-end blob paths.
Tests/ElementService_test.py Adds integration tests for blob add APIs plus offline unit tests for TI process builders/dispatch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TM1py/Services/ElementService.py Outdated
Comment thread TM1py/Services/ElementService.py
Comment thread TM1py/Services/ElementService.py Outdated
Comment thread TM1py/Services/ElementService.py
Comment thread TM1py/Services/ElementService.py
Comment thread TM1py/Services/HierarchyService.py
Comment thread TM1py/Services/HierarchyService.py
@github-actions

Copy link
Copy Markdown
Contributor

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

@MariusWirtz

Copy link
Copy Markdown
Collaborator

Looking good from my side and all tests pass!
Copilot made some cosmetic suggestions. Please consider the suggestions, and then we can merge

- _run_blob_process: skip the defensive list() copy when rows is already a
  list/tuple (the common case), only materializing iterators/generators, to
  avoid doubling memory on large bulk builds.
- add_elements / add_edges: annotate return as Optional[Response] (the blob
  path returns None).
- add_elements_use_blob / add_edges_use_blob: add @require_version("11.4")
  for an earlier, clearer error, matching FileService.create's gating.
- update_or_create_hierarchy_from_dataframe: gate the blob add/delete paths on
  admin rights AND TM1 >= 11.4 (Contents API), falling back to REST on older
  servers so the method stays backward compatible for admins on v11 < 11.4.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@skido-cw

Copy link
Copy Markdown
Contributor Author

Thanks! Addressed all 7 of Copilot's suggestions:

  • add_elements/add_edges now annotated Optional[Response]; *_use_blob carry @require_version("11.4").
  • _run_blob_process skips the list copy when the input is already a list/tuple.
  • update_or_create_hierarchy_from_dataframe now gates the blob add/delete paths on admin + TM1 ≥ 11.4 (falls back to REST on older servers), so it stays backward compatible - I applied the same gate to the pre-existing delete_edges blob calls too for consistency. Re-ran the blob tests against v12; all pass.

@MariusWirtz MariusWirtz merged commit f3ce281 into cubewise-code:master Jun 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants