diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-09-26 22:09:11 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-09-26 22:09:11 -0300 |
| commit | 320954996e921d7b34eb61f462799b5c6ab8ee09 (patch) | |
| tree | 16697bc161faf27f0b4c1ba57f6fcc24d240801b /lib/drl/executor.ml | |
| parent | b555c28c7e6c315fc0394baf213ecb08b21ed959 (diff) | |
| download | Sakura-320954996e921d7b34eb61f462799b5c6ab8ee09.tar.gz Sakura-320954996e921d7b34eb61f462799b5c6ab8ee09.zip | |
new shrunk API for RNT on sakura
Diffstat (limited to 'lib/drl/executor.ml')
| -rw-r--r-- | lib/drl/executor.ml | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/drl/executor.ml b/lib/drl/executor.ml new file mode 100644 index 0000000..e472ec5 --- /dev/null +++ b/lib/drl/executor.ml @@ -0,0 +1,33 @@ +open Utilities.Result + +let page_limit = 16 + +(* [mg:rel] names a relation on the session's branch; a bare name, one the session created. *) +let path_of (ctx : Sublanguage_context.t) name = + match String.index_opt name ':' with + | None -> ctx.session#namespace ^ "\\" ^ name + | Some i -> + String.concat "\\" + [ ""; + "branch"; + ctx.session#branch; + "multigroup"; + String.sub name 0 i; + "relation"; + String.sub name (i + 1) (String.length name - i - 1) ] + +let rec compile ctx = function + | Ast.Base name -> RNT.Base (path_of ctx name) + | Ast.Project (attributes, query) -> RNT.Project (compile ctx query, attributes) + +let execute (ctx : Sublanguage_context.t) query = + let* relation = RNT.execute ctx.kernel (compile ctx query) in + Fun.protect + ~finally:(fun () -> RNT.release relation) + (fun () -> + let* cursor = RNT.enumerate relation in + Fun.protect + ~finally:(fun () -> RNT.release cursor) + (fun () -> + let* {RNT.tuples; exhausted} = RNT.fetch cursor page_limit in + Ok (Sublanguage_types.Cursor {rows= tuples; has_more= not exhausted}) ) ) |
