relate-executor 1.5.0

In-memory graph and Cypher physical executor
Documentation
//! The `LOAD CSV` position builtins: `linenumber()` and `file()`, forms that
//! read the hidden position columns the clause stamps on the rows it builds
//! (`LINE_KEY`, `FILE_KEY` in `crate::csv`).

use std::collections::BTreeMap;

use relate_core::{Result, Value};
use relate_ir::Expr;

use crate::csv::{FILE_KEY, LINE_KEY};
use crate::overlay::ExecGraph;
use crate::row::Row;

/// The hidden `LOAD CSV` position column `key` of `row`; `null` where the
/// row carries none (no `LOAD CSV` built it, or a projection rebuilt it) —
/// the one read-or-null rule both position functions share.
fn position_column(row: &Row, key: &str) -> Value {
    row.get(key).map_or(Value::Null, Clone::clone)
}

/// `linenumber()`: the 1-based record number `LOAD CSV` is on — the
/// header record is line 1 under `WITH HEADERS`. The row carries it as a
/// hidden column (`LINE_KEY`); a row no `LOAD CSV` built (or one a
/// projection rebuilt) carries none, and the answer there is the
/// documented `null`, not a default.
pub(super) fn linenumber_form(
    _graph: &ExecGraph<'_>,
    row: &Row,
    _params: &BTreeMap<String, Value>,
    _args: &[Expr],
) -> Result<Value> {
    Ok(position_column(row, LINE_KEY))
}

/// `file()`: the source the `LOAD CSV` clause read, as the query spelled
/// it; `null` where the row carries none (see [`linenumber_form`]).
pub(super) fn file_form(
    _graph: &ExecGraph<'_>,
    row: &Row,
    _params: &BTreeMap<String, Value>,
    _args: &[Expr],
) -> Result<Value> {
    Ok(position_column(row, FILE_KEY))
}