|
| 1 | +use std::collections::HashMap; |
| 2 | + |
| 3 | +use async_graphql::SimpleObject; |
| 4 | +use serde::{Deserialize, Serialize}; |
| 5 | +use serde_json::Value; |
| 6 | + |
| 7 | +use crate::model::node; |
| 8 | + |
| 9 | +pub type Table = HashMap<String, Vec<Value>>; |
| 10 | + |
| 11 | +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SimpleObject)] |
| 12 | +pub struct TableMetadataRoot { |
| 13 | + pub data: TableData, |
| 14 | + pub error: Value, |
| 15 | + pub links: Option<node::Links>, |
| 16 | + pub meta: Value, |
| 17 | +} |
| 18 | + |
| 19 | +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SimpleObject)] |
| 20 | +pub struct TableData { |
| 21 | + pub id: String, |
| 22 | + pub attributes: TableAttributes, |
| 23 | + pub links: TableLinks, |
| 24 | + pub meta: Value, |
| 25 | +} |
| 26 | + |
| 27 | +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SimpleObject)] |
| 28 | +pub struct TableAttributes { |
| 29 | + pub ancestors: Vec<Value>, |
| 30 | + pub structure_family: String, |
| 31 | + pub specs: Option<Vec<Value>>, |
| 32 | + pub metadata: HashMap<String, Value>, |
| 33 | + pub structure: TableStructure, |
| 34 | + pub access_blob: Value, |
| 35 | + pub sorting: Value, |
| 36 | + pub data_sources: Value, |
| 37 | +} |
| 38 | + |
| 39 | +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SimpleObject)] |
| 40 | +pub struct TableStructure { |
| 41 | + pub arrow_schema: String, |
| 42 | + pub npartitions: i64, |
| 43 | + pub columns: Vec<Value>, |
| 44 | + pub resizable: bool, |
| 45 | +} |
| 46 | + |
| 47 | +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SimpleObject)] |
| 48 | +pub struct TableLinks { |
| 49 | + #[serde(rename = "self")] |
| 50 | + #[graphql(name = "self")] |
| 51 | + pub self_field: String, |
| 52 | + pub full: Option<String>, |
| 53 | + pub partition: Option<String>, |
| 54 | +} |
| 55 | + |
| 56 | +#[cfg(test)] |
| 57 | +mod tests { |
| 58 | + use crate::model::table; |
| 59 | + use crate::test_utils::assert_readable_as; |
| 60 | + |
| 61 | + #[test] |
| 62 | + fn table_metadata() { |
| 63 | + assert_readable_as::<table::TableMetadataRoot>("resources/metadata_table.json"); |
| 64 | + } |
| 65 | + #[test] |
| 66 | + fn table_full() { |
| 67 | + assert_readable_as::<table::Table>("resources/table_full.json"); |
| 68 | + } |
| 69 | +} |
0 commit comments