1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5use utoipa::ToSchema;
6
7use crate::{CalciteId, SourcePosition};
8
9pub type MirNodeId = String;
10
11#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, PartialEq, Eq)]
12pub struct MirInput {
13 pub node: String,
14 pub output: usize,
15
16 #[serde(flatten)]
17 pub extra: HashMap<String, Value>,
18}
19
20#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, PartialEq, Eq)]
21pub struct MirNode {
22 #[serde(default)]
23 pub calcite: Option<CalciteId>,
24
25 #[serde(default)]
26 pub table: Option<String>,
27
28 #[serde(default)]
29 pub view: Option<String>,
30
31 #[serde(default)]
32 pub inputs: Vec<MirInput>,
33
34 pub operation: String,
35
36 #[serde(default)]
37 pub outputs: Option<Vec<Option<MirInput>>>,
38
39 #[serde(default)]
40 pub persistent_id: Option<String>,
41
42 #[serde(default)]
43 pub positions: Vec<SourcePosition>,
44
45 #[serde(flatten)]
46 pub extra: HashMap<String, Value>,
47}
48
49impl MirNode {
50 pub fn is_view(&self) -> bool {
51 self.view.is_some()
52 }
53
54 pub fn is_table(&self) -> bool {
55 self.table.is_some()
56 }
57
58 pub fn is_relation(&self) -> bool {
59 self.is_view() || self.is_table()
60 }
61}