Skip to main content

reifydb_export/
model.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4use std::collections::HashMap;
5
6use reifydb_core::interface::catalog::{
7	dictionary::Dictionary, namespace::Namespace, ringbuffer::RingBuffer, series::Series, sumtype::SumType,
8	table::Table,
9};
10use reifydb_value::value::{Value, value_type::ValueType};
11
12pub struct ShapeRows {
13	pub columns: Vec<String>,
14	pub rows: Vec<Vec<Value>>,
15}
16
17pub struct TableExport {
18	pub table: Table,
19	pub rows: Option<ShapeRows>,
20}
21
22pub struct RingBufferExport {
23	pub ringbuffer: RingBuffer,
24	pub rows: Option<ShapeRows>,
25}
26
27pub struct SeriesExport {
28	pub series: Series,
29	pub rows: Option<ShapeRows>,
30}
31
32pub struct ExportModel {
33	pub namespaces: Vec<Namespace>,
34	pub sumtypes: Vec<SumType>,
35	pub dictionaries: Vec<Dictionary>,
36	pub tables: Vec<TableExport>,
37	pub ringbuffers: Vec<RingBufferExport>,
38	pub series: Vec<SeriesExport>,
39	pub resolver: NameResolver,
40}
41
42pub struct NameResolver {
43	pub namespaces: HashMap<u64, String>,
44	pub dictionaries: HashMap<u64, ResolvedDictionary>,
45	pub sumtypes: HashMap<u64, ResolvedSumType>,
46}
47
48pub struct ResolvedDictionary {
49	pub qualified_name: String,
50	pub value_type: ValueType,
51}
52
53pub struct ResolvedSumType {
54	pub qualified_name: String,
55	pub variants: Vec<ResolvedVariant>,
56}
57
58pub struct ResolvedVariant {
59	pub tag: u8,
60	pub name: String,
61	pub fields: Vec<String>,
62}
63
64impl NameResolver {
65	pub fn empty() -> Self {
66		Self {
67			namespaces: HashMap::new(),
68			dictionaries: HashMap::new(),
69			sumtypes: HashMap::new(),
70		}
71	}
72
73	pub fn dictionary(&self, id: u64) -> Option<&ResolvedDictionary> {
74		self.dictionaries.get(&id)
75	}
76
77	pub fn sumtype(&self, id: u64) -> Option<&ResolvedSumType> {
78		self.sumtypes.get(&id)
79	}
80
81	pub fn sumtype_variant(&self, id: u64, tag: u8) -> Option<&ResolvedVariant> {
82		self.sumtypes.get(&id).and_then(|st| st.variants.iter().find(|v| v.tag == tag))
83	}
84
85	pub fn sumtype_variant_name(&self, id: u64, tag: u8) -> Option<&str> {
86		self.sumtype_variant(id, tag).map(|v| v.name.as_str())
87	}
88}