This repository was archived by the owner on Nov 21, 2026. It is now read-only.
Repository navigation
Python functions callable from SQL and openCypher, and record event callbacks - #391
Merged
Merged
Conversation
tae898
force-pushed
the
udf-callbacks-386
branch
2 times, most recently
from
October 21, 2026 07:26
4622017 to
0855b60
Compare
…allbacks (#386) Database.register_function() / unregister_function() register a Python callable as an engine SQLFunction (bridge class PythonFunctions): SELECT and WHERE in SQL, and openCypher through a namespaced name such as py.slugify (its validator rejects an unknown bare name). An exception in the function is an ArcadeDBError naming the function, never a JVM crash. Database.on() / EventHandle.remove() run Python callbacks on before/after create, update and delete (bridge class PythonRecordEvents), database-wide or per type; a before callback that returns False vetoes the change, and an exception fails the operation. Tests, API and guide docs, coverage, bridge and testing docs, and example 27 in the same change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…st example of #387) (#386) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…base is released with its last result (#386) The registry, the function proxies and the event proxies hold the Database through a weak reference: the engine holds the proxies, so a strong reference would keep the Database alive until a gc pass. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…th tools/ab.py; Example 28 prints the cost on the reader's machine (#386) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eak), readable error for an unconvertible return, Ctrl-C always a KeyboardInterrupt, Document.save()/delete() raise ArcadeDBError; docs: read-only begin(), the ~30 bytes per numeric argument JPype note (#386) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…r-call figure in the examples README (#386) Co-Authored-By: Claude Opus 5.5 <[email protected]>
tae898
force-pushed
the
udf-callbacks-386
branch
from
October 21, 2026 09:08
0855b60 to
86e71fc
Compare
This was referenced Oct 21, 2026
This was referenced Oct 21, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Closes #386.
Two things no query language can express, which the other embedded databases' Python APIs offer (sqlite3, DuckDB and Kuzu/LadybugDB register Python functions; sqlite3/apsw expose change hooks).
Database.register_function(name, fn, *, min_args=None, max_args=None, deterministic=False, replace=False)andunregister_function(name): a Java adapter (PythonFunctions.java, extendsSQLFunctionAbstract) registered in the engine'sDefaultSQLFunctionFactory; SQL calls it by name, openCypher with a dotted name (py.slugify) because its validator rejects unknown bare names. Arguments and results go through the bindings' type conversion; an exception infn(evenKeyboardInterrupt) becomes one query error naming the function, never a JVM failure. Registration is process-wide in the engine: aDatabaseremoves the functions it registered when it closes, and functions should be registered before concurrent queries start. Measured cost: about 5 to 10 microseconds per call (20,000 rows, best of 5,SELECT plus_one(n)againstSELECT n + 1; the docs say how).Database.on(event, fn, type_name=None) -> EventHandle(remove(), context manager) forbefore_/after_create,update,deleteover the engine's record events (PythonRecordEvents.java, one adapter for the six listener interfaces); abefore_*callback returning False vetoes the change; a type filter matches that type only.api/database.md,guide/core/queries.md,guide/core/database.md,java-api-coverage.md,bridge.md,architecture.md,contributing.md,testing.md; example 28 (script, page, README, index, nav).test_python_callbacks.py, 34 cases (functions in SELECT and WHERE, NULLs, arity, errors surfacing, unregister, openCypher; each event firing once with the record, type filter, veto, remove); no skips.Checked locally against the 26.10.2 engine with the bridge jar rebuilt: the new tests with test_core, test_bridge_fixes, test_database_utils, test_async_executor and test_cypher (129 passed), bandit (low/low), pre-commit, the strict docs build.
🤖 Generated with Claude Code