barrel_bql_exec (barrel_docdb v1.1.1)

View Source

BQL post-stage executor for collection sources: drives barrel_docdb:find/3 with a compiled plan and applies the per-row stages (unnest expansion, frame-residual predicates, order, offset/limit, projection).

The frame helpers (frames_for/2, residual_match/2, finalize/3) are also the reuse surface for the barrel module, which feeds them table-function hits instead of find rows.

A frame is #{doc := map() with id merged in, elem := term() | undefined, score := map()}; score carries the synthetic _score / _distance columns of table-function sources (empty here).

Summary

Functions

Order, offset/limit and project a list of frames.

Fold rows without materializing the full result (streamable plans paginate internally; materializing plans fold the built list). Fun(Row, Acc) -> {ok, Acc} | {stop, Acc}.

Expand a document into frames: one per unnested array element, or a single element-less frame. Missing / non-array unnest values produce no frames (inner-join UNNEST).

Evaluate the frame-residual conjuncts (tagged paths) against a frame. Mirrors the engine's exists-and-satisfies leaf semantics.

Run a compiled plan. Streamable plans (no ORDER BY, no UNNEST) keep find/3's chunk semantics: one chunk per call, meta carries the continuation. Materializing plans paginate internally and return everything.

Types

frame/0

-type frame() :: #{doc := map(), elem := term(), score := map()}.

Functions

finalize(Frames0, Post, Unnest)

-spec finalize([frame()], map(), undefined | #{path := list(), alias := binary()}) -> [map()].

Order, offset/limit and project a list of frames.

fold(DbName, Plan, Opts, Fun, Acc)

-spec fold(binary(),
           barrel_bql_lower:plan(),
           map(),
           fun((map(), term()) -> {ok, term()} | {stop, term()}),
           term()) ->
              {ok, term(), map()} | {error, term()}.

Fold rows without materializing the full result (streamable plans paginate internally; materializing plans fold the built list). Fun(Row, Acc) -> {ok, Acc} | {stop, Acc}.

frames_for(Doc, _)

-spec frames_for(map(), undefined | #{path := list(), alias := binary()}) -> [frame()].

Expand a document into frames: one per unnested array element, or a single element-less frame. Missing / non-array unnest values produce no frames (inner-join UNNEST).

residual_match(Conds, Frame)

-spec residual_match([term()], frame()) -> boolean().

Evaluate the frame-residual conjuncts (tagged paths) against a frame. Mirrors the engine's exists-and-satisfies leaf semantics.

run(DbName, Plan, Opts)

-spec run(binary(), barrel_bql_lower:plan(), map()) -> {ok, [map()], map()} | {error, term()}.

Run a compiled plan. Streamable plans (no ORDER BY, no UNNEST) keep find/3's chunk semantics: one chunk per call, meta carries the continuation. Materializing plans paginate internally and return everything.