marsdb_query/value.rs
1use std::collections::BTreeMap;
2
3use marsdb_graph::{Edge, Node, PropertyValue};
4
5use crate::ast::Literal;
6
7/// One element of a `Value::Path` — a path is `node, edge, node, edge,
8/// ..., node`, alternating, as a single `Vec`, not two parallel node/edge
9/// vecs (which would create an unenforced `nodes.len() == edges.len() +
10/// 1` invariant across every place a path gets built or read).
11#[derive(Debug, Clone)]
12pub enum PathElem {
13 Node(Node),
14 Edge(Edge),
15}
16
17#[derive(Debug, Clone)]
18pub enum Value {
19 Node(Node),
20 Edge(Edge),
21 Property(PropertyValue),
22 Literal(Literal),
23 /// A list literal, `collect()` result, or a list-valued node/edge
24 /// property read back from storage (`PropertyValue::List` converts to
25 /// this, never a raw `Value::Property(PropertyValue::List(_))` — see
26 /// `executor::property_value_to_value`) — every existing list
27 /// operation (indexing, `size()`, `IN`, `UNWIND`, ...) pattern-matches
28 /// on this variant specifically, not on a property-sourced list
29 /// separately.
30 List(Vec<Value>),
31 /// A named path (`MATCH p = (a)-->(b) RETURN p`) or a `shortestPath()`
32 /// result — see `Binding::Path`'s docs (executor.rs) for how this
33 /// gets assembled during MATCH evaluation.
34 Path(Vec<PathElem>),
35 /// A map literal (`{a: 1, b: 2}`) — like `List`, a query-layer-only
36 /// concept, never persisted as a `PropertyValue` (nothing in the
37 /// grammar can construct a map literal to store as a node/edge
38 /// property directly; a `CREATE {...}` prop map's *values* are each
39 /// evaluated and stored individually as their own scalar
40 /// `PropertyValue` — see `Executor::eval_props_to_values` — a `Value::
41 /// Map` reaching there is a real error, not silently dropped). Its
42 /// other main real use is as a `date(...)`/`duration(...)`
43 /// construction function's argument, e.g. `date({year: 1984, month:
44 /// 10, day: 11})` — see `Executor::call_builtin`. `BTreeMap`, not
45 /// `HashMap` — canonical key order makes display/comparison
46 /// deterministic without a separate sort step.
47 Map(BTreeMap<String, Value>),
48 Null,
49}