feat(#1458): Renderable Codec Protocol#1472
Open
dimitri-yatsenko wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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
What's NOT in this PR (out of scope per spec)
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