json_eval_rs/
table_metadata.rs

1use serde_json::Value;
2use std::sync::Arc;
3use crate::LogicId;
4
5/// Pre-compiled column metadata computed at parse time (zero-copy design)
6#[derive(Clone, Debug)]
7pub struct ColumnMetadata {
8    /// Column name (Arc to avoid clones)
9    pub name: Arc<str>,
10    /// Variable path like "$columnName" (pre-computed)
11    pub var_path: Arc<str>,
12    /// Logic ID if this column has evaluation logic
13    pub logic: Option<LogicId>,
14    /// Literal value if no logic (Arc to share across evaluations)
15    pub literal: Option<Arc<Value>>,
16    /// Variable names this column depends on (e.g., ["$other_col"])
17    pub dependencies: Arc<[String]>,
18    /// Whether this column has forward references (computed once)
19    pub has_forward_ref: bool,
20}
21
22impl ColumnMetadata {
23    #[inline]
24    pub fn new(
25        name: &str,
26        logic: Option<LogicId>,
27        literal: Option<Value>,
28        dependencies: Vec<String>,
29        has_forward_ref: bool,
30    ) -> Self {
31        let var_path = format!("${}", name);
32        Self {
33            name: Arc::from(name),
34            var_path: Arc::from(var_path.as_str()),
35            logic,
36            literal: literal.map(Arc::new),
37            dependencies: dependencies.into(),
38            has_forward_ref,
39        }
40    }
41}
42
43/// Pre-compiled repeat bound metadata
44#[derive(Clone, Debug)]
45pub struct RepeatBoundMetadata {
46    pub logic: Option<LogicId>,
47    /// Literal value (Arc to share)
48    pub literal: Arc<Value>,
49}
50
51/// Pre-compiled row metadata (computed at parse time)
52#[derive(Clone, Debug)]
53pub enum RowMetadata {
54    Static {
55        columns: Arc<[ColumnMetadata]>,
56    },
57    Repeat {
58        start: RepeatBoundMetadata,
59        end: RepeatBoundMetadata,
60        columns: Arc<[ColumnMetadata]>,
61        /// Pre-computed set of forward-referencing column names (transitive closure)
62        forward_cols: Arc<[usize]>, // indices into columns array
63        /// Pre-computed normal columns in schema order
64        normal_cols: Arc<[usize]>, // indices into columns array
65    },
66}
67
68/// Pre-compiled table metadata (computed once at parse time)
69#[derive(Clone, Debug)]
70pub struct TableMetadata {
71    /// Data columns to evaluate before skip/clear
72    pub data_plans: Arc<[(Arc<str>, Option<LogicId>, Option<Arc<Value>>)]>,
73    /// Row plans with pre-computed metadata
74    pub row_plans: Arc<[RowMetadata]>,
75    /// Skip logic
76    pub skip_logic: Option<LogicId>,
77    /// Skip literal value
78    pub skip_literal: bool,
79    /// Clear logic
80    pub clear_logic: Option<LogicId>,
81    /// Clear literal value
82    pub clear_literal: bool,
83}