datafusion_delta_sharing/client/
action.rs1use std::collections::HashMap;
4
5use serde::Deserialize;
6
7#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
9#[serde(rename_all = "camelCase")]
10pub struct Protocol {
11 min_reader_version: u32,
13}
14
15impl Protocol {
16 pub fn min_reader_version(&self) -> u32 {
19 self.min_reader_version
20 }
21}
22
23impl Default for Protocol {
24 fn default() -> Self {
25 Self {
26 min_reader_version: 1,
27 }
28 }
29}
30
31#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
33#[serde(rename_all = "camelCase")]
34pub struct Format {
35 provider: String,
37 options: Option<HashMap<String, String>>,
38}
39
40impl Format {
41 pub fn provider(&self) -> &str {
43 self.provider.as_ref()
44 }
45
46 pub fn options(&self) -> Option<&HashMap<String, String>> {
48 self.options.as_ref()
49 }
50}
51
52impl Default for Format {
53 fn default() -> Self {
54 Self {
55 provider: String::from("parquet"),
56 options: None,
57 }
58 }
59}
60
61#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
66#[serde(rename_all = "camelCase")]
67pub struct Metadata {
68 id: String,
69 name: Option<String>,
70 description: Option<String>,
71 format: Format,
72 schema_string: String,
73 partition_columns: Vec<String>,
74 #[serde(default)]
75 configuration: HashMap<String, String>,
76 version: Option<String>,
77 size: Option<u64>,
78 num_files: Option<u64>,
79}
80
81impl Metadata {
82 pub fn id(&self) -> &str {
84 &self.id
85 }
86
87 pub fn name(&self) -> Option<&str> {
89 self.name.as_deref()
90 }
91
92 pub fn description(&self) -> Option<&str> {
94 self.description.as_deref()
95 }
96
97 pub fn format(&self) -> &Format {
99 &self.format
100 }
101
102 pub fn schema_string(&self) -> &str {
104 &self.schema_string
105 }
106
107 pub fn partition_columns(&self) -> &[String] {
109 &self.partition_columns
110 }
111
112 pub fn configuration(&self) -> &HashMap<String, String> {
114 &self.configuration
115 }
116
117 pub fn version(&self) -> Option<&str> {
119 self.version.as_deref()
120 }
121
122 pub fn size(&self) -> Option<u64> {
124 self.size
125 }
126
127 pub fn num_files(&self) -> Option<u64> {
129 self.num_files
130 }
131}
132
133#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
135#[serde(rename_all = "camelCase")]
136pub struct File {
137 url: String,
138 id: String,
139 partition_values: HashMap<String, Option<String>>,
140 size: u64,
141 #[serde(skip_serializing_if = "Option::is_none")]
142 stats: Option<String>,
143 #[serde(skip_serializing_if = "Option::is_none")]
144 version: Option<u64>,
145 #[serde(skip_serializing_if = "Option::is_none")]
146 timestamp: Option<u64>,
147 #[serde(skip_serializing_if = "Option::is_none")]
148 expiration_timestamp: Option<u64>,
149}
150
151impl File {
152 pub fn url(&self) -> &str {
154 self.url.as_ref()
155 }
156
157 pub fn url_mut(&mut self) -> &mut String {
159 &mut self.url
160 }
161
162 pub fn id(&self) -> &str {
164 self.id.as_ref()
165 }
166
167 pub fn partition_values(&self) -> HashMap<String, String> {
169 self.partition_values
170 .iter()
171 .map(|(k, v)| (k.clone(), v.clone().unwrap_or_default()))
172 .collect()
173 }
174
175 pub fn size(&self) -> u64 {
177 self.size
178 }
179
180 pub fn stats(&self) -> Option<&str> {
182 self.stats.as_deref()
183 }
184
185 pub fn version(&self) -> Option<u64> {
187 self.version
188 }
189
190 pub fn timestamp(&self) -> Option<u64> {
193 self.timestamp
194 }
195
196 pub fn expiration_timestamp(&self) -> Option<u64> {
199 self.expiration_timestamp
200 }
201}