Skip to content

feat(#1458): Renderable Codec Protocol#1472

Open
dimitri-yatsenko wants to merge 1 commit into
masterfrom
feat/1458-renderable-protocol
Open

feat(#1458): Renderable Codec Protocol#1472
dimitri-yatsenko wants to merge 1 commit into
masterfrom
feat/1458-renderable-protocol

Conversation

@dimitri-yatsenko

Copy link
Copy Markdown
Member

Summary

Implements T3.2 of the 2.3 release plan, against the spec in datajoint-docs#188.

A runtime-checkable Protocol that codecs opt into by implementing `render_spark(self, decoded, *, key=None) -> Any`. Consumers (e.g., a Databricks silver-layer publish pipeline) detect support via `isinstance(codec, Renderable)`.

Closes #1458. Supersedes #1457. Slated for DataJoint 2.3.

What's added

Component File
`Renderable` Protocol declaration `src/datajoint/rendering.py` (new, ~85 lines including docstrings)
Top-level re-export as `dj.Renderable` `src/datajoint/init.py`
9 unit tests `tests/unit/test_rendering.py` (new)

The Protocol surface is intentionally tiny — a single method. The bulk of `rendering.py` is docstring (module-level rationale + class docstring documenting allowed return-value shapes with worked codec examples).

Tests

  • 9/9 pass on the new file.
  • Coverage: opt-in detection, non-opt-in rejection, top-level re-export, `@runtime_checkable` guarantee, built-in `<blob@>` and `<hash@>` codecs are NOT Renderable (per spec contract), invocation pass-through, `key` kwarg acceptance, subclass opt-in behavior.

What's NOT in this PR (out of scope per spec)

  • Specific renderable codec implementations. `<float_array@>`, `<image_2d@>`, `<labeled_struct@>`, `<timeseries@>`, etc. ship downstream as plugins. They register via existing codec auto-registration and opt in by implementing `render_spark()`.
  • Silver-layer publish pipeline. Lives in `datajoint-databricks`. This PR provides the eligibility-check contract; the pipeline consumes it.
  • No `decode_spark` (reverse direction). Delta consumers query rendered columns directly via Spark SQL.
  • No `BINARY` fallback. Codecs either implement `Renderable` or remain non-eligible — no automatic blob → bytes-passthrough.

Sequencing

Independent of the provenance trinity (T2.2.a–c, in flight) — no code overlap. Lands in parallel.

Once this PR merges, the matching docs spec PR (datajoint-docs#188) flips from draft to ready for review.

Test plan

  • 9/9 new unit tests pass
  • CI green (lint, test matrix, unit-tests)
  • `isinstance(codec, dj.Renderable)` returns True for a plugin codec that adds the method (smoke-test against a sample plugin once one exists)

Implements T3.2 of the 2.3 release plan against the spec in
datajoint-docs#188.

A runtime-checkable Protocol that codecs opt into by implementing
``render_spark(self, decoded, *, key=None) -> Any``. Consumers (e.g.,
a Databricks silver-layer publish pipeline) detect support via
``isinstance(codec, Renderable)``.

What's added:

- src/datajoint/rendering.py (new, ~85 lines including docstrings):
  Single @runtime_checkable Protocol declaration. Module-level
  docstring explains the design rationale (Protocol vs. abstract method
  on Codec); class docstring documents allowed return-value shapes
  (primitives / lists / dicts mapping to Spark ArrayType / StructType /
  MapType), with worked codec examples.

- src/datajoint/__init__.py: ``dj.Renderable`` exported at the top
  level alongside the existing Codec API exports.

- tests/unit/test_rendering.py (new, 9 tests): detection of opt-in vs
  non-opt-in classes, top-level re-export, @runtime_checkable guarantee,
  built-in <blob@> and <hash@> codecs are not Renderable (per spec
  contract), invocation pass-through, key kwarg acceptance, subclass
  opt-in behavior.

What's NOT in this PR (out of scope per spec):

- Specific renderable codec implementations. Codecs like <float_array@>,
  <image_2d@>, <labeled_struct@>, <timeseries@> ship downstream as
  plugins. They register via the existing codec auto-registration and
  opt in by implementing render_spark().
- Silver-layer publish pipeline (lives in datajoint-databricks).
- No decode_spark (reverse direction).
- No BINARY fallback — codecs either implement Renderable or remain
  non-eligible.

All 9 unit tests pass. No regressions expected — this is purely additive
(a new module + one top-level re-export + tests).

Slated for DataJoint 2.3.
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.

Add Renderable Protocol for codec-driven Spark-native rendering

1 participant