Liking cljdoc? Tell your friends :D

datajure.asof

Core sorted-merge algorithm for as-of join.

Part 1 — asof-search / asof-indices: asof-search — binary search for the last right index where value <= target. asof-indices — two-pointer merge over pre-sorted, pre-grouped vectors; public utility, not used internally by asof-match.

Part 2 — asof-match: full key-handling layer. Groups right rows by exact keys, sorts within each group, runs asof-search (binary search) per left row. Returns a lazy sequence of [left-row-idx right-row-idx-or-nil] pairs.

Part 3 — build-result: assembles a tech.v3.dataset from the index pairs. Left columns always present in original order; right non-key columns appended (nil-filled for unmatched rows). Conflicting non-key column names suffixed :right.<n>.

Core sorted-merge algorithm for as-of join.

Part 1 — asof-search / asof-indices:
  asof-search  — binary search for the last right index where value <= target.
  asof-indices — two-pointer merge over pre-sorted, pre-grouped vectors;
                 public utility, not used internally by asof-match.

Part 2 — asof-match: full key-handling layer. Groups right rows by exact
keys, sorts within each group, runs asof-search (binary search) per left
row. Returns a lazy sequence of [left-row-idx right-row-idx-or-nil] pairs.

Part 3 — build-result: assembles a tech.v3.dataset from the index pairs.
Left columns always present in original order; right non-key columns
appended (nil-filled for unmatched rows). Conflicting non-key column
names suffixed :right.<n>.
raw docstring

asof-indicesclj

(asof-indices left-vals right-vals)

Two-pointer merge: for each element in left-vals, return a long-array of the matched right-row index within right-vals (both must be pre-sorted ascending). Returns -1 for left rows with no match. Nil values are skipped.

Public utility — not used internally by asof-match, which uses asof-search (binary search per group) instead.

Two-pointer merge: for each element in `left-vals`, return a long-array
of the matched right-row index within `right-vals` (both must be pre-sorted
ascending). Returns -1 for left rows with no match. Nil values are skipped.

Public utility — not used internally by asof-match, which uses asof-search
(binary search per group) instead.
sourceraw docstring

asof-matchclj

(asof-match left right left-keys right-keys)
(asof-match left right left-keys right-keys direction tolerance)

Produce index pairs for an as-of join.

Arguments: left — tech.v3.dataset right — tech.v3.dataset left-keys — vector of column keywords; last = asof col, rest = exact cols right-keys — vector of column keywords; same structure direction — :backward (default), :forward, or :nearest tolerance — numeric max abs distance; nil means unbounded. Requires a numeric asof key. Matches whose distance exceeds tolerance are treated as no-match (nil right index).

Returns a lazy sequence of [left-row-idx right-row-idx-or-nil] pairs in left-row order. Unmatched left rows yield nil for right index.

Produce index pairs for an as-of join.

Arguments:
  left       — tech.v3.dataset
  right      — tech.v3.dataset
  left-keys  — vector of column keywords; last = asof col, rest = exact cols
  right-keys — vector of column keywords; same structure
  direction  — :backward (default), :forward, or :nearest
  tolerance  — numeric max abs distance; nil means unbounded. Requires a
               numeric asof key. Matches whose distance exceeds tolerance
               are treated as no-match (nil right index).

Returns a lazy sequence of [left-row-idx right-row-idx-or-nil] pairs in
left-row order. Unmatched left rows yield nil for right index.
sourceraw docstring

(asof-search right-vals n target)
(asof-search right-vals n target direction)

Binary search over sorted right-vals for the best match to target. Nils in right-vals are treated as greater than any real value (they sort last). Nil target always returns -1.

direction (optional, default :backward): :backward — last index where right-val <= target (default, SQL ASOF convention) :forward — first index where right-val >= target :nearest — closest index by absolute distance; ties prefer :backward

Returns -1 if no qualifying match exists.

Binary search over sorted `right-vals` for the best match to `target`.
Nils in right-vals are treated as greater than any real value (they sort last).
Nil target always returns -1.

direction (optional, default :backward):
  :backward — last index where right-val <= target  (default, SQL ASOF convention)
  :forward  — first index where right-val >= target
  :nearest  — closest index by absolute distance; ties prefer :backward

Returns -1 if no qualifying match exists.
sourceraw docstring

build-resultclj

(build-result left right pairs right-keys)

Assemble the as-of join result dataset from index pairs.

Arguments: left — tech.v3.dataset (all rows preserved, in original order) right — tech.v3.dataset pairs — seq of [left-row-idx right-row-idx-or-nil] right-keys — right key columns (dropped from the appended right columns)

Returns a dataset with:

  • all left columns in original order
  • right non-key columns appended (nil-filled for unmatched rows)
  • conflicting non-key column names suffixed with :right.<n>
Assemble the as-of join result dataset from index pairs.

Arguments:
  left       — tech.v3.dataset (all rows preserved, in original order)
  right      — tech.v3.dataset
  pairs      — seq of [left-row-idx right-row-idx-or-nil]
  right-keys — right key columns (dropped from the appended right columns)

Returns a dataset with:
  - all left columns in original order
  - right non-key columns appended (nil-filled for unmatched rows)
  - conflicting non-key column names suffixed with :right.<n>
sourceraw docstring

window-indicesclj

(window-indices left right left-keys right-keys lo-offset hi-offset)

For each left row, find all right row indices whose asof-key falls within [left-asof-key + lo-offset, left-asof-key + hi-offset] (both bounds inclusive).

Arguments: left, right — tech.v3.dataset left-keys — column keywords (last = asof col, rest = exact-match cols) right-keys — column keywords (same structure as left-keys) lo-offset — lower bound offset added to left asof-key (numeric, raw units) hi-offset — upper bound offset added to left asof-key (numeric, raw units)

Returns a sequence of [left-row-idx [matched-right-original-row-indices]] pairs. Empty inner vector means no right rows fell in the window (left row still appears). Left rows with nil asof-key always yield an empty inner vector.

For each left row, find all right row indices whose asof-key falls within
[left-asof-key + lo-offset, left-asof-key + hi-offset] (both bounds inclusive).

Arguments:
  left, right  — tech.v3.dataset
  left-keys    — column keywords (last = asof col, rest = exact-match cols)
  right-keys   — column keywords (same structure as left-keys)
  lo-offset    — lower bound offset added to left asof-key (numeric, raw units)
  hi-offset    — upper bound offset added to left asof-key (numeric, raw units)

Returns a sequence of [left-row-idx [matched-right-original-row-indices]] pairs.
Empty inner vector means no right rows fell in the window (left row still appears).
Left rows with nil asof-key always yield an empty inner vector.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close